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

how to run a shortcut

116 views
Skip to first unread message

Bo Rong

unread,
Oct 19, 2004, 5:16:04 AM10/19/04
to
Hello, I created some shortcuts in my desktop.

Now I want to run them in jscript.

Who can tell me how to do?


Torgeir Bakken (MVP)

unread,
Oct 19, 2004, 7:57:33 AM10/19/04
to
Bo Rong wrote:

Hi

Sadly, WScript.Shell's Run method has some issues with .lnk files unless
you use "%comspec% /c" or "rundll32.exe url.dll,FileProtocolHandler":


VBScript code, launch lnk files from script:

'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")

oShell .Run "%comspec% /C ""c:\my test\program.lnk""", 0, False

' or
oShell .Run _
"rundll32.exe url.dll,FileProtocolHandler ""c:\my test\program.lnk""" _
, 0, False

'--------------------8<----------------------

More here:

From: Gurgen (gur...@bellatlantic.net)
Subject: Re: Best way to execute a program from a vbs or wsf file
Newsgroups: microsoft.public.scripting.vbscript
http://groups.google.com/groups?selm=wuwc9.10178%24VW5.7317%40nwrddc02.gnilink.net


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Miyahn

unread,
Oct 19, 2004, 8:26:45 AM10/19/04
to
"Bo Rong" wrote in message news:el18Dxbt...@TK2MSFTNGP10.phx.gbl

> Hello, I created some shortcuts in my desktop.
>
> Now I want to run them in jscript.
Hi

Try this.

var objShell = new ActiveXObject("Shell.Application");
var objFolder;
var objFile;
var ssfDesktop = 0;
objShell = new ActiveXObject("Shell.Application");
objFolder = objShell.NameSpace(ssfDesktop);
objFile = objFolder.ParseName("MyShortcut.lnk");
objFile.InvokeVerb();

--
Miyahn (Masataka Miyashita) JPN
Microsoft MVP (Office Systems - Excel)
HQF0...@nifty.ne.jp


Miyahn

unread,
Oct 19, 2004, 8:52:30 AM10/19/04
to
"Miyahn" wrote in message news:upMlTadt...@TK2MSFTNGP14.phx.gbl

> var objShell = new ActiveXObject("Shell.Application");
> var objFolder;
> var objFile;
> var ssfDesktop = 0;
> objShell = new ActiveXObject("Shell.Application");
^ This line is unnecessary.

Bo Rong

unread,
Oct 21, 2004, 1:36:25 AM10/21/04
to
Thanks.

However, I found that shortcut extension usually vary with its type.
For instance, generally shortcut has 'lnk' extension, but internet shortcut
has 'url' extension.

It's annoyed.

And also i found another problem.

I created a shortcut to a jpeg file.
MSPaint program will be launched when I click it.

But my script can't do this.

// script
var shell = WScript.CreateObject( "Shell.Application" );
var ssfDesktop = 0x0;
var folder2 = shell.NameSpace( ssfDesktop );
var shortcut = folder2.ParseName( "jpg.lnk" );
shortcut.InvokeVerb();

Why?

"Miyahn" <HQF0...@nifty.ne.jp> wrote in message
news:Orp$GqdtEH...@TK2MSFTNGP15.phx.gbl...

Torgeir Bakken (MVP)

unread,
Oct 21, 2004, 6:17:04 AM10/21/04
to
Bo Rong wrote:

> Thanks.
>
> However, I found that shortcut extension usually vary with its type.
> For instance, generally shortcut has 'lnk' extension, but internet
> shortcut has 'url' extension.
>
> It's annoyed.
>
> And also i found another problem.
>
> I created a shortcut to a jpeg file.
> MSPaint program will be launched when I click it.
>
> But my script can't do this.
>
> // script
> var shell = WScript.CreateObject( "Shell.Application" );
> var ssfDesktop = 0x0;
> var folder2 = shell.NameSpace( ssfDesktop );
> var shortcut = folder2.ParseName( "jpg.lnk" );
> shortcut.InvokeVerb();
>
> Why?

Hi

Does it work if you use the rundll32.exe url.dll,FileProtocolHandler
method (see my other post in this thread)?

Miyahn

unread,
Oct 21, 2004, 9:25:45 AM10/21/04
to

"Bo Rong" wrote in message news:uUIBq$ytEHA...@TK2MSFTNGP12.phx.gbl

> I created a shortcut to a jpeg file.
> MSPaint program will be launched when I click it.
>
> But my script can't do this.
>
> // script
> var shell = WScript.CreateObject( "Shell.Application" );
> var ssfDesktop = 0x0;
> var folder2 = shell.NameSpace( ssfDesktop );
> var shortcut = folder2.ParseName( "jpg.lnk" );
> shortcut.InvokeVerb();

Probably, the target file is actually a bitmap file with wrong
extension.

How about this ?
shortcut.InvokeVerb("Open")

Bo Rong

unread,
Oct 21, 2004, 10:41:43 PM10/21/04
to
Yes, i try but result is same.
I think perhaps my os has some problem. :(

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:OF5Blc1t...@TK2MSFTNGP15.phx.gbl...

Bo Rong

unread,
Oct 21, 2004, 10:42:45 PM10/21/04
to
jpg.lnk is a name of shortcut to a jpeg file.
I think perhaps my system has something wrong.

"Miyahn" <HQF0...@nifty.ne.jp> wrote in message

news:uQ5LGF3t...@TK2MSFTNGP10.phx.gbl...

0 new messages