Re: help writting script to copy file to every desktop
- From: "Mike Cook" <mcook@xxxxxxxxxxxx>
- Date: Fri, 14 Sep 2007 09:59:12 -0400
Dave
Here is a sample script that I use. I added the script to the policy assigned to the OU. You should be able to limit the scope of the copy by creating multiple versions of this script and assign them to the group policy assigned to each AD site. If site level isn't good enough, you can use a WMI query to get the computer name and make the logic flow that way. I only have a couple of sites, so I let the NETLOGON share handle the replication of the shortcuts for me. Each shortcut is only 1KB each, so the extra replication traffic is nothing.
A quick item to point out, the Scripting.FileSystemObject handles folders differently from files. If the path you send to the object ends with a backslash, that is indicating a folder. If you send a path that doesn't end with a backslash, it is a file. You will get different methods, collections, and properties for a file than you will for a folder.
Const PATH = "\\Server1\shortcut$\Division\Department\"
' Set a constant to look for the UNC to where the shortcuts are located, trailing backslash is neccessary
Const OverwriteExisting = TRUE
' Set a constant for the FileSystemObject to overwrite if necessary
set WshShell = WScript.CreateObject("WScript.Shell")
' Create a wscript.shell object to get the special folder of desktop
strDesktop = WshShell.SpecialFolders("desktop")
' Assign a string variable to the path to the user's desktopSet fso = CreateObject("Scripting.FileSystemObject")
' Create a FileSystemObject to check if the shortcut exists
Set f = fso.GetFolder(PATH)
' Get the folder object
Set fc = f.Files
' Create a collection of files in the folder object
For Each f1 in fc
' Start the loop
strItem = f1.name
If not FSO.FileExists(strDesktop & "\" & strItem) Then
' Check to see if the shortcut exists on the desktop
Set objShortcut = FSO.GetFile(PATH & strItem)
objShortcut.Copy strDesktop & "\" & strItem, OverwriteExisting
' If check fails, set a FileSystemObject to the shortcut on the network and copy it to the desktop
End If
Next
"Dave Allen" <nomail@xxxxxxxxxx> wrote in message news:ec$VM7h9HHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
I have multiple offices in my domain
In every office the desktop computer name is prefixed with the office's name
For example LA = Los Angles, NY, etc....
I need to write a .vbs that can copy a file to every machine's C: drive
based on the machine's name
I'd like to run it with command line variables like this
Domaincopy.vbs NY1- C:\Defrag.exe "C:\Documents and Settings\All
Users\Desktop\"
.
- Follow-Ups:
- Re: help writting script to copy file to every desktop
- From: Dave Allen
- Re: help writting script to copy file to every desktop
- References:
- help writting script to copy file to every desktop
- From: Dave Allen
- help writting script to copy file to every desktop
- Prev by Date: LDAP query... which DC?
- Next by Date: Re: Close DOS Windows
- Previous by thread: help writting script to copy file to every desktop
- Next by thread: Re: help writting script to copy file to every desktop
- Index(es):
Relevant Pages
|