472,986 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

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 4198
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Venkat | last post by:
I just installed Visual Studio.Net 2003 and that is supposed to add that asp.net 1.1 extension. I got an error message while opening ASP.NET project.Error is : "visual studio.net has...
3
by: Glenn | last post by:
We want to deploy a change to a database with minimal effort by the users. I see how to open an Access database from the command line, but can you then issue DDL statements through a command line? ...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
3
by: ^FK^ | last post by:
Blank hi there, I just want to explain my problem. There is an application which is coded by me running. It is an vb.net application having user controls windows forms and something like visual...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
11
by: Gregor Kova | last post by:
Hi! I have an SQL script with bunch of CREATE TABLES, ALTER TABLES, ... I'd like it to run transactially. I have found that id I run a ALTER STATEMENT inside a transaction and then roll it back...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
6
by: tvaughan77 | last post by:
Hi, I have some code that I want to use to run a command line utility and I want to be able to run it from an aspx page running under IIS. The command line utility is a local utility running on...
3
by: WP | last post by:
Hello, I have a very simple script (or would you call it a batch file?) with the following content: connect to mydb2; DROP TABLE staff_employee_address; DROP TABLE...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.