Solved

Need vbscript to copy files from SYSVOL GPO folder to local c: drive

Posted on 2008-10-30
1
1,509 Views
Last Modified: 2012-05-05
Hi Folks,

What's the recommended method to copy files from the SYSVOL\...USER\SCRIPTS\LOGON folder to the local c:\ drive (user's XP or Vista machines).  In the past I've used the the method shown.  But since the GPO has such a long character string for the folder, I was wondering if I need to put that full string in the code.  

Sort of related, can I refer to a file share (such as \\server\share) instead of having to use drive letter?  If I could use a share name I'd just copy the file(s) from that location and be done with it.

Suggestions appreciated.
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
 
Set colFiles = _
   objWMIService.ExecQuery("Select * From CIM_DataFile Where Name = 'f:\\HIPAAScreenSaver\\HNNCSB-HIPAA-SAVER.scr'")
 
 
For Each objFile in colFiles
    objFile.Copy ("C:\windows\system32\HNNCSB-HIPAA-SAVER.scr")
Next

Open in new window

0
Comment
Question by:hnncsb
1 Comment
 
LVL 17

Accepted Solution

by:
Jared Luker earned 125 total points
ID: 22845174
You can use the ExpandEnvironmentStrings method to get the name of the domain controller that you are authenticated to.  That way, you could use that variable along with the sysvol share in UNC notation in order to point to the file that you are wanting to copy.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
LogonServer = wshshell.ExpandEnvironmentStrings("%LOGONSERVER%")
 
objFSO.CopyFile LogonServer & "\sysvol\WhatEverElse","c:\destination",True

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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