Re: help writting script to copy file to every desktop
- From: "Mike Cook" <mcook@xxxxxxxxxxxx>
- Date: Mon, 17 Sep 2007 11:47:45 -0400
OK. Try this one. It will search AD to come back with a list of computer names. Then it will ping each computer to see if it is truly reachable. Then it will copy the file to the C$ share. I made the query exclude any computer with the word "Server" in it.
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objRoot = GetObject("LDAP://RootDSE")
strDNC = objRoot.Get("DefaultNamingContext")
strDN = "LDAP://" & strDNC
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name from '" & strDN & "' " & _
"Where objectClass = 'computer' and not operatingsystem = '*Server*' "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strComputer = objRecordset.Fields("Name").Value
If Ping(strComputer) = True then
Set WshShell = CreateObject("WScript.Shell")
WshShell.run "Copy c:\FileToBeCopied.txt \\" & strComputer & "\c$"
Wscript.Echo "File copied to " & strComputer & "\c$"
Set WshShell = Nothing
objRecordSet.MoveNext
Else
Wscript.Echo strComputer & " isn't reachable"
End If
objRecordSet.MoveNext
Loop
Function ping(strComputer)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
Ping = False
Else
Ping = True
End If
Next
End Function
"Dave Allen" <nomail@xxxxxxxxxx> wrote in message news:OsvxEOv9HHA.5456@xxxxxxxxxxxxxxxxxxxxxxx
Thankx Mike but a few things here.
The infrastructure department at my company is Nazi about access to group policy or the login scripts
so those 2 avenues are not a possibility.
In a way you can say I am in desktop support.
I have admin rights over every desktop but limited access to servers.
What I envisioned writing was a script that would just copy to every machine that was powered up and access the C$ share
"Mike Cook" <mcook@xxxxxxxxxxxx> wrote in message news:CF8BB163-5CFB-4314-A243-2D2AF0CEB863@xxxxxxxxxxxxxxxxDave
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@xxxxxxxxxxxxxxxxxxxxxxxI 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
- Re: help writting script to copy file to every desktop
- From: Mike Cook
- Re: help writting script to copy file to every desktop
- From: Dave Allen
- help writting script to copy file to every desktop
- Prev by Date: Re: Shell Execute limitation
- Next by Date: ideas for searching file ?
- Previous by thread: Re: 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
|