Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Best way to execute a program from a vbs or wsf file

42 views
Skip to first unread message

Finn McGowan

unread,
Aug 30, 2002, 9:33:34 AM8/30/02
to
What would be the best way to execute a file from a VBS or
WSF file. I have tried Wshell.run, shell and shellexecute.
the programs I'm trying to run could be shortcuts, other
scripts, URL's and exe's.

the attached file shows how I've been attempting to do
this with mixed results.

the shell run will run an exe but seems unable to launch a
shortcut. shell and shellexecute give type mismatches
regardless of how I 'type' my variables.

Thanks

Michael Harris (MVP)

unread,
Aug 30, 2002, 9:12:25 PM8/30/02
to

WshShell.Run, WshShell.Exec, Shell.ShellExecute (plus a few others) can all execute *.lnk files. And they all follow the same rules requiring executable paths that include spaces to be enclosed in quotes...

sPath = "c:\my path with spaces\my pgm with spaces.exe"

won't work when passed to any of the above methods.


sPath = """c:\my path\mypgm.exe"""
sPath = Chr(34) & "c:\my path\mypgm.exe" & Chr(34)

will work because the quotes are included...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Torgeir Bakken

unread,
Sep 1, 2002, 4:34:03 PM9/1/02
to
"Michael Harris (MVP)" wrote:

> Finn McGowan wrote:
> > What would be the best way to execute a file from a VBS or
> > WSF file. I have tried Wshell.run, shell and shellexecute.
> > the programs I'm trying to run could be shortcuts, other
> > scripts, URL's and exe's.
> >
> > the attached file shows how I've been attempting to do
> > this with mixed results.
> >
> > the shell run will run an exe but seems unable to launch a
> > shortcut. shell and shellexecute give type mismatches
> > regardless of how I 'type' my variables.
> >
>
> WshShell.Run, WshShell.Exec, Shell.ShellExecute (plus a few others) can all execute *.lnk files.

Hi

At least on Win2k and better, WshShell.Run "drive:\somepath\somefile.lnk" will not work if the lnk-file is made by MSI.


When trying to use the WScript.Shell Run method to start a MSI created link file you will
get this error:

Microsoft VBScript runtime error: Permission denied

--
torgeir


alex_k._angelopoulos_(mvp)

unread,
Sep 1, 2002, 5:06:08 PM9/1/02
to
Torgeir, made by an MSI - or one that points to an MSI, like the Office
app shortcuts?

--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com


"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3D7279BA...@hydro.com...

Torgeir Bakken

unread,
Sep 1, 2002, 5:14:37 PM9/1/02
to
"Alex K. Angelopoulos (MVP)" wrote:

> Torgeir, made by an MSI - or one that points to an MSI, like the Office
> app shortcuts?

Hi

Made by an MSI installation, like e.g. the Office 2k/XP shortcuts. If you select
one of those and select properties, you will see that you can't edit (or really
see) e.g. the target path part.

--
torgeir


alex_k._angelopoulos_(mvp)

unread,
Sep 1, 2002, 6:18:26 PM9/1/02
to
That's right, I forgot those really did have the standard LNK
extension...

--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com


"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message

news:3D72833C...@hydro.com...

Gurgen

unread,
Sep 1, 2002, 6:26:36 PM9/1/02
to
An old trick should work:

set oShell = CreateObject("wscript.shell")
oShell.run chr(34) & "C:\WINNT\Profiles\All Users\Start Menu\Programs\Administrative Tools\Active Directory Users and
Computers.lnk" & chr(34) >-- 'Error: Permission denied.
oShell.run "rundll32 url.dll,FileProtocolHandler " & "D:\WINNT\Profiles\All Users\Start Menu\Programs\Administrative Tools\Active
Directory Users and Computers.lnk" --> Opens mmc

Try to see if it works on MSI created MS Office shortcuts. Mine are in a custom location...


regards,
--
Gurgen Alaverdian
http://www.gurgensvbstuff.com
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message news:3D7279BA...@hydro.com...

Torgeir Bakken

unread,
Sep 1, 2002, 6:48:23 PM9/1/02
to
Gurgen wrote:

> An old trick should work:
>
> set oShell = CreateObject("wscript.shell")
> oShell.run chr(34) & "C:\WINNT\Profiles\All Users\Start Menu\Programs\Administrative Tools\Active Directory Users and
> Computers.lnk" & chr(34) >-- 'Error: Permission denied.
> oShell.run "rundll32 url.dll,FileProtocolHandler " & "D:\WINNT\Profiles\All Users\Start Menu\Programs\Administrative Tools\Active
> Directory Users and Computers.lnk" --> Opens mmc
>
> Try to see if it works on MSI created MS Office shortcuts. Mine are in a custom location...

Hi

All other methods to launch a shortcut works (e.g. the rundll trick as well as the shell.application ShellExecute method), this has
been discussed in previous threads in the scripting newsgroups. It's the oShell.Run that has problems :(

--
torgeir


alex_k._angelopoulos_(mvp)

unread,
Sep 1, 2002, 6:59:48 PM9/1/02
to
It works indeed.

--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com


"Gurgen" <gur...@bellatlantic.net> wrote in message
news:wuwc9.10178$VW5....@nwrddc02.gnilink.net...

0 new messages