AboutSyed Rizwan Muhammad Rizvi Expertise I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.
Experience Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.
Question Basically, I'm starting my own cmd prompt through my program. I've modified the input/output, and useshellexecute = false.
When I try to have the line write, it writes, but can't find the process (taskkill.exe /f /im taskname.exe) and errors. My original thought was that it wouldn't be a problem, and I could use a streamreader to import the error message into a textbox control - however, that obviously doesn't work, and through the debugging I've done, I've come to the conclusion that .net treats it as a failed write (it keeps trying to execute the SI.WriteLine("taskkill.exe /f /im wuauclt.exe /t") over and over and over). I've narrowed it down to a NullReferenceException, but can't figure out how to manipulate the control to ignore the error and return the result to the textbox control.
Snippets:
Public startcmd As New Process
Public cmdinfo As New System.Diagnostics.ProcessStartInfo
Static seconds As Integer = 15
If seconds = 0 Then
Dim SO As System.IO.StreamReader = startcmd.StandardOutput
Dim SI As System.IO.StreamWriter = startcmd.StandardInput
Dim error1 As NullReferenceException
SI.WriteLine("taskkill.exe /f /im wuauclt.exe /t")
txtLoadedLog.Text = txtLoadedLog.Text & vbCrLf & SO.ReadToEnd
SI.Close()
SO.Close()
seconds = 15
End If
seconds -= 1
Sorry it's so much code... I've been at it for several hours now and can't (for the life of me) figure this out.
Moreover there is a logical flaw which you will see when you will try to implement wait for exit. because you are using cmd command and not directly using taskkill.exe once the this command terminates it won't close cmd unless you send "exit" command to cmd which will close the application and unblock the call to the process.