Solved

How do I run a VPN Connection .lnk?

Posted on 2010-09-04
9
561 Views
Last Modified: 2012-05-10
I've created a .lnk file that has everything setup, including userID and password.  I need to run this from the task scheduler.

Will the START command work here?  e.g., START as the command with the parameters "" "mylink.lnk" ?

Almost as important is being able to run the VPN.lnk command from a VBS script. I can't seem to initiate a START command from the VBS script, using the Wscript.shell.run command (yes, I can run other things, but not the start command).  not sure why - is it a syntax thing or is START something that can't be run from the VBS script?

Thanks for the help!

Dave
0
Comment
Question by:dlmille
  • 6
  • 3
9 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
START is part of the CMD prompt, so you need to start cmd first.
However, you cannot use START in conjunction with a .lnk file. You need to start explorer instead:
   explorer test.lnk
will run the commands included in the shortcut file. The same should work from VBS with the run method.
0
 
LVL 41

Author Comment

by:dlmille
Comment Utility
Qlemo - actually, you can use START in conjunction with a .lnk file.  Try it from the command line - works great.

I tried explorer xxx.lnk with no evidence that it actually worked (I had set up the VPN to prompt for password, and it didn't so for some reason explorer xxx.lnk didn't work)

What I'd like to do is initiate the .lnk from a VBS in a minimized or hidden way.  Initiating a START command somehow in VBS perhaps could work, just can't seem to write the code properly.  START has a way to do that just great, whereas doing a wshell.run "%comspec% whatever.lnk" doesn't seem to work as the CMD.exe doesn't seem to have switches for running hidden or in the background.

When I try wshell.run "start /k whatever.lnk" I get an error file not found.
0
 
LVL 41

Author Comment

by:dlmille
Comment Utility
The below code:  the %comspec% line works, but pushes a CMD on the stack and creates a visible window that if closed appears to kill the process running the .lnk

The run command with "Start" gives me a cannot find the file error

I thought I could create the string str and run that, but didn't work either...


dim str
Set OWS = CreateObject("WScript.Shell")
str = "Start " & """Title""" & " xxx.lnk"
wscript.echo str
OWS.run "%comspec% /k  XXX.lnk"
OWS.run "Start xxx.lnk"
wscript.echo "Done"
Set OWS = nothing
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 125 total points
Comment Utility
Sorry, but whenever I run start "" test.lnk, no matter whether the link points to a txt file or contains batch commands or points to a exe, I get the message "This file does not have a program associated with it for performing this action.".
explorer test.lnk however always works.

Anyways, that doesn't help you. The WshShell.Run method as two optional parameters, and the first one is for the Window state. For explanation, see http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx. Using that, one way to start the .lnk is:
   OWS.run "cmd /c XXX.lnk", 0

%comspec% /K doesn't make much sense. /K leaves the DOS prompt open after the command is executed. /c will terminate cmd.exe as soon as the command has finished. You would have wanted a combination of "cmd /c start /min XXX.lnk", maybe, but that will produce a "flashing" cmd window, which vanishes always immediately.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 41

Author Comment

by:dlmille
Comment Utility
I believe the ows.run "explorer xxx.lnk",2,0 will work for me.  I've tested it in a test environment and now need to put it in production.  If it works, I'll award points.  If not, I'll come back with the result for more input.
0
 
LVL 41

Author Comment

by:dlmille
Comment Utility
Indeed, it works.  Thanks alot for your help!
0
 
LVL 41

Author Closing Comment

by:dlmille
Comment Utility
I was not given the solution (how to run START from task scheduler or from VBS) I was looking for exactly.  However, I was given an alternative (re: use explorer to kick off the lnk file).  The provider did not seem to understand the nuances of the CMD /k and why CMD /c would not work.  I had to try several attempts of the vbscript to understand how to minimize the instance and run to completion, which caused me to look for online references for the .run command to achieve that.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Hmm. I gave you the link to understand the RUN method, I explained why your START approach does not work, and that cmd /k doesn't make sense. You never tried to tell why you are so keen on using cmd /k, and so I could not rectify that.

What you have used is a slight variation of my code example. Really, I had more work with verifying your statements and trying to find a solution, than you should have had with implementing my recommendations.

But don't bother, we can leave it at that. Just don't expect to get a ready-to-use solution here all the time, and in particular not for 125 points. Main reason for many Experts to answer on EE is that others can learn how things work, but many weight effort against points nevertheless.
0
 
LVL 41

Author Comment

by:dlmille
Comment Utility
You made some good points.  CMD /c did not work, while /k did for me and I can't explain why either, except that the VPN process never got kicked off with the /c command.  However, given the points, effort, and the fact that I used your solution re: the explorer.exe command, I would upgrade my assessment/rating if I could.

Thanks for your thoughtful response,

Dave
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I recently attended Cisco Live! in Las Vegas, a conference that boasted over 28,000 techies in attendance, and a week of hands-on learning hosted by a solid partner with which Concerto goes to market.  Every year, Cisco displays cutting-edge technol…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now