#140659 - 2005-05-31 11:50 AM
Start shortcut
|
mima
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
|
|
|
|
#140662 - 2005-05-31 01:27 PM
Re: Start shortcut
|
Richard H.
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
|
|
|
|
#140665 - 2005-05-31 06:35 PM
Re: Start shortcut
|
Arkane
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
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
|
|
|
|
#140668 - 2005-06-01 11:28 AM
Re: Start shortcut
|
Arkane
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
|
|
|
|
#140671 - 2005-06-01 02:00 PM
Re: Start shortcut
|
mima
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
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
|
|
|
|
#140674 - 2005-06-01 11:52 PM
Re: Start shortcut
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
What kind of VPN is it?
Kent
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|