How to run an application?

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ericn84
Posts: 3
Last visit: Thu Jan 24, 2008 9:21 pm

How to run an application?

Post by ericn84 »

Hi,I am very new to VBScript and I was asked to create a VBScript for a user to double click on and it will load up all the users desired applications.When I did some searching, it looks like I want to use the Windows Script Host run method. However, the problem that I am running into is that it will not open the applications I want.When I tried to find more information about run, all the tutorials I can find use note pad as an example. But, I want to run an application that I need to specify the directory that it is located. For example, I want to have the application start internet explorer which is located at "C:Program FilesInternet ExplorerIEXPLORE.EXE" but it says it cannot find the file.Here is what my script looks like:Dim WshShellSet WshShell = CreateObject("WScript.Shell")WshShell.Run "C:Program FilesInternet ExplorerIexplore.exe"I have tried putting the direction in ( ) and without, but it still says it cannot find the file. Can anyone please help me?Thank you
User avatar
jdelatorre@hfinc.com
Posts: 54
Last visit: Wed Jan 30, 2008 1:42 am

How to run an application?

Post by jdelatorre@hfinc.com »

YOu can run this

Code: Select all

wshshell.run "iexplore.exe"
or this

Code: Select all

WshShell.Run "C:PROGRA~1INTERN~1Iexplore.exe"
Iexplorer.exe is in you path so you dont have to pass the complete path to the run command.

jdelatorre@hfinc.com2008-01-24 13:25:49
User avatar
ericn84
Posts: 3
Last visit: Thu Jan 24, 2008 9:21 pm

How to run an application?

Post by ericn84 »

Thank you jdelatorre, using the path of:"C:PROGRA~1INTERN~1Iexplore.exe"
Works great! Didn't even think that I would have to use the abbreviated file path locations like the old command/DOS days.Thanks again for your help!!
User avatar
jdelatorre@hfinc.com
Posts: 54
Last visit: Wed Jan 30, 2008 1:42 am

How to run an application?

Post by jdelatorre@hfinc.com »

Its because of the spaces in the complete path.
User avatar
ericn84
Posts: 3
Last visit: Thu Jan 24, 2008 9:21 pm

How to run an application?

Post by ericn84 »

Now I have run into another snag that I am trying to find. One of the apps that I need to open is Microsoft Office and I am unable to open it using just "Outlook.exe". So, I am trying to point to that directory however I have several directories that start with Microsoft and has a space. I am not sure how I should be able to navigate to that directory.
User avatar
bbright20
Posts: 27
Last visit: Tue Dec 07, 2010 10:50 pm

How to run an application?

Post by bbright20 »

How do you know which directories to abbreviate using the "~"?

For example: My outlook is located at:

C:Program FilesMicrosoft OfficeOffice10OUTLOOK.EXE

Is there a "view" option somewhere in windows that will enable the abbreviated view so I can correctly name the paths to the programs I need started?

Thanks.
User avatar
bbright20
Posts: 27
Last visit: Tue Dec 07, 2010 10:50 pm

How to run an application?

Post by bbright20 »

Thanks again man!
User avatar
koolezt
Posts: 15
Last visit: Sat Jun 19, 2010 5:12 am

How to run an application?

Post by koolezt »

or in script, use the FileSystemObject .ShortName property
User avatar
bbright20
Posts: 27
Last visit: Tue Dec 07, 2010 10:50 pm

How to run an application?

Post by bbright20 »

Can you provide an example?

Here's a snippet of my code with the abbreviated paths:

Code: Select all

WshShell.Run "C:Progra~1Xtende~1Conten~1Aex32.exe"
	
WshShell.Run "C:Progra~1Pinpoi~1RightCADRCLOADER.exe"
	
WshShell.Run "C:Progra~1Micros~2Office10Outlook.exe"
User avatar
koolezt
Posts: 15
Last visit: Sat Jun 19, 2010 5:12 am

How to run an application?

Post by koolezt »

Sorry for the delay, but I had password problems logging in here.

Actually, there's a more direct option: placing quotes around the long filename. (That's ALWAYS a good idea, to cater for embedded blanks.)

Something like this (untested) should do the trick:

Code: Select all

WshShell.Run """" & "C:Program FilesMicrosoft OfficeOFFICE10OUTLOOK.EXE" & """"
I use JavaScript, so it's a bit different, but to relieve the drudgery of the """" envelopes, I use something like

Code: Select all

Function strQuoted(strIn)
    strQuoted = """" & strIn & """"
End Function
and I would use[
code]strCommand = "C:Program FilesMicrosoft OfficeOFFICE11OUTLOOK.EXE"
WShShell.Run strQuoted(strCommand)[/code]

Then again, you could always make something like RunCommand(strCommand) to do something like

Code: Select all

WshShell.Run strQuoted(strCommand)
tidying-up the whole package.
This topic is 16 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked