steeb
(Just in Town)
2008-06-17 09:13 PM
Copy directory using runnas

Hello, currently I use a logon script (scriptstart) that is based off of kixtart.

I want to execute commands to copy files, and make directories, but the script wont run because the user doesnt have local access. I am trying to use the runnas utility. I have placed it in \\server\netlogon\Scriptstart\custom\runnas.exe

The following command executes fine on machines where local admin has rights, but not any average domain users.

Please advise

 Code:
if not exist "c:\Documents and Settings\%username%\Spark\spark.properties" goto :usermd else :dumd

:usermd

md "c:\Documents and Settings\%username%\Spark"

copy "\\exchangeserver\netlogon\spark\spark.properties" "%userprofile%\Spark\"


if not exist "c:\Documents and Settings\Default User\Spark\spark.properties" goto :dumd

:dumd

md "c:\Documents and Settings\Default User\Spark"

copy "\\exchangeserver\netlogon\Spark\spark.properties" "C:\Documents and Settings\Default User\Spark\*.*

if not exist "c:\windows\krb5.ini" goto :krb

:krb

copy "\\exchangeserver\netlogon\Spark\krb5.ini" "C:\windows\krb5.ini


Gargoyle
(MM club member)
2008-06-17 10:08 PM
Re: Copy directory using runnas

First off let me begin by saying that the use of GOTO is frowned upon anymore. Makes for very hard to follow code.

Second, you have no ENDIF to go with your IF

Third, why are you changing the Default user location? This should be a part of any build that you are using and not handled in the logon script. As the only time that Default user is used is upon the first logon of a user.

Below is your code cleaned up a small amount that will resolve some of your issues. As to copying the krb5.ini to the System folder, you have several options one of them being to use RUNNAS.

 Code:
if not exist "c:\Documents and Settings\%username%\Spark\spark.properties" 
	md "c:\Documents and Settings\%username%\Spark"
	copy "\\exchangeserver\netlogon\spark\spark.properties" "%userprofile%\Spark\"
EndIf


if not exist "c:\windows\krb5.ini" 

	copy "\\exchangeserver\netlogon\Spark\krb5.ini" "C:\windows\krb5.ini

EndIf


Since you are checking for the spark folder for each user as they logon, there is no need for the Default User to have it.

I did not address the way to copy the file to the system folder as you have to decide the way you want to handle it before we can say exactly the way to do it.


steeb
(Just in Town)
2008-06-18 01:03 AM
Re: Copy directory using runnas

Gargoyle, thanks for the prompt response and clarification. Don't know why I put the default profile. It may have been there from something else I was testing, but found a better solution.

I would more than likely use the Runnas command. What would be the format to execute to write to the windows directory


Gargoyle
(MM club member)
2008-06-18 02:02 AM
Re: Copy directory using runnas

I have never used the RUNNAS as provided by Shawn.

There are many others here that can chime in and help with that.