Re: help writting script to copy file to every desktop

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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@xxxxxxxxxxxxxxxx
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\"

.



Relevant Pages

  • Re: help writting script to copy file to every desktop
    ... I added the script to the policy assigned to the OU. ... Each shortcut is only 1KB each, so the extra replication traffic is nothing. ... You will get different methods, collections, and properties for a file than you will for a folder. ... ' Create a collection of files in the folder object ...
    (microsoft.public.scripting.vbscript)
  • Re: help writting script to copy file to every desktop
    ... Here is a sample script that I use. ... 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. ... Each shortcut is only 1KB each, so the extra replication traffic is nothing. ... You will get different methods, collections, and properties for a file than you will for a folder. ...
    (microsoft.public.scripting.vbscript)
  • Re: Looking for shortcut to empty trash...
    ... If you're in Panther you can a shortcut simply, ... you'll see "Empty Deleted Items Folder" menu item. ... Flip the popup to Entourage. ... Otherwise, or if pre Panther, save this script: ...
    (microsoft.public.mac.office.entourage)
  • Re: desktop shortcut via group policy
    ... I use plain old .bat files for login script. ... > I need to put a desktop shortcut for a defined global group on 1/3 of> my ... If I use the folder redirection feature in group policy,> will ... Microsoft MVP - Windows Server - Group Policy. ...
    (microsoft.public.windows.group_policy)
  • [kde] Re: plasma-desktop (KDE factory) acting up?
    ... example is another logging plasmoid that shows the output of a little ... script that outputs the state of my four drives every ten seconds. ... I have the group set to wheel for the logs I want to be read by trusted ... folder with pictures of people, and a subfolder with pictures of myself. ...
    (KDE)