473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4222
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
1864
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
1895
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
2162
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
1605
by: ° ^F®êâK^ ° | 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
6820
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
21963
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
4079
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
2729
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
3684
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
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.