Link to home
Start Free TrialLog in
Avatar of LeighWardle
LeighWardleFlag for Australia

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
Avatar of Dave Stringfellow
Dave Stringfellow
Flag of United Kingdom of Great Britain and Northern Ireland image

It all depends where you need the files copied, and what rights your users have, but you can use something simple like this:

net use m: \\<server>\<share>
xcopy m:\file1.ext "c:\documents and settings\%userprofile%\desktop"
net use m: /d

hope this helps :)
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%.\$ATETIM0.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\InterimTest" /Y /C /R
xcopy "%5" "E:\Ovations\BulkExtractMQ\InterimTest" /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
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LeighWardle

ASKER

Hi Rob,

Can you elaborate on what a "StartUp script" is, please?

Thanks,

Regards,
Leigh
Hi Rob,

It's OK, I have worked out what a "StartUp script" is.

Thanks,

Regards,
Leigh
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.local\scripts\index.html %allusersprofile%\Desktop


Thanks,

Regards,
Leigh
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.local\scripts\index.html "%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.local\scripts\index.html works OK.


Thanks,

Regards,
Leigh
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%\desktop" 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.local\scripts\index.html "%allusersprofile%\Desktop"

What you might do to test where the problem is, is manually run
copy \\ASRC.local\SYSVOL\ASRC.local\scripts\index.html "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.local\scripts\index.html "%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.
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
Cool. No worries. Thanks for the grade.

Regards,

Rob.