4 Replies - 28504 Views - Last Post: 29 June 2011 - 04:59 PM Rate Topic: -----

#1 eddychamoun  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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)

Any help please,
Thanks

Is This A Good Question/Topic? 0
  • +

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

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,656
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 HighOnTek  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • 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

View Posteddychamoun, 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)

Any help please,
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... :)
Was This Post Helpful? 1
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

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

Posted 28 June 2011 - 01:17 PM

View PostHighOnTek, on 26 June 2011 - 01:40 AM, said:

View Posteddychamoun, 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)

Any help please,
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

Was This Post Helpful? 0
  • +
  • -

#5 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • 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. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1