DrSpirograph
(Fresh Scripter)
2003-09-23 03:39 PM
Executing a Shortcut

I thought this would be an obvious one but I can't find it anywhere.
I want to execute a shortcut in the same directory as the script. If I double click on the shortcut or enter it's name in a cmd window it runs fine. But if I try shell or run on it from within a kix script, nothing happens. I even tried run/shelling "cmd /c shortcut.lnk" but that failed too.
How do I do this?
Alternatively, the shortcut is to bring up the connect dialog for a VPN connection, is there another way to do this from within kix (under windows 98 and 2000)


Sealeopard
(KiX Master)
2003-09-23 03:46 PM
Re: Executing a Shortcut

You need to use %COMSPEC% instead of hardcoding the command interpreter. You also need to provide the full path to the .LNK file. And please read the FAQ Forum for the differences between RUN and SHELL.

Radimus
(KiX Supporter)
2003-09-23 03:49 PM
Re: Executing a Shortcut

shell '%comspec% /c start shortcut.lnk'

DrSpirograph
(Fresh Scripter)
2003-09-30 02:14 AM
Re: Executing a Shortcut

quote:
shell '%comspec% /c start shortcut.lnk'
I tried this, but nothing happens. I pasted that directly into a test kix file and ran it (obviously i changed shortcut.lnk to the real file), the script pauses for a moment then exits.

Interestingly though, when I put a typo in the shortcut file name, I got a popup saying "cannot find vpn.lnk (or one of it's components)..." and a message is printed out
"The system cannot find the file vpn.lnk"

I should probably mention that the shortcut points to a vpn connection, but when I doubleclick the shortcut it does work (ie it brings up the dialup box)

If I replace the shortcut with one that points at an executable then it works.


LonkeroAdministrator
(KiX Master Guru)
2003-09-30 02:57 AM
Re: Executing a Shortcut

you have many ways of doing this.
anyway, before going to use action or run udf's, you should simply try:
shell "explorer shortcut.lnk"


DrSpirograph
(Fresh Scripter)
2003-09-30 03:33 AM
Re: Executing a Shortcut

quote:
shell "explorer shortcut.lnk"

That works.
Only thing is it first asks if I want to run it or download it (as if I'd clicked on it on a webpage), anyway to suppress this? (no, the "always ask this" checkbox is disabled)


LonkeroAdministrator
(KiX Master Guru)
2003-09-30 04:00 AM
Re: Executing a Shortcut

well, you also can send the lnk to notepad.
you will see something like: rasphone.pbk

with path in it.
once found use it as:
shell "C:\Documents and Settings\lonkero\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk"

should work, not 100% sure though.


Kdyer
(KiX Supporter)
2003-09-30 06:26 AM
Re: Executing a Shortcut

What VPN Software are you running? Shiva? Cisco? Windows?

Kent


DrSpirograph
(Fresh Scripter)
2003-09-30 07:40 AM
Re: Executing a Shortcut

Nope, script still does nothing when I use rasphone.pbk

I'm using the plain old windows stuff for VPN - That is go to network and dialup connections, make new connection, etc.

Basically I'm just after the same dialog box you get if you open the VPN connection from exploring into "Network and Dialup Connections", automatically connecting without the user having to press ok would be a nice bonus, but not really necissary.


Kdyer
(KiX Supporter)
2003-09-30 07:44 AM
Re: Executing a Shortcut

Dr.,

Can you get into the properties of the shortcut and paste them into a run line from the start menu?

Kent

[ 30. September 2003, 07:44: Message edited by: kdyer ]


DrSpirograph
(Fresh Scripter)
2003-09-30 08:09 AM
Re: Executing a Shortcut

I'm not sure what you mean, but I think I've tried it.
I've run
C:\Documents and Settings\chris\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk
from the command line (and start->run) and a popup asks me what connection I want to dial. But if I copy the same line that I ran into the script, the script does nothing - not even an error message.


Kdyer
(KiX Supporter)
2003-09-30 08:12 AM
Re: Executing a Shortcut

Dr.,

Look into the use of RASDIAL to complete your task..

HTH,

Kent


DrSpirograph
(Fresh Scripter)
2003-09-30 08:54 AM
Re: Executing a Shortcut

That works for 2000, but I need a solution for windows 98 as well. That's why I thought the shotcut would be good. Since I can easily just put different shortcuts on the 2000 and 98 machines, and name them the same, then the script can just execute the shortcut regardless.

mole
(Getting the hang of it)
2003-10-01 12:05 AM
Re: Executing a Shortcut

Dr. -

You should have specified that you needed a solution for both Win2K and Win9x in the first place.

I don't know if it applies in your case, since you don't specify exactly what the link points to, the exact path would be nice to see, but I do recall a nasty habit Win9x has if it runs certain *.lnk files created by Win2K on a network file share, unless the *.lnk has read-only attributes and/or file permissions set, it changes the *.lnk file to a *.pif. This was the case where the *.lnk started a *.bat anyway is my vague recollection, but it may apply to other file types as well.

There are also different ways to handle the "start" command in NT versus W9x scenarios. Branch depending upon the output from @inwin. Since "start" is a command within the command processor, cmd.exe in NT, you need to use the form:

code:
shell '%comspec% /c start "fullpathto\shortcut.lnk"'

Since start.exe is used in Win9x, external to the command processor, you shouldn'd need the %comspec% /c part:

code:
shell 'start "fullpathto\shortcut.lnk"'

Also be careful using quotes with the start command in NT-based OS's. Open a command prompt and type "start /?" (sans quotes) for the full description of proper usage of the start command in NT. It will probably try to interpret your *.lnk if its in quotes as a title for the window it opens and you'll need a second set of quotes. Based on this notion, it might be best to construct an internal variable in your script based on what @inwin returns, using chr(34) for quotes and so on.

Generally in my opinion it is messy using different combinations of %comspec%, *.lnk's and "start" in a mixed NT/9x environment to do something and its best to try to avoid it if at all possible.

mole


DrSpirograph
(Fresh Scripter)
2003-10-07 03:33 AM
Re: Executing a Shortcut

quote:
You should have specified that you needed a solution for both Win2K and Win9x in the first place.
I did in the very first post for this thread.

quote:
since you don't specify exactly what the link points to, the exact path would be nice to see
As I said, it's a shortcut to a VPN connection, as a result, the properties simply state
Target Location: Network and Dialup Connections
Target: My VPN Connection

quote:
in NT, you need to use the form:
code:
shell '%comspec% /c start "fullpathto\shortcut.lnk"'  


This also does nothing, the script just runs and exits. I've tried messing around with the quotes as you suggested, the best I get is a window with the link as the title (as you predicted). It must be something weird to do with this particular kind of shortcut.

quote:
...in Win9x...
code:
shell 'start "fullpathto\shortcut.lnk"'


This works.

SOLUTION:
I'm going to use the above in Windows 98, and under Windows 2000 it seems I can use
code:
shell '%comspec% /c "rasphone.pbk"'

(I'm going to deploy a custom phone book in the same directory as the script)

Thanks very much for all the help everyone.


Sealeopard
(KiX Master)
2003-10-07 03:38 AM
Re: Executing a Shortcut

A shortcut to a VPN connection could be anything. In my case, a shortcut to a VPN connection is actually pointing to an executable that establishes a vPN connection based on command-line parameters provided to it.

Read the FAQ Forum for the differences between SHELL and RUN.


DrSpirograph
(Fresh Scripter)
2003-10-27 01:28 AM
Re: Executing a Shortcut

quote:
A shortcut to a VPN connection could be anything.
In this case I'm talking about the native windows VPN software, nothing 3rd party. In the case of Windows 2000 this means going into the Properties of "My Network Places", using make new connection to make a VPN connection, and then creating a shortcut from the connection that subsequently appears in "Network and Dialup Connections"

The upshot of this is that shortcuts created like this are not "normal" shortcuts, they don't point to a file or an executable.


LonkeroAdministrator
(KiX Master Guru)
2003-10-27 02:51 AM
Re: Executing a Shortcut

sure they are shortcuts just like others.
and they probably point to the obvious point given to ya:
quote:
%userprofile%\ A p p l i c a t i o n D a t a \ M i c r o s o f t \ N e t w o r k \ C o n n e c t i o n s \ P b k \ r a s p h o n e . p b k


LonkeroAdministrator
(KiX Master Guru)
2003-10-27 11:18 AM
Re: Executing a Shortcut

yet one more.
once you found your VPN .pbk-file, you are able to execute it either with execution UDF (obviously my thing [Wink] ) or by just saying:
run 'rasphone.exe -f "my_vpn_pbk_file.pbk"'