Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Process/cmd/sendkeys/System.InvalidOperationException


Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2006, 12:24 PM
Keoki12 Keoki12 is offline
Newcomer
 
Join Date: Jan 2006
Posts: 3
Default 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
Reply With Quote
  #2  
Old 01-25-2006, 01:28 PM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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
Reply With Quote
  #3  
Old 01-26-2006, 09:18 AM
Keoki12 Keoki12 is offline
Newcomer
 
Join Date: Jan 2006
Posts: 3
Default

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.
Reply With Quote
  #4  
Old 01-26-2006, 09:46 AM
Sonreir's Avatar
Sonreir Sonreir is offline
Contributor
 
Join Date: Jul 2004
Location: Hampshire, England
Posts: 540
Default

1.) AFAIK, WaitForInputIdle only works with processes that have a GUI (no DOS windows allowed, sorry!).
Reply With Quote
  #5  
Old 01-26-2006, 10:04 AM
Keoki12 Keoki12 is offline
Newcomer
 
Join Date: Jan 2006
Posts: 3
Default

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?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->