Page 1 of 1 1
Topic Options
#45854 - 2003-09-23 03:39 PM Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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)

Top
#45855 - 2003-09-23 03:46 PM Re: Executing a Shortcut
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#45856 - 2003-09-23 03:49 PM Re: Executing a Shortcut
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
shell '%comspec% /c start shortcut.lnk'
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#45857 - 2003-09-30 02:14 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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.

Top
#45858 - 2003-09-30 02:57 AM Re: Executing a Shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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"
_________________________
!

download KiXnet

Top
#45859 - 2003-09-30 03:33 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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)

Top
#45860 - 2003-09-30 04:00 AM Re: Executing a Shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#45861 - 2003-09-30 06:26 AM Re: Executing a Shortcut
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
What VPN Software are you running? Shiva? Cisco? Windows?

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#45862 - 2003-09-30 07:40 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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.

Top
#45863 - 2003-09-30 07:44 AM Re: Executing a Shortcut
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#45864 - 2003-09-30 08:09 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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.

Top
#45865 - 2003-09-30 08:12 AM Re: Executing a Shortcut
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Dr.,

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

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#45866 - 2003-09-30 08:54 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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.
Top
#45867 - 2003-10-01 12:05 AM Re: Executing a Shortcut
mole Offline
Getting the hang of it

Registered: 2003-01-01
Posts: 76
Loc: Indian Head, Maryland, USA
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
_________________________
mole

Who is John Galt?

Top
#45868 - 2003-10-07 03:33 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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.

Top
#45869 - 2003-10-07 03:38 AM Re: Executing a Shortcut
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#45870 - 2003-10-27 01:28 AM Re: Executing a Shortcut
DrSpirograph Offline
Fresh Scripter

Registered: 2003-09-23
Posts: 8
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.

Top
#45871 - 2003-10-27 02:51 AM Re: Executing a Shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#45872 - 2003-10-27 11:18 AM Re: Executing a Shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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"'
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org