Page 1 of 1 1
Topic Options
#140659 - 2005-05-31 11:50 AM Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
Hi

Stupid question, but... I cant get this to work.

Trying to start a shortcut from kix script.
The name of the shortcut is "C:\Customer\start vpn connection.lnk". Trying to do the following line:
Code:

Shell '%COMSPEC% /c "C:\Customer\start vpn connection.lnk"'
? "@Error,@Serror"


I get returncode 0..but nothing is happening. If I do the same thing with notepad shortcut or any ordinary applikation it works, but the vpn connection is created from the wizard of my network connections.
If I open a command prompt and write "C:\Customer\start vpn connection.lnk" the connection is starting.


Top
#140660 - 2005-05-31 12:05 PM Re: Start shortcut
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
Try this instead

Code:
 

Shell "%COMSPEC% /c C:\Customer\start vpn connection.lnk"

? "@Error,@Serror"


_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#140661 - 2005-05-31 12:12 PM Re: Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
I renamed my shortcut to vpn.lnk so no spaces is the problem.
Tried AzzerShaw:s suggestion but with the same result as earlier. Nothing happends and it returns 0.

Top
#140662 - 2005-05-31 01:27 PM Re: Start shortcut
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
How about this:
Code:
Shell '"'+%COMSPEC%+'" /c START "C:\Customer\start vpn connection.lnk"'


Top
#140663 - 2005-05-31 01:34 PM Re: Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
No Richard, it doesnt work, it just starts a new command window.

Any more idees ?

Top
#140664 - 2005-05-31 01:39 PM Re: Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
If I open a command prompt and write "start vpn connection.lnk" the connection is started.

If I create a cmd file with one line "start vpn connection.lnk", and try to start this cmd file from explorer it does NOT work.
If I start this cmd file from a command prompt it workes.

I DONT UNDERSTAND THIS........?????????????!!!!!!!!!!

Top
#140665 - 2005-05-31 06:35 PM Re: Start shortcut
Arkane Offline
Getting the hang of it

Registered: 2004-08-14
Posts: 50
Loc: Bath, UK
I think the problem is not with your code, but the fact you are trying to RUN a windows shortcut. I've just run it in a command-window and it runs ok, yet when I try to script it, it fails (it doesn't run).

After tinkering around, I found this works...

Code:

$PRG = "C:\Documents and Settings\All Users\Start Menu\Programs\Accessories\command prompt.lnk"
Run ('%COMSPEC% /C START "$PRG"')



Obviously replace $PRG with whatever you want to run, it seems that 'START' must be called from a command-window and as such, needs that %COMSPEC% bit.

Hopefully this will fix your problem

Top
#140666 - 2005-06-01 08:56 AM Re: Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
Arkane, I dident get your suggestion to work, it only left a empty command prompt.
But I got this solution to work.
Here is my kix code:
Code:
 
$Rc = SetConsole("Hide")
Break on
$Title = "Vpn Connection / TS session"

$Answer = MessageBox("Do you want to connect to Terminal session on your company trough vpn ?","$Title",291)
If $Answer = 6 ; Yes
Shell "%COMSPEC% /e:1024 /c Start /Min C:\Vpn\Vpn.cmd"
If @Error = 0
$Answer = MessageBox("When you see 'Company is now connected' down to the right on your screen, press OK to continue..","$Title",33)
If $Answer = 1 ; OK
Shell "%COMSPEC% /c C:\Vpn\Rdp.lnk"
Endif
Else
$Answer = MessageBox("Connection failed .@CrlfError code : @Error, @SError","$Title",16)
Endif
Endif



The C:\Vpn\Vpn.cmd looks like this:
Code:

@echo off
c:\Vpn\vpn.lnk
echo "Close this window when you are finished."



If I tried to put an Exit in the Vpn.cmd the connection is not working. It seems like the Vpn connection, which is a shortcut from My Networks Connection, needs the command prompt to be open as long as it takes to start the connection..?

Well anyway, no it works, the Vpn is connecting, the customer press OK and his terminal server session starts, and then when he logs off he sees one command prompt windows left, that he just close. It is not a perfect solution, but it works.

Top
#140667 - 2005-06-01 10:40 AM Re: Start shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
why you were running with comspec in the first place?
is .lnk somekinda "dos-shortcut" I don't know about?

if this does not work:
shell "myown.lnk"

this at least will:
shell "explorer myown.lnk"
_________________________
!

download KiXnet

Top
#140668 - 2005-06-01 11:28 AM Re: Start shortcut
Arkane Offline
Getting the hang of it

Registered: 2004-08-14
Posts: 50
Loc: Bath, UK
mima: Sorry about that, I realised my mistake some time later. I had the same problem because I had to actually use the code I pasted in a project and found it didn't work.
Running a .cmd is a rather 'unclean' way to do it, particularly as all you want to do is fire up a shortcut - try this (which I know works for me... I tested it this time )
Code:

$mypath = '"c:\Vpn\vpn.lnk"'
Run ('%COMSPEC% /C "START "" /D%windir% $mypath"')


That handles things with spaces too, however I had to build my '$mypath' variable up from other things due to the way my script handles files/directories (as in I have to append a \ and the filename to the path...)

Jokeli: Yeah, a .lnk is a windows shortcut file. You can't run it with explorer.exe unfortunately and for it to work reliably you have to use %COMSPEC% with the /C switch and the 'START' command as well, quite why you need %COMSPEC% I am not sure but it wouldn't work without it. Of course the better thing to do would be to simply be able to 'extract' things from the .lnk file(s) in the first place and then run them directly but you can't do that so easily.

Top
#140669 - 2005-06-01 12:28 PM Re: Start shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
can't?
how about:
Code:

$file = "the full path to the damn lnk"

$shell=createobject("shell.application")
$file=Split($file,"\")
$folder=$Shell.namespace(Join($file,"\",UBound($file)))
$theTarget = $folder.ParseName($File[UBound($File)]).self.target
"and the target is: " $theTarget



untested though...


Edited by jokeli (2005-06-01 12:32 PM)
_________________________
!

download KiXnet

Top
#140670 - 2005-06-01 12:33 PM Re: Start shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
still, I can't compute that you can't exec lnk file... quess I'm getting old...
_________________________
!

download KiXnet

Top
#140671 - 2005-06-01 02:00 PM Re: Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
jokeli, I dont think you getting old...I said earlier in this post
Quote:

If I do the same thing with notepad shortcut or any ordinary applikation it works, but the vpn connection is created from the wizard of my network connections.




so it works to execute .lnk files, but NOT the one that have been created from My Network Connections. If you look at properties on that it doesnt seems like the other .lnk. In my working code I CAN execute my Rdp.lnk.
Code:
 If $Answer = 1 ; OK   
Shell "%COMSPEC% /c C:\Vpn\Rdp.lnk"
Endif



I will try your latest suggestion with $shell=createobject("shell.application").

Will be back with the result.

Top
#140672 - 2005-06-01 02:15 PM Re: Start shortcut
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
jokeli, I couldnt follow your code...

Code:
 $file = "C:\vpn\vpn.lnk"
$shell=createobject("shell.application")
$file=Split($file,"\")
$folder=$Shell.namespace(Join($file,"\",UBound($file)))
$theTarget = $folder.ParseName($File[UBound($File)]).self.target
? "and the target is: " $theTarget



result = nothing

What should happend ?

Top
#140673 - 2005-06-01 11:44 PM Re: Start shortcut
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, quess the shortcut is not normal.
_________________________
!

download KiXnet

Top
#140674 - 2005-06-01 11:52 PM Re: Start shortcut
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
What kind of VPN is it?

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

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 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.069 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

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