LeighWardle
asked on
How to automaticall copy some files to workstation desktop during NetLogon when logging on as standard user
Hi Experts!,
I would like to have a script or batch file that will copy some files from our Server to a Workstation desktop via the NetLogon script when a standard user logs in.
Regards,
Leigh
I would like to have a script or batch file that will copy some files from our Server to a Workstation desktop via the NetLogon script when a standard user logs in.
Regards,
Leigh
This is what i used for a bulk network copy, this i triggered off running a scheduled exe to do the processing ie
User -> EXE -> Batch Copy.
Notes the %1,2,3,4,5 are parameters passed to the batch file. You can pass your own, in which case you just need to change the servers etc. Remember to share the folders you will be copying to, adding the correct permissions. I also add error logging below if you want to use it.
@echo off
REM * ---------Getting Date Time for Log File-------------------
If Not %1'==/?' Goto Begin
Echo Sets DATE and TIME variable to the system date and time.
Echo.
Echo [Call] DATETIME
Goto End
:Begin
For %%V In (DATE TIME) Do Set %%V=
If %OS%'==Windows_NT' Goto %OS%
Echo @Prompt %%%%1 %%%%0 :: $D $T$_Set DATE=%%%%3$_Set TIME=%%%%4$_>%TEMP%.\$ATET IM0.BAT
%COMSPEC% /C %TEMP%.\$ATETIM0.BAT > %TEMP%.\$ATETIM1.BAT
Call %TEMP%.\$ATETIM1.BAT
Del %TEMP%.\$ATETIM?.BAT
Goto End
:Windows_NT
For /F "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
REM * -------------------------- ---------- ---------- ---------- --
REM * ----------Get Log File Parameters and create/Delete-------
set slog=%3%DATE%%4
echo %slog%
if exist %slog% del %slog% >NUL
REM * -------------------------- ---------- ---------- ---------- --
REM * ----------Specify Which Region for Copy (PROD Local)-------------
echo %ERRORLEVEL%
cd c:\windows\system32
echo Delete Mapped Drive >> %slog%
echo Creating Drive Mapping >> %slog%
echo %ERRORLEVEL%
echo Check if source exists >> %slog%
echo If NOT EXIST %5 GOTO ErrorSource >> %slog%
REM * -----net use Local >> %slog%
echo Copy the file across %5>> %slog%
echo xcopy "%5" "E:\Ovations\BulkExtractMQ \InterimTe st" /Y /C /R
xcopy "%5" "E:\Ovations\BulkExtractMQ \InterimTe st" /Y /C /R
echo Error:%ERRORLEVEL%
echo IF %ERRORLEVEL% NEQ 0 goto ErrorCopy
echo Delete Mapped Drive >> %slog%
net use J: /delete
REM * -------------------------- ---------- ---------- ---------- --
:ErrorMap
echo Errors Indicator:%ERRORLEVEL% - Couldnt Map Drive to specified directory >> %slog%
goto finish
:ErrorCopy
echo Errors Indicator:%ERRORLEVEL% - Couldnt Copy file to specified directory >> %slog%
goto finish
:ErrorSource
echo Errors Indicator:%ERRORLEVEL% - Source directory couldnt be found >> %slog%
goto finish
:finish
echo Finished >> %slog%
@echo on
User -> EXE -> Batch Copy.
Notes the %1,2,3,4,5 are parameters passed to the batch file. You can pass your own, in which case you just need to change the servers etc. Remember to share the folders you will be copying to, adding the correct permissions. I also add error logging below if you want to use it.
@echo off
REM * ---------Getting Date Time for Log File-------------------
If Not %1'==/?' Goto Begin
Echo Sets DATE and TIME variable to the system date and time.
Echo.
Echo [Call] DATETIME
Goto End
:Begin
For %%V In (DATE TIME) Do Set %%V=
If %OS%'==Windows_NT' Goto %OS%
Echo @Prompt %%%%1 %%%%0 :: $D $T$_Set DATE=%%%%3$_Set TIME=%%%%4$_>%TEMP%.\$ATET
%COMSPEC% /C %TEMP%.\$ATETIM0.BAT > %TEMP%.\$ATETIM1.BAT
Call %TEMP%.\$ATETIM1.BAT
Del %TEMP%.\$ATETIM?.BAT
Goto End
:Windows_NT
For /F "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
REM * --------------------------
REM * ----------Get Log File Parameters and create/Delete-------
set slog=%3%DATE%%4
echo %slog%
if exist %slog% del %slog% >NUL
REM * --------------------------
REM * ----------Specify Which Region for Copy (PROD Local)-------------
echo %ERRORLEVEL%
cd c:\windows\system32
echo Delete Mapped Drive >> %slog%
echo Creating Drive Mapping >> %slog%
echo %ERRORLEVEL%
echo Check if source exists >> %slog%
echo If NOT EXIST %5 GOTO ErrorSource >> %slog%
REM * -----net use Local >> %slog%
echo Copy the file across %5>> %slog%
echo xcopy "%5" "E:\Ovations\BulkExtractMQ
xcopy "%5" "E:\Ovations\BulkExtractMQ
echo Error:%ERRORLEVEL%
echo IF %ERRORLEVEL% NEQ 0 goto ErrorCopy
echo Delete Mapped Drive >> %slog%
net use J: /delete
REM * --------------------------
:ErrorMap
echo Errors Indicator:%ERRORLEVEL% - Couldnt Map Drive to specified directory >> %slog%
goto finish
:ErrorCopy
echo Errors Indicator:%ERRORLEVEL% - Couldnt Copy file to specified directory >> %slog%
goto finish
:ErrorSource
echo Errors Indicator:%ERRORLEVEL% - Source directory couldnt be found >> %slog%
goto finish
:finish
echo Finished >> %slog%
@echo on
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Rob,
Can you elaborate on what a "StartUp script" is, please?
Thanks,
Regards,
Leigh
Can you elaborate on what a "StartUp script" is, please?
Thanks,
Regards,
Leigh
ASKER
Hi Rob,
It's OK, I have worked out what a "StartUp script" is.
Thanks,
Regards,
Leigh
It's OK, I have worked out what a "StartUp script" is.
Thanks,
Regards,
Leigh
ASKER
Hi Rob,
I have created a "StartUp script" and a Group Policy Object to deploy it to all authenticated users.
It's not working, is it valid to use %allusersprofile% in a batch file, or should I be using .vbs?
Right now my batch file consists of:
copy \\ASRC.local\SYSVOL\ASRC.l ocal\scrip ts\index.h tml %allusersprofile%\Desktop
Thanks,
Regards,
Leigh
I have created a "StartUp script" and a Group Policy Object to deploy it to all authenticated users.
It's not working, is it valid to use %allusersprofile% in a batch file, or should I be using .vbs?
Right now my batch file consists of:
copy \\ASRC.local\SYSVOL\ASRC.l
Thanks,
Regards,
Leigh
ASKER
Hi Rob,
I have got a bit further by adding quotes to the part of the copy command that includes %allusersprofile%.
Right now my batch file consists of:
copy \\ASRC.local\SYSVOL\ASRC.l ocal\scrip ts\index.h tml "%allusersprofile%\Desktop "
It doesn't work on StartUp, but I can run it from a command prompt on the workstation.
It gives an "Access Denied" error.
This is something to do with the destination, as TYPE \\ASRC.local\SYSVOL\ASRC.l ocal\scrip ts\index.h tml works OK.
Thanks,
Regards,
Leigh
I have got a bit further by adding quotes to the part of the copy command that includes %allusersprofile%.
Right now my batch file consists of:
copy \\ASRC.local\SYSVOL\ASRC.l
It doesn't work on StartUp, but I can run it from a command prompt on the workstation.
It gives an "Access Denied" error.
This is something to do with the destination, as TYPE \\ASRC.local\SYSVOL\ASRC.l
Thanks,
Regards,
Leigh
ASKER
P.S. I am logging in as a standard user without admin rights (that's what I require).
Make sure the user you are using has permissions in the destination folder to copy files, test first by giving everyone permission and youll see whether it is a sharing issue on the folder.
all users needs admin rights to copy too, if you just need a file on each desktop, use "c:\documents and settings\%userprofile%\des ktop" to put on to the users desktop when they log in
Hi Leigh, sorry, I went to sleep after I posted my last comment.
Looks like you've got it right so far. Yes, you did need quotes around the target path, because C:\Documents and Settings\All Users\Desktop, has spaces in it. You can see this at a command prompt by typing
echo %allusersprofile%\Desktop
This should work in a batch file no problem.
So the way you have it should be fine:
copy \\ASRC.local\SYSVOL\ASRC.l ocal\scrip ts\index.h tml "%allusersprofile%\Desktop "
What you might do to test where the problem is, is manually run
copy \\ASRC.local\SYSVOL\ASRC.l ocal\scrip ts\index.h tml "C:\Temp"
so you know whether the file can be copied to the drive. However, that's under the current user profile, which is not the System profile that a StartUp script runs under. If you right-click the index.html file, and go to the security tab, there should be an entry for SYSTEM.
Now, to test the file copy actually using the SYSTEM account, grab a copy of PSExec from Microsoft, and run this:
psexec -accepteula -s \\localhost copy \\ASRC.local\SYSVOL\ASRC.l ocal\scrip ts\index.h tml "%allusersprofile%\Desktop "
and the -s there runs under the SYSTEM account. This way, you'll know whether it should work or not.
See how you go.
Regards,
Rob.
Looks like you've got it right so far. Yes, you did need quotes around the target path, because C:\Documents and Settings\All Users\Desktop, has spaces in it. You can see this at a command prompt by typing
echo %allusersprofile%\Desktop
This should work in a batch file no problem.
So the way you have it should be fine:
copy \\ASRC.local\SYSVOL\ASRC.l
What you might do to test where the problem is, is manually run
copy \\ASRC.local\SYSVOL\ASRC.l
so you know whether the file can be copied to the drive. However, that's under the current user profile, which is not the System profile that a StartUp script runs under. If you right-click the index.html file, and go to the security tab, there should be an entry for SYSTEM.
Now, to test the file copy actually using the SYSTEM account, grab a copy of PSExec from Microsoft, and run this:
psexec -accepteula -s \\localhost copy \\ASRC.local\SYSVOL\ASRC.l
and the -s there runs under the SYSTEM account. This way, you'll know whether it should work or not.
See how you go.
Regards,
Rob.
ASKER
Hi Rob,
Last night I decided to try copying to %userprofile%\Desktop, as you suggested in your first scenario.
I got that working. It's a lot easier, as I can do that from the Login script without worrying about StartUp scripts and Group Policy.
Cheers,
Leigh
Last night I decided to try copying to %userprofile%\Desktop, as you suggested in your first scenario.
I got that working. It's a lot easier, as I can do that from the Login script without worrying about StartUp scripts and Group Policy.
Cheers,
Leigh
Cool. No worries. Thanks for the grade.
Regards,
Rob.
Regards,
Rob.
net use m: \\<server>\<share>
xcopy m:\file1.ext "c:\documents and settings\%userprofile%\des
net use m: /d
hope this helps :)