The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
How to start VBS script on over the LAN?
Discuss How to start VBS script on over the LAN? in the Visual Basic Programming forum on Dev Shed. How to start VBS script on over the LAN? Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 8th, 2012, 04:18 PM
|
|
Contributing User
|
|
Join Date: Apr 2011
Posts: 128
Time spent in forums: 1 Day 2 h 27 m 54 sec
Reputation Power: 3
|
|
|
How to start VBS script on over the LAN?
Hi,
I was wondering how to start a VBS script from my host on the LAN computer.
Thanks, vl123456
|

March 8th, 2012, 08:51 PM
|
|
|
|
The short answer is "you can't"
There are tools available that allow you to run programs on a remote machine, for example if you have ssh available you can fire off a command line program. And I think for windows sysinternals.com has a remote execution tool.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
|

March 8th, 2012, 10:12 PM
|
 |
|
|
Join Date: Jan 2004
Location: New Springfield, OH
|
|
Doug is correct. For security reasons there is no direct method of executing a command on a remote machine without using something like SSH or a tool such as PsExec. You can also use remote scripting. If you have proper permissions on the remote machine, you can run scripts from your current machine that execute on the remote machine.
Here's how it works. You run a script on your local machine that uses the FileSystemObject to copy a prewritten script file to a remote machine on your network. You'll need it's UNC path and proper credentials. Then, using WMI you can run the script (or any other command line for that matter) by starting a process on the target machine. A pure scripting example looks something like this.
vb Code:
Original
- vb Code |
|
|
|
Set objFso = CreateObject("Scripting.FileSystemObject") objFso.CopyFile "myscript.vbs" "\\remotecomputer\c$\myscript.vbs" strComputer = "remotecomputer" Set objWMIService = GetObject _ ("winmgmts:{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2:Win32_Process") strCommandLine = "cmd.exe /c cscript.exe c:\myscript.vbs" errReturn = objWMIService.Create(strCommandLine, vbNull, vbNull, intProcessID)
Last edited by Nilpo : March 8th, 2012 at 10:15 PM.
|

March 9th, 2012, 12:53 PM
|
|
Contributing User
|
|
Join Date: Apr 2011
Posts: 128
Time spent in forums: 1 Day 2 h 27 m 54 sec
Reputation Power: 3
|
|
|
First, thank you Doug and Nilpo for helping me!
I’m not a programmer, I’m just trying to make my life easier by automating some processes on the machines I’m working with. Basically I’m pulling evt logs and processing them. I found and modified a script for that. It stores decompressed EVT logs as a text file to the “host” and now I want to “call” my EVT.vbs script “from the host machine", I have all the credentials and I’ll try Nilpo’s script during weekend.
I do not want to “schedule” my EVT.vbs script on my local machines, I want to “cal it” from the “host”.
Thank you guys again. Vl123456
|

March 9th, 2012, 01:02 PM
|
|
Contributing User
|
|
Join Date: Apr 2011
Posts: 128
Time spent in forums: 1 Day 2 h 27 m 54 sec
Reputation Power: 3
|
|
|
My bad!
Actually my EVT.vbs script does not store decompressed EVT.txt to the “host”. It stores locally in the “home” folder and then I’m using XCOPY batch file that pulls the EVT.text file from the “local” machines to the “host”.
Sorry about this, VL123456
|

March 9th, 2012, 03:38 PM
|
 |
|
|
Join Date: Jan 2004
Location: New Springfield, OH
|
|
|
You're just reading event logs? Windows provides a tool for that. WMI (Windows Management Instrumentation) is capable of reading events and is designed to work on remote machines. That's the technology my script above is using to launch a process on the remote machine. From what it sounds like, WMI can do the whole process for you by design. Can you provide more details about what you're trying to find?
|

March 9th, 2012, 11:55 PM
|
|
Contributing User
|
|
Join Date: Apr 2011
Posts: 128
Time spent in forums: 1 Day 2 h 27 m 54 sec
Reputation Power: 3
|
|
Thank you for your help Nilpo!
I'm pulling out "System" even logs (from the systems on LAN) then using special .exe and a .bat that decompresses the event logs and gives me only the events I'm interested in and stores them in the home dir on each machine as a TXT file. Then using Perl (I'm comfortable with Perl) I'm sorting/processing the EVTs and sending them to the server. The only missing part was the way to get these TXT files from locals to the host com.
I got VBS script (thanks to Google) to pull the EVT logs, I also modified it so it pulls EVTs, decompresses and stores it to the home dir on each local machine. I was thinking to use a VBS script to get the TXT files from the local machines. Actually today, I managed to transfer the TXT files from the local comps with Perl.
Code:
my $cmd = "copy C:\\fromhere C:\\tothere \/y";
system ("$cmd") ;
I cannot use Perl on these local machines - not allowed.That is why I wanted to use VBS that I know nothing about.
Thank you again for you time Nilpo .
Vl123456
|

March 10th, 2012, 01:07 AM
|
 |
|
|
Join Date: Jan 2004
Location: New Springfield, OH
|
|
I guess what I'm getting at is that you don't need to do anything on the remote machines at all. You can do all of this from one location. A WMI script can poll remote machines for only the event information you want and store it locally...any way you want. Then you can use Perl or whatever you wish to crunch the data. For instance, let say I wanted to check every computer on my network for bluescreens and improper shutdowns. I could do something like this.
vb Code:
Original
- vb Code |
|
|
|
arrComputers = Array("Computer1", "Computer2", "Computer3") For Each strComputer in arrComputers Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * from Win32_NTLogEvent Where Logfile = 'System'" _ & " and SourceName = 'SaveDump' " _ ' Stop Events & " or EventCode = '6008'") ' Improper Shutdown For Each objEvent in colLoggedEvents Wscript.Echo "Event date: " & objEvent.TimeGenerated Wscript.Echo "Description: " & objEvent.Message Next Next
The script can even be written to do the work asynchronously to speed it up a little.
|

March 12th, 2012, 09:21 PM
|
|
Contributing User
|
|
Join Date: Apr 2011
Posts: 128
Time spent in forums: 1 Day 2 h 27 m 54 sec
Reputation Power: 3
|
|
|
Yes, as you can see I'm kind of using CMD (from Perl) to pull out my logs from each local machine.
I'm OK with that for now but I was wondering how I could call "my VBS" script on each machine from the host. I'm using Perl to manipulate the logs.
Thank you for your help Nilpo!
Vl123456
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|