Login Script to Copy Folders

I would like to create a login script which copies file onto c:\Program Files folder and this is the script:

xcopy /s /r /y /q "\\servername\Test\*.*" "C:\Program Files\xxx\bbb_folder"

The script runs successfully if it is run locally as administrator but not from the login script.  Can anyone help me with the good login script?  Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are standandard users able to write to C:\Program Files\xxx\bbb_folder ?
Michael FowlerSolutions ConsultantCommented:
Try creating it as a Scheduled Task as this will give you more options such as the account to run under. There is a trigger for it to run on startup
Steve KnightIT ConsultancyCommented:
The user will probably not have rights to that area, and the login script runs as the user.  So... options IMO:

1. Use a startup script from AD instead of Login, that runs as the computer so will have rights.
2. Use group policy preferences to copy the file....
3. Give the user rights to that area, that can be through group policy or script

I'd use #2 if possible in your environment, is easy and quick... quick google shows a doc on how-to to save re-inventing the wheel but ask if not sure.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Personally, I would say use option 1, but you need to make sure that that Domain Computers have read rights to the network source you are copying from.

yimsoin57Author Commented:
Please note user has full admin rights to the computer.  I will try the option one and update the result.  Thank you.
If the user has full rights to the computer, and the logon script isn't working, it's likely that UAC is getting in the way.  Running it as a StartUp script (and providing Domain Computers access to the source) will get around the UAC issue.
Steve KnightIT ConsultancyCommented:
Yes, full admin rights still won't let them copy unless they use run-as-admin to use their admin token.

So msot easily you would have to add the "users" group with suitable rights to that directory to have the user run the script, or another user or group that contains that user's account, e.g. a domain group you create for the purpose.

But as we said doing as startup script, or using group policy preferences will work regardless of the user involved.

If you do look at group policy preferences you can potentially bring in other login script functions such as drive mappings etc. if you want to that way too.

I hate to say it, but this is not really a good job for a login script.
It is an EXCELLENT job for Group Policy
@Steve Knight's #2 really is the way you want to go.

I know it look intimidating, but given the location you are trying to jam those files into, the Group Policy really is the only way to go.
Robberbaron (robr)Commented:
A group policy [computer - startup]  script will work fine. (i have it in use now)

but I have found that the files you want to copy are best located under the NetLogon scripts folder to  ensure that files are available PRIOR to logon.  So dont store sensitive files there...

as a startup script it runs 'system' user.

my script that copies individual files attached.  easy enough to change to a folder copy.

' RG    23.Jun.2009  added 64bit detection and located DLL correctly.
' Constants for opening files
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8

'--- set up files & log ---------
const ScrFldr="\\MyDomain\SYSVOL\MyDomain.com\scripts\"       'std source location

const LogFldr="\\\MyDomain\SYSVOL\\MyDomain.com\logs\"       

	dim a, src , sVers , isOS64
	dim fs

	lf = "installs2.log"

	datetime=Year(now()) & Right("0" & Month(now()), 2) & Right("0" & Day(now()), 2) & "=" & Right("0" & Hour(now()), 2) & Right("0" & Minute(now()), 2) '& Right("0" & Second(now()), 2)

	' Create the Shell etc objects
  Set oShell = CreateObject("WScript.Shell")
	Set oNet = CreateObject("WScript.Network")
	Set oFSO = CreateObject("Scripting.FileSystemObject")  
	sysfld = oFSO.GetSpecialFolder(1)    'the system folder
	winfld =  oFSO.GetSpecialFolder(0)   'the windows folder
  if oFSO.folderexists(winfld & "\SYSWOW64") then
     isOS64 = true
     isOS64 = false
  end if
	' write to Log 
	' write to Log 
	Set flf = oFSO.GetFile(logfldr & lf)
	Set tslf = flf.OpenAsTextStream(OpenFileForAppending)

	tslf.Write (Onet.ComputerName & " , " & "BEGIN " & iif(isOS64,"64bit","32bit") & " , " & Datetime & vbCrLf)
'------- end setup section ----
'###################### PHASE 1 #################################
'---copy dsofile if not exist --------------
	on error resume next
	If (oFSO.FileExists(winfld & "\" & src )) Then
    msg = "dsofile exists in Windows."
		sVers = oFSO.GetFileVersion(winfld & "\" & src )
		msg = msg & " v=" & sVers & " -- deleted"
		oFSO.DeleteFile winfld & "\" & src
	end if
  If (oFSO.FileExists(sysfld & "\" & src )) Then
      msg = "dsofile exists in sysfld."
      sVers = oFSO.GetFileVersion(sysfld & "\" & src )
      msg = msg & " <" & sVers & "> "
  end if  
  'now the tricky stuff
  if isOS64 then
    'copy dsofile64 to sysfldr   v2.0.1126
    'copy dsofile32 to win\SYSWOW64  v2.1.2841
    'register 64bit

    if left(sVers,6) = "2.0.11" then    
        'no action needed      should be 2.0.1126
        set f1 = oFSO.GetFile( scrfldr & src64 )
        fDest = sysfld 
        f1.Copy fDest & "\" & src,True
        if Err.Number=0 then msg = msg & " copied dsofile64. "

        a=(sysfld & "\regsvr32.exe /S " & fDest & "\" & src )
        oShell.Run a
        if Err.Number=0 then msg = msg & " Installed dsofile64. "
        set f1 = oFSO.GetFile( scrfldr & src32 )       
        fDest = winfld & "\SYSWOW64"
        f1.Copy fDest & "\" & src,True
        if Err.Number=0 then msg = msg & " copied dsofile32. "
        a=(fDest & "\regsvr32.exe /S " & fDest & "\" & src)
        oShell.Run a
        msg = msg & " Install dsofile 32"
        if Err.Number=0 then msg = msg & " Installed dsofile32. "   
    End If
      'copy dsofile32 to sysfldr  v2.1.2841

      if left(sVers,6) = "2.1.28" then    
          'no action needed      
          set f1 = oFSO.GetFile( scrfldr & src32 )
          fDest = sysfld 
          f1.Copy fDest & "\" & src,True
          if Err.Number=0 then msg = msg & " copied dsofile 32. "

          a=(sysfld & "\regsvr32.exe /S " & fDest & "\" & src )
          oShell.Run a
          if Err.Number=0 then msg = msg & " Installed dsofile 32. "
      End If    
  end if
	tslf.Write (Onet.ComputerName & " ,#1# " & msg & " , " & Datetime & vbCrLf)

'--- close out log file -----
	tslf.Write (Onet.ComputerName & " , " & msg & " , " & Datetime & vbCrLf)
'------ end ---
	set onet = nothing
	set oShell = nothing
	Set oFSO = Nothing

Open in new window

Steve KnightIT ConsultancyCommented:
Personally would say https:#a40469785 , https:#a40470041 , https:#a40469930  as answers as show the ways it should or could be done.  If no-one objects can trigger it to finish it off like that if wanted.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.