Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sheduling VPN connection and data transfer. 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

I've been tasked with the job to write a batchfile that can be put into the windows scheduled tasks to do the following...

1. Launch the VPN decktop icon
2. Issue the map network drive command (net use)
3. Copy a file across the network
4. Disconnect the VPN

I've played with DOS Batch, START, RUNDLL etc.. and cannot seem to get the shortcut to run for the VPN connection.

I posted in the windows API and they sugested trying VBScript, a sample code was provided
Code:
Set OWS = CreateObject("Wscript.Shell")
OWS.Run("full_path to your LNK file here")
' i.e. c:\LNKFolder\MyLnk.lnk
but when I try this I get the following error
Invalid procedure call or argument [VBScript runtime error]
Can someone help as to how I can create a file that can be scheduled to acheive my required task.

If I can get a VBS file to work fine, but how would I then issue the net use command and data transfer, would it be the same method i.e. OWS.run "net use", OWS.run "copy [file] [target]" etc... and how would I then kill the VPN connection.

All help is much appreciated.

Regards,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
>OWS.Run("full_path to your LNK file here")
>' i.e. c:\LNKFolder\MyLnk.lnk

[tt]OWS.Run "%comspec% /c c:\LNKFolder\MyLnk.lnk",0[/tt]

 
Thanks for the reply, if I use that syntax nothing seems to happen, If I enclose it with ( ) brackets, I get a different error
cannot use parentheses while calling a sub
if I remove the ,0 a DOS (cmd.exe) window flashes real quick but the VPN does not start.

NOTE: if I go to DOS prompt and type c:\path\mylink and press enter the VPN runs fine and connects.

why won't this work?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
If you are monitoring for testing (rather than scheduling), change parameters for inspection.
[tt] OWS.Run "%comspec% /k c:\LNKFolder\MyLnk.lnk"[/tt]
 
To have more control and leave nothing to the caprice of folder options setting, do this.
[tt]
OWS.Run "rundll32 url.dll,FileProtocolHandler c:\LNKFolder\MyLnk.lnk"
[/tt]
 
nothing happens when I run the VBS file using rundll32 method.

I'd tried using the rundll via DOS batch and had the same problem.

I've just used the /k switch using .run and BINGO - thank you so so much [2thumbsup]

OK - now I have a few more questions.

1. How to I pause a VBS script x seconds to - give it a chance to connect.
2. How do disconnect the VPN process, probaly a kill process command would be easiest, is there one?

plus I've checked Task Manager and when the VPN connects I cannot see a process or Application relating to it.

How do i close the VPN connection after data transfer?

1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
>1. How to I pause a VBS script x seconds to - give it a chance to connect.
[tt]x=2 '2 sec
wscript.sleep x*1000
[/tt]
>2. How do disconnect the VPN process, probaly a kill process command would be easiest, is there one?
If you use in a hybrid approach, shelling out to utility just like a batch, use kill.exe utility or something alike is perfectly valid, but it depends on having it on the targetted host. For more power, run wmi script with win32_process class using terminate method. Both are not using vpn specific functionality.
 
If you use in a hybrid approach, shelling out to utility just like a batch, use kill.exe utility or something alike is perfectly valid, but it depends on having it on the targetted host. For more power, run wmi script with win32_process class using terminate method. Both are not using vpn specific functionality.

sorry you've lost me a bit there, what am I killing? I can't see anything in the processes for me to kill, this is not a 3rd party VPN client this is the inbuilt windows network connection, is there a way of querying open network connections and killing it via some API.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
oh and how do i print to the screen, like the DOS ECHO command?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Such as killing the winoa386.mod for archaic system.
[tt] kill /f winoa386.mod[/tt]
For instance, if you use tlist, do you see the vpn associated task listed out?
 
tlist ? how do I use that? , if i type it on the command line I get an error saying not a recognised internal or external command.

Maybe I should have said - today is the first time I've ever used VBScript or any of the methods you have shown, I usualy program in PERL and VBA for MS Access - so I appologise if I seem a bit thick!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
vpn should have turned up in the three-finger window or task list or any process list utility?
 
it appears in the system tray (by the clock)

If I open task manager and click the process tab I cannot see a process relating to it?

If I click the networking tab i can see the VPN name under the adapter column below the I/O graph?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
my comand line to VPN, I don't have one...

I go to My Network Places, I create a new network connection, I then right mouse click the network connection and send to desktop.

I am then openeing that shortcut .lnk - I tried to open the .lnk file to see that it contained but I just got a load of strange characters which I'm assuming is binary data, like if you viewed a JPG in notepad!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I wish I could give you more stars, you're a genius, thank you so much, rasdial is the ticket!

Now I can connect and disconnect the VPN at will, excellent!

I've nearly finished my complete VBScript, but I do have another concern, when I Map the network drive and initiate the file copy, I'm simply pausing the VBScript x seconds.

This might not be long enough for the file to transfer, how can I check if the file has finished copying before continuing with the VBScript?

Again thank you so much for all your help, I wouldn't have been able to do any of this without you, it is very much appreciated.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
and initiate the file copy
How do you do that ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

I use the following to copy the data...

Code:
' Transfer File
OWS.Run "%comspec% /k copy h:\SOURCE.BAK c:\PATH\TARGET.BAK /Y", 0


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Set the bWaitOnReturn to true. I'm also concerned why you keep using /k switch. The number of instances will accumulate! Also synchronous meant the window should be closed, but by whom? when scheduling?, before the following line be executed.
[tt]
' Transfer File
OWS.Run "%comspec% /[red]c[/red] copy h:\SOURCE.BAK c:\PATH\TARGET.BAK /Y", 0,[blue]true[/blue]
'the following line will be waited until it's completed and the window closed
[/tt]

 
cool, the reason I am using the /k switch on everything is 1 - I don't want a window to open, I have my own message box giving a running momentry and 2 if you remember nothing worked before until you provided me the /k switch, so I stuck it on everything, what does it do?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top