We help IT Professionals succeed at work.

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
Comment
Watch Question

Dave StringfellowIT manager

Commented:
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 :)

Commented:
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
SILVER EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi Leigh, two scenario's come to mind here...

1. You want files copied to the logged on user's Desktop.
2. You want files copied to the All Users Desktop.

If you're after option number one, then every user should have rights to their own desktop, so just set up a network share with the relevant permissions (usually Domain Users at Read), and then use a normal Login script to copy \\server\share\file.ext to %userprofile%\Desktop

If you're after option number two, then use a StartUp script, instead of a Login script, and have the files you want to copy under the NetLogon share of a domain controller.  Then have the script copy files from
\\domain.com\sysvol\domain.com\scripts\file.ext to %allusersprofile%\Desktop.  The StartUp script runs under the System account, and as far as network permissions goes, only has rights on the NetLogon folder (which is the same as \\domain.com\sysvol\domain.com\scripts).

Regards,

Rob.

Author

Commented:
Hi Rob,

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

Thanks,

Regards,
Leigh

Author

Commented:
Hi Rob,

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

Thanks,

Regards,
Leigh

Author

Commented:
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

Author

Commented:
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

Author

Commented:
P.S. I am logging in as a standard user without admin rights (that's what I require).

Commented:
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.
Dave StringfellowIT manager

Commented:
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
SILVER EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.

Author

Commented:
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
SILVER EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Cool. No worries. Thanks for the grade.

Regards,

Rob.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.