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.
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.
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

18 Experts available now in Live!

Get 1:1 Help Now