Solved

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

Posted on 2008-10-30
1
1,534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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