Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Remote execute batch

623 views
Skip to first unread message

freddy

unread,
Mar 26, 2008, 10:09:32 AM3/26/08
to
I have a script that goes out to each computer in a text file and check the
EPO version. If the versions are different than copy a file from the local
machine to the remote machine and execute the batch file on the remote the
problem is that it execute on the local machine - Why?
Here is the script. Thank You

Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
Dim shell
Set shell = CreateObject("WScript.shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\EPO.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
Path = ("\\"& strComputer & "\C$\Program Files\Network Associates\Common
Framework\FrameworkService.exe")
Verison = objFSO.GetFileVersion (Path)
Current = "3.6.0.546"
If version = Current Then
WScript.Echo " Version are equal"
Else
WScript.Echo " Version are not equal"
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
objFSO.CopyFolder "C:\EPO_Agent_McAfee_85i\2007\EPO_3.60_Patch1", "\\" &
strComputer & "\c$\temp\"
WScript.Echo "Copy Done, running batch file for updating EPO"
Net use
shell.Run "c:\temp\EPO_3.60_Patch1\install.bat"
End If
WScript.Echo strComputer & ":" & " EPO File Version is " &
objFSO.GetFileVersion (Path)
Loop

objTextFile.Close

Pegasus (MVP)

unread,
Mar 26, 2008, 1:13:37 PM3/26/08
to

"freddy" <fre...@discussions.microsoft.com> wrote in message
news:1FA26BE6-DE94-458D...@microsoft.com...

AFAIK you need a tool such as psexec.exe to run a program
on a remote machine. You could wrap the whole job into a
single batch file: Check the version, then run the update.


Tom Lavedas

unread,
Mar 26, 2008, 4:15:54 PM3/26/08
to


WSH 5.6 supports remote execution via the WSHController class and its
methods. I've never used it, but have seen discussions. The target
machine has to be enabled (registry setting) to permit remote
scripting, but as I said, I've never actually done it so I can't give
chapter and verse. See the WSH documentation for more info ...

Example from docs ...

Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
strComputer = "remoteservername" ' in UNC
Set RemoteScript = Controller.CreateScript("remote1.js", strComputer)
RemoteScript.Execute

Do While RemoteScript.Status <> 2
WScript.Sleep 100
Loop

Change "remote1.js" to "c:\temp\EPO_3.60_Patch1\install.bat" in this
instance. That needs to be a local path, not on the target machine, I
think. CreateScript method performs the copy to a temporary location
on the

WMI also has a class that supports remote execution. I forget which
class. I suspect that a groups.google search of "remote execution" or
"run remote script" or some such with the word "remote" will yield
more than a few threads that discuss both of these (as well as
psexec).

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Corey Thomas - MCSE/MCSA/MCDBA

unread,
Mar 27, 2008, 9:33:01 AM3/27/08
to
You can also create a batch file to kick off the script. Then create a
scheduled task with the appropriate credentials. You can then run it with
admin rights if needed.

For something like this, I usually prefer the scheduled task because it can
be faster than remote code execution.

-Corey

Richard Mueller [MVP]

unread,
Mar 27, 2008, 10:48:34 AM3/27/08
to
freddy wrote:

The Run method of the wshShell object executes the command locally. I have
an example VBScript program that deploys executables to remote computers
linked here:

http://www.rlmueller.net/Deploy.htm

This example deploys to the computers in a domain group. I find that easier
to manage. The Create method of the Win32_Process class is used to run the
executable on the remote computer, which must run silently. The program
waits for the executable to finish, then deletes it. I find that a mapped
drive must be used. The program keeps a detailed log. Hopefully this helps.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Pegasus (MVP)

unread,
Mar 27, 2008, 6:37:35 PM3/27/08
to

"Tom Lavedas" <tglb...@cox.net> wrote in message
news:2c54f910-0925-4c3c...@n75g2000hsh.googlegroups.com...

I was unable to get your script to run due to persistent ActiveX
errors but I had no problem with the following script, copied
straight from the Scripting Guy column. In the code below,
c:\Test.bat resides in \\remote\c$.

strComputer = "remote"
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objWMIService.Create "c:\test.bat", Null, Null, intProcessID
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")


Pegasus (MVP)

unread,
Mar 27, 2008, 6:42:22 PM3/27/08
to

"Tom Lavedas" <tglb...@cox.net> wrote in message
news:2c54f910-0925-4c3c...@n75g2000hsh.googlegroups.com...

We don't actually need the last line - this will suffice:

niresh....@gmail.com

unread,
Feb 8, 2013, 12:02:06 PM2/8/13
to
Please help. This is not working:
I am trying to run batch script on remote computer.


Machine 1:
testa.bat: it has below VBS
testb.vbs:
Dim sServer

sServer = "<RemoreServerName>"


Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

Set objSWbemServices = objSWbemLocator.ConnectServer(sServer, "root\cimv2", "<UserName>", "<Password>")

Set objProcess = objSWbemServices.Get("Win32_Process")

errReturn = objProcess.Create("C:\Scripts\test1.bat", Null, Null, intProcessID)

If errReturn <> 0 Then
msgbox "It could not be started due to error: " & errReturn
End If
--------------------------------------------------------------------------------------
Machine2:

test1.bat:
----------
cd C:\Scripts
test1.vbs

niresh....@gmail.com

unread,
Feb 8, 2013, 12:02:16 PM2/8/13
to

James

unread,
Mar 6, 2013, 10:52:43 AM3/6/13
to
On Thursday, March 27, 2008 6:42:22 PM UTC-4, Pegasus (MVP) wrote:
> "Tom Lavedas" <tglb...@cox.net> wrote in message news:2c54f910-0925-4c3c...@n75g2000hsh.googlegroups.com... > On Mar 26, 1:13 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: >> "freddy" <fre...@discussions.microsoft.com> wrote in message >> >> news:1FA26BE6-DE94-458D...@microsoft.com... >>>>>> >> >I have a script that goes out to each computer in a text file and check >> >the >> > EPO version. If the versions are different than copy a file from the >> > local >> > machine to the remote machine and execute the batch file on the remote >> > the >> > problem is that it execute on the local machine - Why? >> > Here is the script. Thank You>> >> > Const HKEY_LOCAL_MACHINE = &H80000002 >> > Const ForReading = 1>> > Dim shell >> > Set shell = CreateObject("WScript.shell")>> >> > Set objFSO = CreateObject("Scripting.FileSystemObject") >> > Set objTextFile = objFSO.OpenTextFile("c:\scripts\EPO.txt", ForReading) >> > Do Until objTextFile.AtEndOfStream >> > strComputer = objTextFile.Readline >> > Path = ("\\"& strComputer & "\C$\Program Files\Network >> > Associates\Common >> > Framework\FrameworkService.exe") >> > Verison = objFSO.GetFileVersion (Path) >> > Current = "3.6.0.546" >> > If version = Current Then >> > WScript.Echo " Version are equal">> > Else >> > WScript.Echo " Version are not equal" >> > set objWMIService = getobject("winmgmts://"_ >> > & strComputer & "/root/cimv2") >> > objFSO.CopyFolder "C:\EPO_Agent_McAfee_85i\2007\EPO_3.60_Patch1", "\\" >> > &>> > strComputer & "\c$\temp\" >> > WScript.Echo "Copy Done, running batch file for updating EPO" >> > Net use >> > shell.Run "c:\temp\EPO_3.60_Patch1\install.bat" >> > End If >> > WScript.Echo strComputer & ":" & " EPO File Version is " & >> > objFSO.GetFileVersion (Path)>> > Loop>> >> > objTextFile.Close>> >> AFAIK you need a tool such as psexec.exe to run a program >> on a remote machine. You could wrap the whole job into a >> single batch file: Check the version, then run the update.> > > WSH 5.6 supports remote execution via the WSHController class and its > methods. I've never used it, but have seen discussions. The target > machine has to be enabled (registry setting) to permit remote > scripting, but as I said, I've never actually done it so I can't give > chapter and verse. See the WSH documentation for more info ...> > Example from docs ...>> Dim Controller, RemoteScript > Set Controller = WScript.CreateObject("WSHController") > strComputer = "remoteservername" ' in UNC > Set RemoteScript = Controller.CreateScript("remote1.js", strComputer) > RemoteScript.Execute> > Do While RemoteScript.Status <> 2> WScript.Sleep 100 > Loop> > Change "remote1.js" to "c:\temp\EPO_3.60_Patch1\install.bat" in this > instance. That needs to be a local path, not on the target machine, I > think. CreateScript method performs the copy to a temporary location > on the> > WMI also has a class that supports remote execution. I forget which > class. I suspect that a groups.google search of "remote execution" or > "run remote script" or some such with the word "remote" will yield > more than a few threads that discuss both of these (as well as > psexec).>> Tom Lavedas> =========== > http://members.cox.net/tglbatch/wsh/We don't actually need the last line - this will suffice: strComputer = "remote"Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process") objWMIService.Create "c:\test.bat", Null, Null, intProcessID

Thanks Pegasus.
If the test.bat generates some output, such as print out some error message, how to obtain the output from the remote computer?
Thanks again!

Mayayana

unread,
Mar 6, 2013, 12:21:24 PM3/6/13
to
You're responding to a 5-year-old post! You might
want to consider getting a real newsreader and getting
off of google groups. (That would also make your
posts more readable.)

--------------------
0 new messages