mima
(Hey THIS is FUN)
2005-05-31 11:50 AM
Start shortcut

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.



AzzerShaw
(Seasoned Scripter)
2005-05-31 12:05 PM
Re: Start shortcut

Try this instead

Code:
 

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

? "@Error,@Serror"




mima
(Hey THIS is FUN)
2005-05-31 12:12 PM
Re: Start shortcut

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.


Richard H.Administrator
(KiX Supporter)
2005-05-31 01:27 PM
Re: Start shortcut

How about this:
Code:
Shell '"'+%COMSPEC%+'" /c START "C:\Customer\start vpn connection.lnk"'



mima
(Hey THIS is FUN)
2005-05-31 01:34 PM
Re: Start shortcut

No Richard, it doesnt work, it just starts a new command window.

Any more idees ?


mima
(Hey THIS is FUN)
2005-05-31 01:39 PM
Re: Start shortcut

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........?????????????!!!!!!!!!!


Arkane
(Getting the hang of it)
2005-05-31 06:35 PM
Re: Start shortcut

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


mima
(Hey THIS is FUN)
2005-06-01 08:56 AM
Re: Start shortcut

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.


LonkeroAdministrator
(KiX Master Guru)
2005-06-01 10:40 AM
Re: Start shortcut

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"


Arkane
(Getting the hang of it)
2005-06-01 11:28 AM
Re: Start shortcut

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.


LonkeroAdministrator
(KiX Master Guru)
2005-06-01 12:28 PM
Re: Start shortcut

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...


LonkeroAdministrator
(KiX Master Guru)
2005-06-01 12:33 PM
Re: Start shortcut

still, I can't compute that you can't exec lnk file... quess I'm getting old...

mima
(Hey THIS is FUN)
2005-06-01 02:00 PM
Re: Start shortcut

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.


mima
(Hey THIS is FUN)
2005-06-01 02:15 PM
Re: Start shortcut

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 ?


LonkeroAdministrator
(KiX Master Guru)
2005-06-01 11:44 PM
Re: Start shortcut

k, quess the shortcut is not normal.

Kdyer
(KiX Supporter)
2005-06-01 11:52 PM
Re: Start shortcut

What kind of VPN is it?

Kent