Jump to content

Help With Batch File


Recommended Posts

I want to automate the way a group of user is connecting to a Remote Computer using our VPN and RDC (Windows Remote Desktop Connection). :hello:

First, I've managed to get a batch file like this one:

start Extranet.exe -auth 0 -user LOGIN -pwd PASSWORD -serverip 000.000.000.000 -s
start %SystemRoot%\system32\mstsc.exe REMOTECOMPUTER.rdp

The only problem is that there is a halt box where I have to click OK after the VPN connection is established... (the VPN client is Nortel Contivity)

And then, there is a warning message with RDC telling that I will be sharing my Hard Drive and once again I have to click OK

Any way to send the ENTER key with a batch file? Or maybe it is possible to use AutoIT but I'm not too familiar with this program...

Link to comment
Share on other sites


Batch wont do what youre looking for, youll need to use AutoIt or VBScript. Ive never used AutoIt, but for VBScript...

Open notepad and copy the following text into it...

Set WshShell = WScript.CreateObject("WScript.Shell")

' Set %Systemdrive% variable to 'SYSD'
SYSD = WshShell.ExpandEnvironmentStrings("%Systemdrive%")

' Launch Nortel App
WshShell.Run  ("Extranet.exe -auth 0 -user LOGIN -pwd PASSWORD -serverip 000.000.000.000 -s")
' Wait until Nortel App comes up
Do until WshShell.AppActivate ("PLACE TEXT OF TITLEBAR OF YOUR NORTEL PROMPT HERE")
   WScript.Sleep 2000
Loop

' Hit Enter
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000

'Launch RDC
WshShell.Run  (SYSD & "\system32\mstsc.exe REMOTECOMPUTER.rdp")

' Wait until RDC box comes up
Do until WshShell.AppActivate ("PLACE TEXT OF TITLEBAR OF THE RDC PROMPT HERE")
   WScript.Sleep 2000
Loop

' Hit Enter
WshShell.SendKeys "{ENTER}"

Edit the "WshShell.AppActivate" lines and place in the text of the Titlebars of the app prompt windows as mentioned.

Save it as <whatever>.vbs and place this in the same location as 'Extranet.exe' and 'REMOTECOMPUTER.rdp'

This should work, but without testing with the actual apps cant guarantee itll work of course...

Link to comment
Share on other sites

Thank you so much DUREX!  :thumbup

Your VBS Skills kills! :ph34r: (but you forgot to put \WINDOWS\... in front of System32\mstsc.exe)  :P

BTW, is there a way to compile this script to a standalone .EXE ?

Np.. as far as the 'forgot to put windows in fron of sys32' I did put it in front of it.. thats what the 'SYSD &' is for... if you look at the top of the script SYSD is set to %systemdrive% and the '&' symbol concatenates (aka puts together) that variable with the rest of the line in quotes.

And to be honest, if you want to get into symantics, you dont need the 'C:\windows\system32' in front of mstsc.exe anyway because the sys32 directory is in your system path, which means you can actually launch any executables that reside in that directory from anywhere.

G'head and try it.. just goto Start>Run and type 'mstsc', itll launch without issue (should)

And lastly in regards to compiling this to exe, if you have Microsofts Visual Studio you can compile it.. im not aware of any other 3rd party apps that do this (although there may be one that exists)

Link to comment
Share on other sites

And to be honest, if you want to get into symantics, you dont need the 'C:\windows\system32' in front of mstsc.exe anyway because the sys32 directory is in your system path, which means you can actually launch any executables that reside in that directory from anywhere.

Yep! you're right!!! :o Almost forgot about that...

Is there a way to use a variable to get to the Nortel Network Folder?

I've tried this without success:

' Set %ProgramFiles% variable to 'PROG'
PROG = WshShell.ExpandEnvironmentStrings("%ProgramFiles%")

' Launch Nortel App
WshShell.Run  (PROG & "Nortel Networks\Extranet.exe -auth 0 -user LOGIN -pwd PASSWORD -serverip 000.000.000.000 -s")

Link to comment
Share on other sites

echo %programfiles% at the command prompt... it should return 'C:\Program Files' (assuming progfiles is on your c drive) so using your syntax youre actually running 'C:\ProgramFilesNortel Networks\Extranet.net'... see the problem?? ;)

the syntax you want is

WshShell.Run  (PROG & "\Nortel Networks\Extranet.exe...

Link to comment
Share on other sites

Regardless of what drive ProgFiles is on, the variable should point to the correct drive. When you get there error, what does it say? and what line does it say it occurs on?

Its def not the space in your folder.. vbscript doesnt read in like batch does.. in other words it will look at the entire path and not up until a space like batch does (unless you have it in quotes)

Link to comment
Share on other sites

Here A Test Vbs I Ran And The Code Work On My Computer

Adjust To Your Needs

Set Action = CreateObject("wscript.shell")

SysDr =Action.ExpandEnvironmentStrings("%SystemDrive%")

Sysdr= SysDr & "\Program Files\ZZ YY XX 123"

Action.run (Chr(34) & SysDr & "\Hello It My Cmd Window.cmd" & Chr(34))

Link to comment
Share on other sites

humm... this doesn't work:

Set Action = CreateObject("wscript.shell")
PROG =Action.ExpandEnvironmentStrings("%ProgramFiles%")
Action.run (Chr(34) & PROG & "\test.cmd" & Chr(34))

Remember that my Program Files folder is on the D:\ drive... not on C:\

Link to comment
Share on other sites

So You Know %systemdrive% can be

Any Drive Where Windows Is Located

So It Does Not Matter, If It C:\ D:\ E:\ F:\ etc

Windows Just see The Varible And applies The

Proper Location.

This Set The Location

SysDr =Action.ExpandEnvironmentStrings("%SystemDrive%")

This Add To The Previous Varible

Sysdr= SysDr & "\Program Files\ZZ YY XX 123"

Edited by gunsmokingman
Link to comment
Share on other sites

Yes but %SystemDrive% will resolve on C:\ and %ProgramFiles% will resolve on D:\

So if I use your code, the result is C:\Program Files\XX YY ZZ ... and that's not correct for me.

C:\Windows

D:\Program Files

E:\Documents and Settings

This is the way our computer are installed...

Link to comment
Share on other sites

For Only D:\

Set Action = CreateObject("wscript.shell")

SysDr =Action.ExpandEnvironmentStrings("%SystemDrive%")

Sysdr= SysDr & "\Program Files\ZZ YY XX 123"

'Action.run (Chr(34) & SysDr & "\Hello It My Cmd Window.cmd" & Chr(34))

Action.run Chr(34) &"D:\Program Files\ZZ YY XX 123\Hello It My Cmd Window.cmd"& Chr(34)

This Will Also Work

Action.run (Chr(34) &"D:\Program Files\ZZ YY XX 123\Hello It My Cmd Window.cmd"& Chr(34))

Edited by gunsmokingman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...