Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


File Run, using script

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File Run, using script
  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 >>
 File Run, using script - 5/9/2007 1:50:00 AM   
  netman06

 

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

I'm trying to get a file to run from within the current directory. I'm currently using a batch file to perform this function.

@echo off
readme.txt

vm_3805_1.exe

But now would like to add more functions to it, and can only do these things, using vbscript.

I know how to run a file, from a specific location, but how can you run it from it's current location, which may change from time to time.

Thanks,

Mike
 
 
Post #: 1
 
 RE: File Run, using script - 5/9/2007 1:53:59 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Do you mean that you want to always run it from wherever the script is running?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 2
 
 RE: File Run, using script - 5/9/2007 1:59:37 AM   
  netman06

 

Posts: 108
Score: 0
Joined: 10/19/2006
Status: offline
Yes, that is correct.

Mike

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: File Run, using script - 5/9/2007 2:05:27 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
In that case you just need to determine the current working directory for the script and prepend it to the exe that you want to run. About the easiest way is probably:

strExeAndPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "vm_3805_1.exe")



_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 4
 
 RE: File Run, using script - 5/9/2007 2:40:51 AM   
  netman06

 

Posts: 108
Score: 0
Joined: 10/19/2006
Status: offline
Hi, ebgreen

Here is the script code.

I do not know if I have it setup right, can you please take a look at it and see, what might be wrong?

Here is the error message, that I'm getting.

Line 3, Char 1
Microsoft VBScript runtime error: Object doesn't support this property or method: 'WScript.MSJVM'

Code:
'Run script and execute files anywhere the script resides
'File Name: MSJVM.vbs

strExeAndPath = Replace(WScript.ScriptFullName, WScript.MSJVM, "vm_3805_1.exe") ' here did I setup this right with the script name.
Set WshShell = WScript.CreateObject("WScript.Shell")
If (MsgBox("Do you want to Install Microsoft Virtual Machine?",_
  vbYesNo + vbQuestion, "Question") = vbYes) Then
  WshShell.Run"strExeAndPath\vm_3805_1.exe"
  WshShell.Run"strExeAndPath\vm_3809_2.exe"
  WshShell.Run"strExeAndPath\vm_3810_3.exe"
End If

Code:
 
Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: File Run, using script - 5/9/2007 2:52:51 AM   
  netman06

 

Posts: 108
Score: 0
Joined: 10/19/2006
Status: offline
I got the path to work and do not get the error message above, but no I'm getting an error, regarding the file.

Line 9, Char4 (null): The system cannot find the file specified.

So from the error message, it is not picking up the file name, because error is null value, is that correct?

And by my above posting, I have three files, that I need to have run via the script.

Thanks,

Mike

< Message edited by netman06 -- 5/9/2007 2:56:48 AM >

(in reply to netman06)
 
 
Post #: 6
 
 RE: File Run, using script - 5/9/2007 2:53:40 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
ScriptName is a property of the WScript object. Use the line exactly as I posted it.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 7
 
 RE: File Run, using script - 5/9/2007 2:58:26 AM   
  netman06

 

Posts: 108
Score: 0
Joined: 10/19/2006
Status: offline
Hi, Ebgreen

Yes, I figure that out, but now have a new error, regarding null file name.

Mike

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: File Run, using script - 5/9/2007 3:12:56 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Well since it looks like you are actually running multiple exes from the same location, it would be best to save the location as a var then use it when running the files:

'Run script and execute files anywhere the script resides
'File Name: MSJVM.vbs

strPath = Replace(WScript.ScriptFullName, WScript.Name, "")
If (MsgBox("Do you want to Install Microsoft Virtual Machine?",_
vbYesNo + vbQuestion, "Question") = vbYes) Then
WshShell.Run strPath & "vm_3805_1.exe"
WshShell.Run strPath & "vm_3809_2.exe"
WshShell.Run strPath & "vm_3810_3.exe"
End If


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 9
 
 RE: File Run, using script - 5/9/2007 3:25:28 AM   
  netman06

 

Posts: 108
Score: 0
Joined: 10/19/2006
Status: offline
Hi, Ebgreen

That work great. Now I can customize the rest of the script for my purposes.

I always learn something new, with working with people like yourself.

Thanks for the help.

Mike   

(in reply to ebgreen)
 
 
Post #: 10
 
 
 
  

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 >> File Run, using script 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