How do I user VB.NET to Open Command Prompt, Call .bat File, and Send Parameters to .bat fil

Greetings,

I am Creating an ASP.NET application that our users may go to to unlock a locked out computer. Once the user supplies the IP Address and UserName they click the unlock button. The button Runs VB.Net code that takes the IP Address and UserName, looks at the first 2 octets of the IP and from that chooses which .bat file to run. All of that works great.

The problem I am having is when I try to open the command prompt to call the .bat file nothing happens. I've searched and found many helpful ways but none seem to support passing the IP and UserName to the .bat file. the .bat file calls a .vbe that logs onto the remote computer as admin and then calls another .bat which calls the unlocking .vbe This is about the only way we have found to remotely unlock users since we do not use AD/LDAP. I'll supply a code snippet to demonstrate how the format works.


Dim IPAsString

Dim personAsString

Dim FirstOctetsAsString

Dim goAs System.Diagnostics.ProcessStartInfo =New System.Diagnostics.ProcessStartInfo("cmd.exe")

go.UseShellExecute =False

go.RedirectStandardInput =True

go.RedirectStandardOutput =True

go.RedirectStandardError =True

go.WorkingDirectory ="c:\\Scripts\\"

IP = IPAddress.Text'Gets I.P. from text box

person = UserName.Text'Gets user name from text box

FirstOctets = Left(IP, 6)'Grabs only the first 6 characters of the I.P. address

If FirstOctets = ("10.20.")Then

MsgBox("Calling Program")

Dim procAs System.Diagnostics.Process = System.Diagnostics.Process.Start(go)

Dim sinAs System.IO.StreamWriter = proc.StandardInput

Dim soutAs System.IO.StreamReader = proc.StandardOutput

sin.WriteLine("go20.bat " & IP & person)


Thanks for any help you may be able to go.

Zach

[4069 byte] By [Wolvenshade] at [2007-12-24]
# 1

System.Diagnostics.Process.Start("filename.bat", "param1 param2")

ThE_lOtUs at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
are you making an ASP.NET app or a Winform app because ASP.NET does not have MsgBox - this applies for Winforms only I believe. You also wont see any outputs on the screen from the output/streamoutput since that will be done "locally" on the box on the ASPNET account unless you have made some way to show it to the user in a live view
ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Thank you so much for your help. Once I put it in and tested it I had to create a new object to house both parameters into one and tried it again and it worked like a charm. Thank you so much.

Zach

Wolvenshade at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

ASP.Net does allow the use of msgbox BUT and its a big BUT, this occurs on the server and not the client and will result in a modal dialog appearing on the server and waiting for manual intervention and therefore is almost certainly not what you require.

spotty at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
thanks for that - much appreciated. I knew it would have something about not being able to show it on the "client" side....obviously to show some message box would require the use of say, javascript or vbscript, but thats something totally different for this any way. Another lecture, another day.
ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
I finally realized that once i put it on the production server for a test. I worked great from my computer. I had totally forgotten that I was trying to run it server side. The deeper and deeper I go in this little project the more I wish we used ADSI/LDAP. But that's not going to happen. Maybe I should Try A new Approach. One where I redisign the whole thing, but that would be getting into some low level code I would know nothing about. Any Suggestions?
Wolvenshade at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

Hello Wolvenshade

There is no secure way to accomplish what you want to do.....but....

Create a Windows service that listens to a given port for Input!

The service uses an agreed upon hash algorithm that can verify the the credentials of the caller on the port

You ASP.Net app can call the service on the given port passing the proper credentials hash.

Your service calls the required Bat.

this is a real simple pseudo design. Fill in the logic, add two eggs, beat until fluffy, bake at 350F for 10 minutes.

Install the service on each machine and have it run under an account with authority to do what you need.

Ibrahim

IbrahimY at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...