Solved

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

Posted on 2008-10-30
1
1,502 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

939 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

6 Experts available now in Live!

Get 1:1 Help Now