# How To Send Commands To CMD ( command prompt ) using VB .Net ?

Page 1 of 1

## 4 Replies - 46300 Views - Last Post: 29 June 2011 - 04:59 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=236952&amp;s=ad9dfc934f3fe028c116c7852bbc63c2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 eddychamoun

Reputation: 1
• Posts: 35
• Joined: 22-November 10

# How To Send Commands To CMD ( command prompt ) using VB .Net ?

Posted 24 June 2011 - 11:03 PM

Hello ,
In my application I have only one button . That button will open CMD then it will send a command into cmd , now after that command it requires an "enter key" to continue the process .
I tried the shell command in order to access the command but then I couldn't press enter in cmd using my application .
My code is :

Shell("cmd /c" & "format G:", AppWinStyle.MaximizedFocus)

Thanks

Is This A Good Question/Topic? 0

## Replies To: How To Send Commands To CMD ( command prompt ) using VB .Net ?

• Saucy!

Reputation: 6243
• Posts: 24,013
• Joined: 23-August 08

## Re: How To Send Commands To CMD ( command prompt ) using VB .Net ?

Posted 25 June 2011 - 04:38 AM

Go to http://msdn.microsoft.com and search for System.Diagnostics.Process.

### #3 HighOnTek

Reputation: 2
• Posts: 3
• Joined: 25-June 11

## Re: How To Send Commands To CMD ( command prompt ) using VB .Net ?

Posted 26 June 2011 - 01:40 AM

eddychamoun, on 24 June 2011 - 11:03 PM, said:

Hello ,
In my application I have only one button . That button will open CMD then it will send a command into cmd , now after that command it requires an "enter key" to continue the process .
I tried the shell command in order to access the command but then I couldn't press enter in cmd using my application .
My code is :

Shell("cmd /c" & "format G:", AppWinStyle.MaximizedFocus)

Thanks

You could try using the following;

Shell("cmd /c" & "format G:", AppWinStyle.MaximizedFocus)
SendKeys.Send("{enter}")

And if it doesn't work... then you may have to look @ implementing a timer control as it may be trying to hit/send "Enter" key command before your cmd prompt is expecting it.

If I had VB.net on this PC I'd test it for you.... but I'm pretty sure this will do the trick for ya.

Hope that helps...

### #4 trevster344

• The Peasant

Reputation: 225
• Posts: 1,526
• Joined: 16-March 11

## Re: How To Send Commands To CMD ( command prompt ) using VB .Net ?

Posted 28 June 2011 - 01:17 PM

HighOnTek, on 26 June 2011 - 01:40 AM, said:

eddychamoun, on 24 June 2011 - 11:03 PM, said:

Hello ,
In my application I have only one button . That button will open CMD then it will send a command into cmd , now after that command it requires an "enter key" to continue the process .
I tried the shell command in order to access the command but then I couldn't press enter in cmd using my application .
My code is :

Shell("cmd /c" & "format G:", AppWinStyle.MaximizedFocus)

Thanks

You could try using the following;

Shell("cmd /c" & "format G:", AppWinStyle.MaximizedFocus)
SendKeys.Send("{enter}")

And if it doesn't work... then you may have to look @ implementing a timer control as it may be trying to hit/send "Enter" key command before your cmd prompt is expecting it.

If I had VB.net on this PC I'd test it for you.... but I'm pretty sure this will do the trick for ya.
Hope that helps...

I have a better way unfortunately I am not able to get it for you at this time cause I'm traveling, but in a few hours I should! Hopefully you figure it out before then.

This post has been edited by trevster344: 28 June 2011 - 01:18 PM

### #5 trevster344

• The Peasant

Reputation: 225
• Posts: 1,526
• Joined: 16-March 11

## Re: How To Send Commands To CMD ( command prompt ) using VB .Net ?

Posted 29 June 2011 - 04:59 PM

Alright you might try a "Using" block with the process class.

```Using p as new process
...

```

I only suggest the "Using" block because it will dispose of your process object, but you can also do that yourself.

Under p.StartInfo you'll find the arguments(commands) part, and such. This should do the trick, but if it doesn't let me know, I'll help figure something out. This will also help you:

http://msdn.microsof...cs.process.aspx

I have a great program on my laptop somewhere, I don't have it with me right now, but next week for sure.