Process Launching Bat Not Working

Raven65

Well-known member
Joined
Oct 4, 2006
Messages
305
Programming Experience
3-5
Alright, so this one has me stuck.

My setup is this:

Server/Client service using TCPClient/Listener. Client sends the Listener a path to run. Listener using Process to launch that path locally.

This works fine on one machine. However on another I am having a terrible time. Code to run the process is this:

VB.NET:
Dim p As New Process()
p.StartInfo.FileName = "cmd"
p.StartInfo.Arguments = "/c " & data.Substring(4)
p.StartInfo.UseShellExecute = False
p.StartInfo.UserName = "USERNAME"
Dim password As New System.Security.SecureString
Dim givenPassword As String = "PASSWORD"
For x As Integer = 0 To givenPassword.Length - 1
 password.AppendChar(givenPassword(x))
Next
p.StartInfo.Password = password
p.StartInfo.RedirectStandardError = True
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.Start()
p.WaitForExit()
myWriter.Write("Ec " & p.ExitCode)
myWriter.WriteLine()
myWriter.Write("Er: " & p.StandardError.ReadToEnd)
myWriter.WriteLine()
myWriter.Write("Op: " & p.StandardOutput.ReadToEnd)
myWriter.WriteLine()
If p.ExitCode = 0 Then
 msg = System.Text.Encoding.ASCII.GetBytes("Process Completed.")
 stream.Write(msg, 0, msg.Length)
Else
 msg = System.Text.Encoding.ASCII.GetBytes("Process Failed. Returned: " & p.StandardError.ReadToEnd)
 stream.Write(msg, 0, msg.Length)
End If
p.Dispose()
p = Nothing

So, everything else works. The data is received and reply sent back to the client, but it simply will not run the process. I continue to get a "The system cannot find the drive specified" error.

What Im trying to launch is just a batch file from another server. I've verified the system has access to that folder and I can manually run the bat if I try. Also, the user/pass stuff I added recently to try and get past this problem, the user I am giving also has access to run the bat.

Im really stuck here, Google has been unproductive around this particular situation...I dont understand how the system cannot find the "drive". I've tried UNC and mapped paths, both produce the same results.
 
I have a Client/Listener set up doing the same thing. Instead of passing a path I'm sending the name of a process to the listener and looking up the information from a local XML file.

I'd guess that the environment variable "path" on the listener machine isn't set up correctly.

Try setting p.StartInfo.FileName to "C:\Windows\System32\cmd.exe".
Try setting p.StartInfo.WorkingDirectory to "C:\Windows\System32\"

I'd start out slowly and try and open a process taking no arguments like calc.exe or notepad.exe and slowly add in more complexity until you find your problem.
 
I thought about that initially, but my paths number in the hundreds, and grow every day =\

I'm trying the simple->complex stepping now, but if anyone has further thoughts I'd love to hear them...
 
I thought about that initially, but my paths number in the hundreds, and grow every day =\

I'm trying the simple->complex stepping now, but if anyone has further thoughts I'd love to hear them...

Please let me know where it fails.

If you're able to open calc.exe by providing the full path and not by just providing calc then I'd go into the environment variables for the machine and changing the Path System Variable from %SystemRoot%\System32\ to C:\Windows\System32\ and see if that makes a difference in calling it by exe name (think you need a reboot for the change to take effect.)
 

Latest posts

Back
Top