#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    128
    Rep Power
    4

    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
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,448
    Rep Power
    4539
    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.

    Comments on this post

    • Nilpo agrees
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    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:
    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 11:15 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    128
    Rep Power
    4
    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
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    128
    Rep Power
    4
    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
  10. #6
  11. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    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?
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    128
    Rep Power
    4
    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
  14. #8
  15. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    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:
    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.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    128
    Rep Power
    4
    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

IMN logo majestic logo threadwatch logo seochat tools logo