 |
 |

01-25-2006, 12:24 PM
|
|
Newcomer
|
|
Join Date: Jan 2006
Posts: 3
|
|
Process/cmd/sendkeys/System.InvalidOperationException
|
I have a couple of separate problems going on here. I am attempting to open a DOS window, keep it open and visible from vb.net and send in multiple commands. Over the last 2 1/2 days I have tried multiple methods with various problems.
This is my most recent attempt:
Code:
Imports System
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.IO
Imports System.Security
Imports System.Collections
Imports System.Exception
Public Class frmCom_Utilities
Inherits System.Windows.Forms.Form
Private mProcess As Process
Private Sub frmCom_Utilities_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RunCmd As Process = New Process
'Dim RunCmd As New Process
RunCmd.StartInfo.FileName = "cmd.exe"
RunCmd.StartInfo.WindowStyle = ProcessWindowStyle.Normal
RunCmd.EnableRaisingEvents = True
AddHandler RunCmd.Exited, AddressOf Me.SendKeysTestExited
Timer1.Enabled = True
Timer1.Interval = 3000
Timer1.Start()
Me.LaunchedProcess = RunCmd
RunCmd.Start()
RunCmd.WaitForInputIdle(1000)
If RunCmd.Responding Then
System.Windows.Forms.SendKeys.Send("C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\SDKVARS.BAT")
System.Windows.Forms.SendKeys.SendWait("{ENTER}")
Else
RunCmd.Kill()
End If
End Sub
Friend Sub SendKeysTestExited(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myProcess As Process = DirectCast(sender, Process)
Timer1.Stop()
If Not myProcess Is Nothing Then
MessageBox.Show("Cmd was closed, raising the Exited event at: " & myProcess.ExitTime & "." & _
System.Environment.NewLine & "Exit Code: " & myProcess.ExitCode)
End If
myProcess.Close()
End Sub
Private Property LaunchedProcess() As Process
Get
Return mProcess
End Get
Set(ByVal Value As Process)
mProcess = Value
End Set
End Property
end class
Problem 1: When the process hits the line RunCmd.WaitForInputIdle(1000)
I get a "System.InvalidOperationException".
Problem 2: When the sendkeys line hits, the command fails because the DOS window states: "'C:\Program ' is not recognized as an internal or external command, operable program, or batch file."
My objective is to have the command window open, stay open, perform several commands and when I am ready, to have it close. Everything I have tried has failed in one or more of these areas. Help is greatly appreciated. Please be explicit because sometimes I can be a real dunce!
Thanks,
Keoki12
|
Last edited by wayneph; 01-25-2006 at 01:26 PM.
Reason: please use [vb] tags for posting code and added line breaks
|

01-25-2006, 01:28 PM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
don't have time right now to look at problem 1.
problem 2, send quotes as well. (See Red Quotes)
Code:
System.Windows.Forms.SendKeys.Send("[COLOR=Red]""[/COLOR]C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\SDKVARS.BAT[COLOR=Red]""[/COLOR]")
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

01-26-2006, 09:18 AM
|
|
Newcomer
|
|
Join Date: Jan 2006
Posts: 3
|
|
|
Wayne,
Sending the extra quotes was the first thing I tried because it is something I have used in VB 6 on a regular basis. To my astonishment, I kept getting error messages from VB.Net. It wouldn't compile. I even spent quite a bit of time trying to figure out the QuoteSnippetString to see if it was something I could use.
Now to my embarrassment, I opened up the app, entered the extra quotes, and it worked like a charm. I am baffled by the problem I was having, but more than anything, I am so glad that worked today and I can knock it off my problem list.
Thanks for stating the obvious.
|
|

01-26-2006, 09:46 AM
|
 |
Contributor
|
|
Join Date: Jul 2004
Location: Hampshire, England
Posts: 540
|
|
|
1.) AFAIK, WaitForInputIdle only works with processes that have a GUI (no DOS windows allowed, sorry!).
|
|

01-26-2006, 10:04 AM
|
|
Newcomer
|
|
Join Date: Jan 2006
Posts: 3
|
|
|
Sonreir. Thank you so much. I had not read that in all the stuff I have gone through. Do you have any suggestions of where I might look to get more information on that besides Microsoft?
I was getting the same error message when I tried to use WaitForExit which I found in a couple of samples using the cmd window that I found on line. Any idea why it would throw out the same exception error?
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|