Page 1 of 1

How to run an application?

Posted: Thu Jan 24, 2008 5:11 am
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

How to run an application?

Posted: Thu Jan 24, 2008 5:25 am
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

How to run an application?

Posted: Thu Jan 24, 2008 5:42 am
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!!

How to run an application?

Posted: Thu Jan 24, 2008 5:49 am
by jdelatorre@hfinc.com
Its because of the spaces in the complete path.

How to run an application?

Posted: Thu Jan 24, 2008 9:21 pm
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.

How to run an application?

Posted: Thu Feb 07, 2008 4:14 am
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.

How to run an application?

Posted: Thu Feb 07, 2008 5:19 am
by bbright20
Thanks again man!

How to run an application?

Posted: Mon Feb 11, 2008 2:24 pm
by koolezt
or in script, use the FileSystemObject .ShortName property

How to run an application?

Posted: Mon Feb 11, 2008 8:24 pm
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"

How to run an application?

Posted: Mon Feb 25, 2008 10:54 pm
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.