Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Execute a file on remote pc

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60583
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Execute a file on remote pc
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Execute a file on remote pc - 5/22/2008 7:28:28 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
Hello,

I'm trying to get this to work and was wondering if this is correct or is there a better way to execute a file using vbscript.

Here is what I'm doing now.


      wshShell.Run "cmd /C" & "\\" & strComputer & "\" & "c$\defragall.exe"

This is the UNC path to the remote computer

\\Schedule02\c$\DefragAll.exe

I'm pulling this strcomputer names from a text file.

Thanks,

Mike

 
 
Post #: 1
 
 RE: Execute a file on remote pc - 5/22/2008 7:32:46 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
wshShell.Run "cmd /c \\" & strComputer & "\c$\defragall.exe"

or

wshShell.Run "\\" & strComputer & "\c$\defragall.exe"

Oh, and this only executes on the machine running this script.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 2
 
 Execute a file on remote pc - 5/22/2008 8:14:12 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
HI, dm_4ever

So how can I execute  a file on a remote computer using vbscript to call a defragall.exe file.

Thanks,


Mike

(in reply to netman06)
 
 
Post #: 3
 
 RE: Execute a file on remote pc - 5/22/2008 9:39:31 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You can use WMI and Win32_Process class, or psexec.exe (from microsoft), or create a scheduled task via WMI or schtasks (on winxp or better), and there's a few more...how many machines are you looking at?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 4
 
 RE: Execute a file on remote pc - 5/22/2008 9:49:18 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
50 or so. from a text file. computers.txt

I'm currently looking at psexec, but I'm suck on the pathing.

return = WshShell.Run("c:\scripts\psexec.exe" & "\\" & strComputer & "c:\defragall.exe" , true)

This is the error that I'm getting.

(null): The system cannot find the file specified.

All that I need to perform in run this defrag.exe file on 50 or so windows xp pro workstations.

I just can not figure out how to run a exe file remotely.

Thanks,

Mike

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Execute a file on remote pc - 5/22/2008 9:57:25 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If defragall.exe is already on the C: drive of the 50 or so machines it would be something like

WshShell.Run "C:\scripts\psexec.exe \\" & strComputer & " C:\defragall.exe"

If the executable is not on the workstations...copy it over with PSExec if it is small enough


strSource = "\\server\share\defragall.exe"

WshShell.Run "C:\scripts\psexec.exe \\" & strComputer & " -c " & strSource

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 6
 
 RE: Execute a file on remote pc - 5/27/2008 3:36:19 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
Hi dm_4ever,
 
The above posted did work. Thanks
 
So why is it that VBScript can not execute on a remote machine, Is it with Windows or VBScript Security.
 
I have tested it and came to this conclusion that if I use this line of code
 
WshShell.Run "\\" & strComputer & "\c$\helloworld.vbs"
 
It will run Helloworld.vbs, my test script and it did a popup with Hello World msgbox.
 
So why is this working like this, you can not use runas or something like it.
 
The only program that I know of is psexec by Microsoft\Sysinternals, is there any other program that does this type of job.
 
 
I Also tried this line and it does not work either.
 
WshShell.Run "\\" & strComputer & "\c$\defragall.exe"
 
Thanks,
 
Mike
 

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Execute a file on remote pc - 5/27/2008 3:42:16 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Remote Scripting:  http://www.microsoft.com/technet/scriptcenter/topics/remote/rscripting.mspx

.Run will execute the command locally...the same as if you typed it in the "run" prompt or command line

aside from using the info in the link I posted above, PSExec or WMI can start processes on remote machines, though PSExec has a few advantages over both in my opinion

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 8
 
 RE: Execute a file on remote pc - 5/27/2008 5:13:25 AM   
  netman06

 

Posts: 107
Score: 0
Joined: 10/19/2006
Status: offline
dm_4ever,

So do you mean .Run on the local computer running the script or remote PC.

Because if I use the command DefragAll it executes it locally and not remotely.

Where as psexec will execute it remotely.


Thanks for the help and information. I'll research the provided link.

-Mike

< Message edited by netman06 -- 5/27/2008 5:17:41 AM >

(in reply to dm_4ever)
 
 
Post #: 9
 
 RE: Execute a file on remote pc - 5/27/2008 7:23:35 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
.Run will ALWAYS run on the machine executing the script

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 10
 
 RE: Execute a file on remote pc - 7/6/2008 7:17:34 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
how about if I need to do the same, for a remote PC witch is not in the same domain ?
the code here http://www.microsoft.com/technet/scriptcenter/topics/remote/rscripting.mspx
should only work one in the same Domain.
Would psexec authenticate and execute the .vbs ? any ideas?

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to dm_4ever)
 
 
Post #: 11
 
 RE: Execute a file on remote pc - 7/6/2008 11:01:44 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
You can pass the username/password for the remote PC via your psexec commandline (-u and -p).  Take a look at the help file for specific syntax.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to 4scriptmoni)
 
 
Post #: 12
 
 RE: Execute a file on remote pc - 7/7/2008 6:15:51 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
I got it! here is the code I used:
I had first to map the remote drive copy the .vbs and then use psexec to execute it


      

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to mbouchard)
 
 
Post #: 13
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Execute a file on remote pc Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts