Solved

How do I run a VPN Connection .lnk?

Posted on 2010-09-04
9
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 33604821
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 42

Author Comment

by:dlmille
ID: 33607326
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 42

Author Comment

by:dlmille
ID: 33607334
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Accepted Solution

by:
Qlemo earned 125 total points
ID: 33607992
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
 
LVL 42

Author Comment

by:dlmille
ID: 33629981
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 42

Author Comment

by:dlmille
ID: 33631410
Indeed, it works.  Thanks alot for your help!
0
 
LVL 42

Author Closing Comment

by:dlmille
ID: 33631439
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 70

Expert Comment

by:Qlemo
ID: 33631603
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 42

Author Comment

by:dlmille
ID: 33632397
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Secure VPN Connection terminated locally by the Client.  Reason 442: Failed to enable Virtual Adapter. If you receive this error on Windows 8 or Windows 8.1 while trying to connect with the Cisco VPN Client then the solution is a simple registry f…
OpenVPN is a great open source VPN server that is capable of providing quick and easy VPN access to your network on the cheap.  By default the software is configured to allow open access to your network.  But what if you want to restrict users to on…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

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