Computing.Net > Forums > Programming > Copy Folder to Computers on VPN (no domain)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Copy Folder to Computers on VPN (no domain)

Reply to Message Icon

Name: UserInterface
Date: May 28, 2009 at 20:35:34 Pacific
OS: Windows XP
Subcategory: General
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 28, 2009 at 21:03:29 Pacific
Reply:

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.


0

Response Number 2
Name: UserInterface
Date: May 28, 2009 at 21:49:29 Pacific
Reply:

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.


0

Response Number 3
Name: UserInterface
Date: May 28, 2009 at 21:58:49 Pacific
Reply:

Sorry i did not realise i was posting that unused funtion each time, i will edit it out.


0

Response Number 4
Name: Razor2.3
Date: May 28, 2009 at 23:42:38 Pacific
Reply:

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.


0

Response Number 5
Name: UserInterface
Date: May 29, 2009 at 00:26:10 Pacific
Reply:

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 



0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: May 29, 2009 at 08:20:13 Pacific
Reply:

It doesn't like your ExecQuery(). Make sure C:\Scripts' exists on the client PC.


0

Response Number 7
Name: reno
Date: May 29, 2009 at 09:14:13 Pacific
Reply:

"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"


0

Response Number 8
Name: UserInterface
Date: May 29, 2009 at 16:21:22 Pacific
Reply:

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.


0

Response Number 9
Name: Razor2.3
Date: May 29, 2009 at 17:18:58 Pacific
Reply:

If this directory is on your local PC, you're doing it entirely wrong. If it is on the client PC, ignore this post.


0

Response Number 10
Name: UserInterface
Date: May 29, 2009 at 17:21:22 Pacific
Reply:

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\,


0

Response Number 11
Name: UserInterface
Date: May 29, 2009 at 17:23:31 Pacific
Reply:

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?


0

Response Number 12
Name: Razor2.3
Date: May 29, 2009 at 19:35:01 Pacific
Reply:

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


0

Response Number 13
Name: UserInterface
Date: May 31, 2009 at 17:44:30 Pacific
Reply:

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


0

Response Number 14
Name: Razor2.3
Date: May 31, 2009 at 18:15:40 Pacific
Reply:

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.


0

Response Number 15
Name: UserInterface
Date: May 31, 2009 at 19:56:57 Pacific
Reply:

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


0

Response Number 16
Name: Razor2.3
Date: May 31, 2009 at 21:55:11 Pacific
Reply:

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.


0

Response Number 17
Name: UserInterface
Date: May 31, 2009 at 22:02:49 Pacific
Reply:

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,


0

Response Number 18
Name: UserInterface
Date: May 31, 2009 at 22:58:43 Pacific
Reply:

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"


0

Response Number 19
Name: Razor2.3
Date: June 3, 2009 at 11:49:36 Pacific
Reply:

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.


0

Response Number 20
Name: UserInterface
Date: June 3, 2009 at 17:24:08 Pacific
Reply:

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..


0

Response Number 21
Name: Razor2.3
Date: June 4, 2009 at 12:37:20 Pacific
Reply:

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


0

Response Number 22
Name: UserInterface
Date: June 4, 2009 at 15:22:17 Pacific
Reply:

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..



0

Response Number 23
Name: Razor2.3
Date: June 4, 2009 at 15:55:11 Pacific
Reply:

I copy/pasted the wrong version. Try it again.


0

Response Number 24
Name: UserInterface
Date: June 4, 2009 at 16:01:02 Pacific
Reply:

Shows as "1 is now updated. date" continues to next one but just says "2 is updated. date"..


0

Response Number 25
Name: UserInterface
Date: June 4, 2009 at 19:32:53 Pacific
Reply:

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


0

Response Number 26
Name: UserInterface
Date: June 4, 2009 at 23:04:21 Pacific
Reply:

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


0

Response Number 27
Name: Razor2.3
Date: June 13, 2009 at 20:28:18 Pacific
Reply:

Are you sure you want the computer's name? The only way I know how to do it would be with remote WMI.


0

Response Number 28
Name: UserInterface
Date: June 15, 2009 at 18:22:25 Pacific
Reply:

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


0

Response Number 29
Name: Razor2.3
Date: June 17, 2009 at 07:57:27 Pacific
Reply:

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


0

Response Number 30
Name: UserInterface
Date: July 16, 2009 at 23:41:05 Pacific
Reply:

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!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Code for fork() in cpp Why conflict?



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Copy Folder to Computers on VPN (no domain)

Batch file to copy folder www.computing.net/answers/programming/batch-file-to-copy-folder/17404.html

batch copy file on Ping Errorlevel= www.computing.net/answers/programming/batch-copy-file-on-ping-errorlevel/18016.html

Batch Job to Copy folders www.computing.net/answers/programming/batch-job-to-copy-folders-/18383.html