[RESOLVED]How to have text automatically filled when the process starts?
If I make a button that starts command prompt:
Code:
Process.Start "cmd.exe"
I want text to be entered as soon as it starts. Like "ipconfig" is typed in by the pc, and hit "enter" automatically. Little Help?
Re: How to have text automatically filled when the process starts?
I don't know if there's any better way of doing it (as cmd.exe doesn't take command line arguments), but you can use sendkeys to achieve the desired effect :
Code:
Process.Start("cmd.exe")
My.Computer.Keyboard.SendKeys("ipconfig" & vbCrLf)
Re: How to have text automatically filled when the process starts?
lol i was just trying that... didnt work on mine though. works for notepad though..
Re: How to have text automatically filled when the process starts?
Quote:
Originally Posted by
xCalliba
you could probably do this by utilising the my.computer.keyboard.sendkeys event. . .
Wish I'd thought of that:)
EDIT - ah I see the hasty edit, however I've tested the exact code above on my vista machine and it works fine - can't see why it would work on notepad but not on command prompt.
Re: How to have text automatically filled when the process starts?
hmm, im usin windows 7. either it dont like that, or my machine lol
Battalion, have you considered making a script to do it for you?
Re: How to have text automatically filled when the process starts?
There is a submission in the VB.NET CodeBank forum from gigemboy that deals with this topic specifically.
Re: How to have text automatically filled when the process starts?
Quote:
Originally Posted by
keystone_paul
I don't know if there's any better way of doing it (as cmd.exe doesn't take command line arguments), but you can use sendkeys to achieve the desired effect :
Code:
Process.Start("cmd.exe")
My.Computer.Keyboard.SendKeys("ipconfig" & vbCrLf)
Ok I will try this.
Re: How to have text automatically filled when the process starts?
Quote:
Originally Posted by
jmcilhinney
There is a submission in the VB.NET CodeBank forum from gigemboy that deals with this topic specifically.
Right. I searched the database, and tracked down user "gigemboy's" posts. I found a "Automate Command Prompt" Article that deals with this, here it is:
http://www.vbforums.com/showthread.php?t=381405
Re: How to have text automatically filled when the process starts?
Yep - I've just been looking at that myself.
Thats definitely a "better way of doing it".
Re: How to have text automatically filled when the process starts?
Quote:
Originally Posted by
keystone_paul
I don't know if there's any better way of doing it (as cmd.exe doesn't take command line arguments), but you can use sendkeys to achieve the desired effect :
Code:
Process.Start("cmd.exe")
My.Computer.Keyboard.SendKeys("ipconfig" & vbCrLf)
Bingo! This code works. A new rep for paul :)
Re: [RESOLVED]How to have text automatically filled when the process starts?
Thanks, however you should note that gigemboy's way of doing it is more robust... under some circumstances it is possible that the SendKeys approach may fail (if another window steals the focus between the command window opening and the send keys executing - its unlikely but there is a chance).
Also if Windows 7 prevents command prompt windows receiving send keys messages, it may not be viable on that platform, however gigemboy's should.