Login Script to Copy Folders

Posted on 2014-11-27
Last Modified: 2016-06-11
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.
Question by:yimsoin57
LVL 29

Expert Comment

ID: 40469745
Are standandard users able to write to C:\Program Files\xxx\bbb_folder ?
LVL 23

Expert Comment

ID: 40469760
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
LVL 43

Accepted Solution

Steve Knight earned 500 total points
ID: 40469785
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.
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

LVL 65

Expert Comment

ID: 40469801
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.


Author Comment

ID: 40469898
Please note user has full admin rights to the computer.  I will try the option one and update the result.  Thank you.
LVL 65

Expert Comment

ID: 40469930
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.
LVL 43

Expert Comment

by:Steve Knight
ID: 40470041
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.

LVL 26

Expert Comment

ID: 40471110
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.
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 40473488
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\\scripts\"       'std source location

const LogFldr="\\\MyDomain\SYSVOL\\\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

LVL 43

Expert Comment

by:Steve Knight
ID: 41649069
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.


Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now