468,753 Members | 1,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,753 developers. It's quick & easy.

Running Command Line statements

I am looking for a way to run DOS-type commands from within a VB.net 2003
application.

I also need to be able to answer questions (ie 'Are You Sure') that the
command line may require.

Thanks,

Atley
Nov 20 '05 #1
9 4039
Hi,

Dim arArgs() As String = Environment.GetCommandLineArgs

http://msdn.microsoft.com/library/de...eargstopic.asp

Ken

--------------------

"Atley" <at*****@hotmail.com> wrote in message
news:eJ**************@tk2msftngp13.phx.gbl...
I am looking for a way to run DOS-type commands from within a VB.net 2003
application.

I also need to be able to answer questions (ie 'Are You Sure') that the
command line may require.

Thanks,

Atley

Nov 20 '05 #2
I don't see how that allows me to execute a DOS command, I tried a simple
one like 'dir c:\windows'
and it put it in the console window, but I did not see it execute.

What am I doing wrong?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Hi,

Dim arArgs() As String = Environment.GetCommandLineArgs

http://msdn.microsoft.com/library/de...eargstopic.asp
Ken

--------------------

Nov 20 '05 #3
On Mon, 9 Feb 2004 14:51:07 -0500, Atley wrote:
I don't see how that allows me to execute a DOS command, I tried a simple
one like 'dir c:\windows'
and it put it in the console window, but I did not see it execute.

What am I doing wrong?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Hi,

Dim arArgs() As String = Environment.GetCommandLineArgs

http://msdn.microsoft.com/library/de...eargstopic.asp

Ken

--------------------


Look at the System.diagnostics.Process class. You can call the
Process.Start method to start a DOS command. You can optionally, redirect
the output of the DOS command. When you receive a certain output such as
"Are You Sure?" You can send the appropriate response. Search Google for
examples on redirecting input and you should find a link with an example.

Just FYI (and I'm sure you already know this) most DOS commands that ask
"Are You Sure?" also provide a switch /y for answering yes.

Regards,
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #4
I have been trying to use the Shell method, but I can't seem to make the
command window activate the way you can with calc or word or notepad... It
is making it impossible to use the SendKeys function, which would be
ideal... I will take a look at the suggestion you gave me, but the Shell
looks like it would be the way to go, if I could just get the focus to the
window without errors.

The code is simple and works for everything except a DOS command window.

Dim myLng As Integer = Shell("NET SHARE tshare /DELETE",
AppWinStyle.NormalFocus)
AppActivate(myLng)
SendKeys.SendWait("y")
SendKeys.SendWait("{Enter}")

That should work and does if you substitute notepad, word, etc instead of
any DOS command, for some reason Windows cannot find the Command Window to
set focus.

I am using NET SHARE to unshare a directory on a server so that some file
maintence can be done at night, even though some users still leave their
computers attached to the share. I cannot find a /y to answer affermative
and ECHO y| doesn't work for it either, or I would be using a simple batch
file to do this.


"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1k*****************************@40tude.net...
On Mon, 9 Feb 2004 14:51:07 -0500, Atley wrote:
I don't see how that allows me to execute a DOS command, I tried a simple
one like 'dir c:\windows'
and it put it in the console window, but I did not see it execute.

What am I doing wrong?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Hi,

Dim arArgs() As String = Environment.GetCommandLineArgs

http://msdn.microsoft.com/library/de...eargstopic.asp

Ken

--------------------


Look at the System.diagnostics.Process class. You can call the
Process.Start method to start a DOS command. You can optionally, redirect
the output of the DOS command. When you receive a certain output such as
"Are You Sure?" You can send the appropriate response. Search Google for
examples on redirecting input and you should find a link with an example.

Just FYI (and I'm sure you already know this) most DOS commands that ask
"Are You Sure?" also provide a switch /y for answering yes.

Regards,
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #5
On Tue, 10 Feb 2004 08:47:40 -0500, Atley wrote:
I have been trying to use the Shell method, but I can't seem to make the
command window activate the way you can with calc or word or notepad... It


I'm not sure that cmd.exe has a window you can find. You may have noticed
that the cmd.exe window (when run on XP) does not have the XP look and
feel. I think that is because it is not a standard window, but I could be
wrong.

Check this link:

http://www.mvps.org/dotnet/dotnet/sa...ectConsole.zip

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #6
* Chris Dunaway <dunawayc@_lunchmeat_sbcglobal.net> scripsit:
I have been trying to use the Shell method, but I can't seem to make the
command window activate the way you can with calc or word or notepad... It
I'm not sure that cmd.exe has a window you can find. You may have noticed
that the cmd.exe window (when run on XP) does not have the XP look and
feel. I think that is because it is not a standard window, but I could be
wrong.


It will have a window, but I am not sure if the according 'Process'
object has a 'MainWindowHandle' (I seriously doubt it has). Maybe
playing around with Spy++ (which comes with VS.NET) helps.
http://www.mvps.org/dotnet/dotnet/sa...ectConsole.zip


:-)

This will redirect the console output into a Windows Forms application.
I am not sure if that's what the OP wants to do.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
On 11 Feb 2004 20:10:25 +0100, Herfried K. Wagner [MVP] wrote:

This will redirect the console output into a Windows Forms application.
I am not sure if that's what the OP wants to do.


The OP said he wants to "run DOS-type commands from within a VB.net 2003
application." and "answer questions (ie 'Are You Sure') that the
command line may require."

If he redirects the DOS programs output to a stream, shouldn't he be able
to scan the stream for the prompt (i.e. 'Are You Sure?') and send an
appropriate answer back to the DOS programs standard input? I'll have to
try that myself and see if it can be done.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #8
Chris,

* Chris Dunaway <dunawayc@_lunchmeat_sbcglobal.net> scripsit:
This will redirect the console output into a Windows Forms application.
I am not sure if that's what the OP wants to do.


The OP said he wants to "run DOS-type commands from within a VB.net 2003
application." and "answer questions (ie 'Are You Sure') that the
command line may require."

If he redirects the DOS programs output to a stream, shouldn't he be able
to scan the stream for the prompt (i.e. 'Are You Sure?') and send an
appropriate answer back to the DOS programs standard input? I'll have to
try that myself and see if it can be done.


Maybe it will work. If would be great if you post your experiences
here.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
Answer:
Set commands in a batch file, this will give the window a title you can rely
on and send responses too... At least it is working for me.

Thanks for all of your help.
Atley

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Chris,

* Chris Dunaway <dunawayc@_lunchmeat_sbcglobal.net> scripsit:
This will redirect the console output into a Windows Forms application.
I am not sure if that's what the OP wants to do.


The OP said he wants to "run DOS-type commands from within a VB.net 2003
application." and "answer questions (ie 'Are You Sure') that the
command line may require."

If he redirects the DOS programs output to a stream, shouldn't he be able to scan the stream for the prompt (i.e. 'Are You Sure?') and send an
appropriate answer back to the DOS programs standard input? I'll have to try that myself and see if it can be done.


Maybe it will work. If would be great if you post your experiences
here.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by Roman Mashak | last post: by
11 posts views Thread by Gregor Kova | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.