Copy Folder to Computers on VPN (no domain)

May 28, 2009 at 20:35:34
Specs: Windows XP
I am trying to make a script that will copy the GroupPolicy Folder to all my computers on my remote sites.

It will have to check if an IP is alive and is acually an computer (XP) not something like a router or IP phone.

i would like to have it run against a lot of ip address ranges.

e.g.
10.10.0.
10.2.222.
110.2.248.
all from .1-254

What i have so far is below, i am having a lot of trouble around line 36

'On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Const OverWriteFiles = True

Dim objPassword, strUser, strPassword
Dim objWbemLocator, objWMIService
Dim strSystemOS
DIM strLocalpath, strRemotepath

' Set IP range
strSubnetPrefix = "10.2.222."
intStartSubnet = 21
intEndSubnet = 21

'Asks for User/Pass/Computer
Set objPassword = CreateObject("ScriptPW.Password") 
WScript.StdOut.Write "Enter your user id: "
strUser = WScript.StdIn.ReadLine
WScript.StdOut.Write "Please enter " & strUser & " password: "
strPassword = objPassword.GetPassword()
WSCript.Echo
'WScript.StdOut.Write "Enter System Name: "
'strComputer = WScript.StdIn.ReadLine
'WSCript.Echo

For i = intStartSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objWbemLocator.ConnectServer _
	(strComputer, strNamespace, strUser, strPassword,,, wbemConnectFlagUseMaxWait)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

	Set objWMIService = GetObject("winmgmts:" _
		& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colFolders = objWMIService.ExecQuery( _
		"Select * from Win32_Directory where Name = 'c:\\Scripts\GroupPolicy'")
	For Each objFolder in colFolders
		errResults  = objFolder.Copy("\\" & strComputer & "\c$\WINDOWS\system32")
		Wscript.Echo errResults
	Next	
Next 


Function PingStatus(strComputer)

    On Error Resume Next
    strWorkstation = "."
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2")
    Set colPings = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
    For Each objPing in colPings
        Select Case objPing.StatusCode
            Case 0 PingStatus = "Success"
            Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
            Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
            Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
            Case 11004 PingStatus = _
              "Status code 11004 - Destination Protocol Unreachable"
            Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
            Case 11006 PingStatus = "Status code 11006 - No Resources"
            Case 11007 PingStatus = "Status code 11007 - Bad Option"
            Case 11008 PingStatus = "Status code 11008 - Hardware Error"
            Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
            Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
            Case 11011 PingStatus = "Status code 11011 - Bad Request"
            Case 11012 PingStatus = "Status code 11012 - Bad Route"
            Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
            Case 11014 PingStatus = _
              "Status code 11014 - TimeToLive Expired Reassembly"
            Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
            Case 11016 PingStatus = "Status code 11016 - Source Quench"
            Case 11017 PingStatus = "Status code 11017 - Option Too Big"
            Case 11018 PingStatus = "Status code 11018 - Bad Destination"
            Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
            Case 11050 PingStatus = "Status code 11050 - General Failure"
            Case Else PingStatus = "Status code " & objPing.StatusCode & _
               " - Unable to determine cause of failure."
        End Select
    Next

End Function

What i had at line 36 before was just to check that i could connect with the User and pass i supply was the code below and it worked fine...

For i = intStartSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objWbemLocator.ConnectServer _
	(strComputer, strNamespace, strUser, strPassword,,, wbemConnectFlagUseMaxWait)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
Set colItems = objWMIService.ExecQuery ("Select * From Win32_ComputerSystem")
	For Each objItem In colItems
		WScript.Echo "Name: " & objItem.Name
		WScript.Echo "Model: " & objItem.Model
		WScript.Echo "Manufacturer: " & objItem.Manufacturer
		WScript.Echo "PartOfDomain: " & objItem.PartOfDomain


See More: Copy Folder to Computers on VPN (no domain)

Report •


#1
May 28, 2009 at 21:03:29
Assuming the commented out line On Error Resume Next is line one:

strNamespace is never declared nor defined.

wbemConnectFlagUseMaxWait is never declared nor defined.

WbemAuthenticationLevelPktPrivacy is never declared nor defined.

The above could have been avoided if your first line was Option Explicit.

The above is rendered moot, however, because on line 36 you discard the connection and attempt to reconnect w/o the provided username and password via GetObject(), so don't do that.

Also, the Win32_Directory.Copy() may or may not fail. I don't have enough experience with the function to say definitively one way or the other.


Report •

#2
May 28, 2009 at 21:49:29
I follow must of it, the strNamespace was left ova so deleted it.

wbemConnectFlagUseMaxWait i placed with a
Const wbemConnectFlagUseMaxWait = 128

I don't understand how to use strUser and strPassword with the GetObject command
Should it look like this?

For i = intStartSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
	

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objWbemLocator.ConnectServer _
	(strComputer, strUser, strPassword,,, wbemConnectFlagUseMaxWait)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

	Set objWMIService = GetObject("winmgmts:" _
		& "strComputer, strUser, strPassword,,, wbemConnectFlagUseMaxWait)!\\" & strComputer & "\root\cimv2")
	Set colFolders = objWMIService.ExecQuery( _
		"Select * from Win32_Directory where Name = 'c:\\Scripts\GroupPolicy'")
	For Each objFolder in colFolders
		errResults  = objFolder.Copy("\\" & strComputer & "\c$\WINDOWS\system32")
		Wscript.Echo errResults
	Next	
Next 


One other thing i put in Option Explicit to check my varibles and i do keep getting an error on strSubnetPrefix.. i have checked the spelling and it is fine...

New full code is

'On Error Resume Next
Option Explicit

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const wbemConnectFlagUseMaxWait = 128
Const WbemAuthenticationLevelPktPrivacy = 6

Const OverWriteFiles = True

Dim objPassword, strUser, strPassword
Dim objWbemLocator, objWMIService
Dim strSystemOS
DIM strLocalpath, strRemotepath

Dim strSubnetPrefix
Dim intStartSubnet
Dim intEndSubnet
Dim i

' Set IP range
strSubnetPrefix = "10.2.222."
intStartSubnet = 21
intEndSubnet = 21

'Asks for User/Pass/Computer
'Set objPassword = CreateObject("ScriptPW.Password") 
'WScript.StdOut.Write "Enter your user id: "
strUser = Administrator 'WScript.StdIn.ReadLine
'WScript.StdOut.Write "Please enter " & strUser & " password: "
strPassword = Desktop1 'objPassword.GetPassword()
WSCript.Echo
'WScript.StdOut.Write "Enter System Name: "
'strComputer = WScript.StdIn.ReadLine
'WSCript.Echo

For i = intStartSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objWbemLocator.ConnectServer _
	(strComputer, strUser, strPassword,,, wbemConnectFlagUseMaxWait)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

	Set objWMIService = GetObject("winmgmts:" _
		& "(strComputer, strUser, strPassword,,, wbemConnectFlagUseMaxWait)!\\" & strComputer & "\root\cimv2")
	Set colFolders = objWMIService.ExecQuery( _
		"Select * from Win32_Directory where Name = 'c:\\Scripts\GroupPolicy'")
	For Each objFolder in colFolders
		errResults  = objFolder.Copy("\\" & strComputer & "\c$\WINDOWS\system32")
		Wscript.Echo errResults
	Next	
Next 


Function PingStatus(strComputer)

    On Error Resume Next
    strWorkstation = "."
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2")
    Set colPings = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
    For Each objPing in colPings
        Select Case objPing.StatusCode
            Case 0 PingStatus = "Success"
            Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
            Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
            Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
            Case 11004 PingStatus = _
              "Status code 11004 - Destination Protocol Unreachable"
            Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
            Case 11006 PingStatus = "Status code 11006 - No Resources"
            Case 11007 PingStatus = "Status code 11007 - Bad Option"
            Case 11008 PingStatus = "Status code 11008 - Hardware Error"
            Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
            Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
            Case 11011 PingStatus = "Status code 11011 - Bad Request"
            Case 11012 PingStatus = "Status code 11012 - Bad Route"
            Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
            Case 11014 PingStatus = _
              "Status code 11014 - TimeToLive Expired Reassembly"
            Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
            Case 11016 PingStatus = "Status code 11016 - Source Quench"
            Case 11017 PingStatus = "Status code 11017 - Option Too Big"
            Case 11018 PingStatus = "Status code 11018 - Bad Destination"
            Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
            Case 11050 PingStatus = "Status code 11050 - General Failure"
            Case Else PingStatus = "Status code " & objPing.StatusCode & _
               " - Unable to determine cause of failure."
        End Select
    Next

End Function

Error that i get when i run the test now is..

(17, 1) Microsoft VBScript runtime error: Variable is undefined: 'strSubnetPrefix'

Thanks heaps for your help too i have been trying to get something working for months.


Report •

#3
May 28, 2009 at 21:58:49
Sorry i did not realise i was posting that unused funtion each time, i will edit it out.

Report •

Related Solutions

#4
May 28, 2009 at 23:42:38
I don't understand how to use strUser and strPassword with the GetObject command
Should it look like this?

No. It shouldn't be used at all; that's the job of the objWbemLocator.ConnectServer()

Error that i get when i run the test now is..
You need to Dim the variable before you use it.


Report •

#5
May 29, 2009 at 00:26:10
Thanks i have it all execpt line 54 i think, i belive that there is something wrong with how i am creating the Folder Path might need \\ or something but can not work it out.. I get an error on the line above that is the for statement.

Line 53 and 54

	For Each objFolder in colFolders
		errResults  = objFolder.Copy("\\" & strComputer & "\c$\WINDOWS\system32\")

and the whole script now i have got in your recommendations..

Error when i run script is :

<53, 2> <null>: 0x80041017

Option Explicit
Dim objPassword
Dim strUser
Dim strPassword
Dim objWbemLocator
Dim objWMIService
Dim strSystemOS
Dim strLocalpath
Dim strRemotepath
Dim strSubnetPrefix
Dim intStartSubnet
Dim intEndSubnet
Dim Administrator
Dim Desktop1
Dim i
Dim strComputer
Dim strNamespace
Dim colFolders
Dim objFolder

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const wbemConnectFlagUseMaxWait = 128
Const WbemAuthenticationLevelPktPrivacy = 6

Const OverWriteFiles = True

' Set IP range
strSubnetPrefix = "10.2.255."
intStartSubnet = 25
intEndSubnet = 25

'Asks for User/Pass/Computer
'Set objPassword = CreateObject("ScriptPW.Password") 
'WScript.StdOut.Write "Enter your user id: "
strUser = "workgroup\Administrator" 'WScript.StdIn.ReadLine
'WScript.StdOut.Write "Please enter " & strUser & " password: "
strPassword = "Desktop1" 'objPassword.GetPassword()
WSCript.Echo
'WScript.StdOut.Write "Enter System Name: "
'strComputer = WScript.StdIn.ReadLine
'WSCript.Echo
strNamespace = "root\cimv2"

For i = intStartSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
	Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objWbemLocator.ConnectServer _
	(strComputer, strNamespace, strUser, strPassword,,, wbemConnectFlagUseMaxWait)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
	Set colFolders = objWMIService.ExecQuery( _
		"Select * from Win32_Directory where Name = 'c:\\Scripts\'")
	For Each objFolder in colFolders
		errResults  = objFolder.Copy("\\" & strComputer & "\c$\WINDOWS\system32\")
		Wscript.Echo errResults
	Next	
Next 



Report •

#6
May 29, 2009 at 08:20:13
It doesn't like your ExecQuery(). Make sure C:\Scripts' exists on the client PC.

Report •

#7
May 29, 2009 at 09:14:13
"Select * from Win32_Directory where Name = 'c:\\Scripts'")
'removed the extra slash

'then do if folder exist
if col.count=0 then wsh.echo "folder not found"


Report •

#8
May 29, 2009 at 16:21:22
Yeah i have the folder i want to copy in c:\Scripts and it is a group policy folder so it is a hidden system folder would that be why it can not see it?

And i want to copy it to \\IPaddress\c$\windows\system32

I can not test these changes till monday as our remote computers are off till then, i will post back with how i go.

Thanks again everyone for your help, i am desprate to get this working and have been losing my mind over it.


Report •

#9
May 29, 2009 at 17:18:58
If this directory is on your local PC, you're doing it entirely wrong. If it is on the client PC, ignore this post.

Report •

#10
May 29, 2009 at 17:21:22
I made the changes and it takes 20sec to run but i just get folder does not exist.

I tried
c:\\scripts this is the closest to working, no errors but does not show up on remote machine, or if i have that bit of error coding posted above the it says folder not found (i changed it to if colfolders.count=0 then wsh.echo "folder not found")

and every other combination of file paths.. c:\\scripts\,


Report •

#11
May 29, 2009 at 17:23:31
Yes it is on the computer that i want to copy from (local) and want to move it to a remote machine..

Is what i have trying to copy from remote to remote?


Report •

#12
May 29, 2009 at 19:35:01
Is what i have trying to copy from remote to remote?
Pretty much, yeah.

I assume the following is closer to what you want:

Option Explicit
Dim net, fso
Dim remoteCom, remoteShare, user, password
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

remoteCom = "10.2.255.25"
user = "workgroup\Administrator"
password = "Desktop1"

remoteShare = "\\" & remoteCom & "\admin$"
net.MapNetworkDrive "", remoteShare, False, user, password
With fso.GetFolder("C:\scripts")
  If .Subfolders.Count Then _
    fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
  If .Files.Count Then _
    fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
End With
net.RemoveNetworkDrive remoteShare


Report •

#13
May 31, 2009 at 17:44:30
Yes that exactly what I want to do, surprisingly I searched the internet for a way of making a mapped drive on the remote computer and could not find anything...

I have modified the script to check if ip is a computer as there are things like IP phones, printers etc in each range.
However the script just outputs that the last IP in not a computer.
Modified script is below and I only get 10.2.222.254 is not a computer, it does not seem to keep going through the "for i =" statement...


Option Explicit
Dim net, fso, strSubnetPrefix, intStartSubnet, intEndSubnet, i
Dim remoteCom, remoteShare, user, password
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
'Set objFSO = CreateObject("Scripting.FileSystemObject") 'to check if alive

'remoteCom = "10.2.222.24"
user = "workgroup\Administrator"
password = "Desktop1"

' Set IP range
strSubnetPrefix = "10.2.222."
intStartSubnet = 1
intEndSubnet = 254

For i = intStartSubnet To intEndSubnet
	remoteCom = strSubnetPrefix & i
next
If fso.FolderExists("\\" & remoteCom & "\C$") = True Then
	remoteShare = "\\" & remoteCom & "\admin$"
net.MapNetworkDrive "", remoteShare, False, user, password
With fso.GetFolder("C:\scripts")
  If .Subfolders.Count Then _
    fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
  If .Files.Count Then _
    fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
End With
net.RemoveNetworkDrive remoteShare
Else
	wscript.echo remoteCom & " is not a Windows machine."
End If


Report •

#14
May 31, 2009 at 18:15:40
I searched the internet for a way of making a mapped drive on the remote computer and could not find anything...
Your Google-fu sucks

it does not seem to keep going through the "for i =" statement...
Move your Next. Presumably to the end of the code.


Report •

#15
May 31, 2009 at 19:56:57
I think i see where you mean but if i move it to the end the script no longer copies, it just reports that the ip is not a computer even though it is going through each ip.

modified it as such..

Option Explicit
Dim net, fso, strSubnetPrefix, intStartSubnet, intEndSubnet, i
Dim remoteCom, remoteShare, user, password
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

user = "workgroup\Administrator"
password = "Desktop1"

' Set IP range
strSubnetPrefix = "10.2.222."
intStartSubnet = 1
intEndSubnet = 254

For i = intStartSubnet To intEndSubnet
	remoteCom = strSubnetPrefix & i
If fso.FolderExists("\\" & remoteCom & "\C$") = True Then
	remoteShare = "\\" & remoteCom & "\admin$"
net.MapNetworkDrive "", remoteShare, False, user, password
With fso.GetFolder("C:\scripts")
  If .Subfolders.Count Then _
    fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
  If .Files.Count Then _
    fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
End With
	wscript.echo remoteCom & " is now updated. " & date()
net.RemoveNetworkDrive remoteShare
Else
	wscript.echo remoteCom & " is not a Windows machine. " & date()
End If
Next


Report •

#16
May 31, 2009 at 21:55:11
If fso.FolderExists("\\" & remoteCom & "\C$") = True Then
  remoteShare = "\\" & remoteCom & "\admin$"

You're trying to access a remote folder before mapping a drive with valid credentials, which is why your FolderExists() fails.

EDIT: A better way to detect the computer would be to catch any error the MapNetworkDrive() threw.


Report •

#17
May 31, 2009 at 22:02:49
I thought that the quickest way to see if it was a PC was to check if i could access the share, i will see if i can add user and password to that command,

Report •

#18
May 31, 2009 at 22:58:43
When you say catch any errors do you mean something like this?

If err.numbe=0 then
 wscript.echo "address is not a valid or not a computer"


Report •

#19
June 3, 2009 at 11:49:36
Kind of, only Err.Number = 0 means nothing went wrong, while Err.Number <> 0 means something did go wrong. Also, remember to call Err.Clear() to acknowledge the error and prevent false positives.

Report •

#20
June 3, 2009 at 17:24:08
Sorry was sick over the last few days.

I have tried to catch the errors from net.Map.Network.Drive but i get an error.

Option Explicit
Dim net, fso
Dim remoteCom, remoteShare, user, password
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

remoteCom = "10.2.222.1"
user = "workgroup\Administrator"
password = "Desktop1"

remoteShare = "\\" & remoteCom & "\admin$"
net.MapNetworkDrive "", remoteShare, False, user, password
	If err.number <> 0 then wscript.echo remoteCom & " address is not a valid or not a computer. " & date() & " " & time ()
	Err.Clear
With fso.GetFolder("C:\scripts")
  If .Subfolders.Count Then _
    fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
  If .Files.Count Then _
    fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
End With
net.RemoveNetworkDrive remoteShare
wscript.echo remoteCom & " has been updated sussesfully. " & date() & " " & time (

Error that i get is

Z:\RemoteUpdateAE.vbs(12, 1) WSHNetwork.MapNetworkDrive: The network path was no
t found.

now this error is right, as i am trying to map to the router, so the ip is alive but not a computer.
but i can not get it to display my echo and continue
(btw, get same thing if the ip is unreachable)

If the ip is valid it works fine..


Report •

#21
June 4, 2009 at 12:37:20
You haven't enabled the catching of errors; that's done by On Error Resume Next.

Option Explicit
Dim net, fso, strSubnetPrefix, intStartSubnet, intEndSubnet, i
Dim remoteCom, remoteShare, user, password
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

user = "workgroup\Administrator"
password = "Desktop1"

' Set IP range
strSubnetPrefix = "\\10.2.222."
intStartSubnet = 1
intEndSubnet = 254

On Error Resume Next
For i = intStartSubnet To intEndSubnet
  remoteShare = strSubnetPrefix & i & "\admin$"
  net.MapNetworkDrive "", remoteShare, False, user, password
  If Not Err Then
    With fso.GetFolder("C:\scripts")
      If .Subfolders.Count Then _
        fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
      If .Files.Count Then _
        fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
    End With
    wscript.echo i & " is now updated. " & date()
    net.RemoveNetworkDrive remoteShare
  Else
    wscript.echo i & " is not a Windows machine. " & date()
    Err.Clear
  End If
Next


Report •

#22
June 4, 2009 at 15:22:17
Yeah i tried something like that and i get 10.2.222.1 is now updated, when it should be an error.

I used your one but added the line for remote share and get same thing...Get the same thing for 10.2.222.2 and there is nothing on this IP..



Report •

#23
June 4, 2009 at 15:55:11
I copy/pasted the wrong version. Try it again.

Report •

#24
June 4, 2009 at 16:01:02
Shows as "1 is now updated. date" continues to next one but just says "2 is updated. date"..


Report •

#25
June 4, 2009 at 19:32:53
Awesome got it...
don't laugh at me but it was upside down...

I really cant say thanks enough for sticking in with me on this, I was really a lerning curve for me and i have to go off and learn more on a few topics such as error handling, definatly error handling...

Thanks again!

FINISHED SCRIPT:

Option Explicit
Dim net, fso, strSubnetPrefix, intStartSubnet, intEndSubnet, i
Dim remoteCom, remoteShare, user, password
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

user = "workgroup\Administrator"
password = "Desktop1"

' Set IP range
strSubnetPrefix = "10.2.222."
intStartSubnet = 1
intEndSubnet = 254

On Error Resume Next
For i = intStartSubnet To intEndSubnet
  remoteCom = strSubnetPrefix & i
remoteShare = "\\" & remoteCom & "\admin$"
  net.MapNetworkDrive "", remoteShare, False, user, password
  If err.number Then
	wscript.echo remoteCom & " is not a Windows machine. " & date() & " " & time ()
    Err.Clear
Else
	With fso.GetFolder("C:\scripts")
	  If .Subfolders.Count Then _
		fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
	  If .Files.Count Then _
		fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
End With
	wscript.echo remoteCom & " is now updated. " & date() & " " & time ()
	net.RemoveNetworkDrive remoteShare
End If
Next


Report •

#26
June 4, 2009 at 23:04:21
Just to try and push my luch, i have set it to append to a log if it updates the folder but i would like to have the computer name instead of the ip in the log (if i look in log in a week the ip will not corrispond to the right computer)

I tried to add this to it..

Jus test copy does not have the logging in it..

Option Explicit
Dim net, fso, strSubnetPrefix, intStartSubnet, intEndSubnet, i
Dim remoteCom, remoteShare, strUser, strPassword, strComputer
Set net = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(remoteCom, "root\cimv2", strUser, strPassword)
Set colSwbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_ComputerSystem")
	For Each objProcess in colSWbemObjectSet
	objItem.Name = strComputer

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strUser = "workgroup\Administrator"
strPassword = "Desktop1"
strSubnetPrefix = InputBox("Please enter the IP range. E.G ""10.10.0.""", "St. Hilliers, Update Remote Group Policy Folder")
intStartSubnet = 9
intEndSubnet = 9

On Error Resume Next
For i = intStartSubnet To intEndSubnet
  remoteCom = strSubnetPrefix & i
remoteShare = "\\" & remoteCom & "\admin$"
  net.MapNetworkDrive "", remoteShare, False, strUser, strPassword
  If err.number Then
	wscript.echo remoteCom & " is not a Windows machine. " & date() & " " & time ()
    Err.Clear
Else
	With fso.GetFolder("C:\scripts")
	  If .Subfolders.Count Then _
		fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
	  If .Files.Count Then _
		fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
End With
	wscript.echo strComputer & " is now updated. " & date() & " " & time ()
	net.RemoveNetworkDrive remoteShare
End If
Next


Report •

#27
June 13, 2009 at 20:28:18
Are you sure you want the computer's name? The only way I know how to do it would be with remote WMI.

Report •

#28
June 15, 2009 at 18:22:25
I can live with it the way it is but I would like to have the computer name returned if I can.

I thought I should be able to try something like this below, but i will not get a chance to try it for a few days yet..

End With
			Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
			Set objSWbemServices = objSWbemLocator.ConnectServer (remoteCom, "root\cimv2", "user", "password")
			objWMIServices.Security_.ImpersonationLevel = 3
			Set OpSysSet = GetObject("winmgmts:\root\cimv2").ExecQuery("select * from Win32_ComputerSystem").
		ComputerName = Name
	wscript.echo ComputerName & " is now updated. " & date() & " " & time ()
	net.RemoveNetworkDrive remoteShare
End If
Next


Report •

#29
June 17, 2009 at 07:57:27
It won't work. Really, you need to stop, take a breath, and try to figure out what you're actually copy/pasting.

This is untested, as I'm at work, but here's an updated version of what you posted:

Option Explicit
Main
WScript.Quit

Function Main
  Dim net, fso, strSubnetPrefix, intStartSubnet, intEndSubnet, i
  Dim remoteCom, remoteShare, strUser, strPassword, strComputer
  Dim locWMI
  Set net = CreateObject("WScript.Network")
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set locWMI = CreateObject("WbemScripting.SWbemLocator")

  strUser = "workgroup\Administrator"
  strPassword = "Desktop1"
  strSubnetPrefix = InputBox("Please enter the IP range. E.G ""10.10.0.""", _
    "St. Hilliers, Update Remote Group Policy Folder")
  intStartSubnet = 9
  intEndSubnet = 9

  On Error Resume Next
  For i = intStartSubnet To intEndSubnet
    remoteCom = strSubnetPrefix & i
    remoteShare = "\\" & remoteCom & "\admin$"
    net.MapNetworkDrive "", remoteShare, False, strUser, strPassword
    With fso.GetFolder("C:\scripts")
      If .Subfolders.Count Then _
        fso.CopyFolder "C:\scripts\*", remoteShare & "\system32\" 
      If .Files.Count Then _
        fso.CopyFile "C:\scripts\*", remoteShare & "\system32\"
    End With
    If Err.Number = 0 Then
      wscript.echo remoteName(locWMI, remoteCom, strUser, strPassword) & _
        " is now updated. " & Now
    Else
      wscript.echo remoteCom & " is not a Windows machine. " & Now
    End If
    net.RemoveNetworkDrive remoteShare
    Err.Clear
  Next 'i
End Function

Function remoteName(locWMI, remote, usr, pass)
  Dim WMI, c
  remoteName = remote
  On Error Resume Next
  Set WMI = locWMI.ConnectServer(remote, "root\cimv2", usr, pass)
  For Each c in WMI.InstancesOf("Win32_ComputerSystem")
    remoteName = c.Name
  Next 'c
  On Error GoTo 0
End Function


Report •

#30
July 16, 2009 at 23:41:05
Sorry this took so long to reply, as you can guess it worked perfectly. I have spent the last month pushing out folder and documents to thousands of computers! Thanks for all your help and especially your patience!

Report •


Ask Question