Results 1 to 11 of 11

Thread: [RESOLVED]How to have text automatically filled when the process starts?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Location
    Washington, D.C
    Posts
    26

    Resolved [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?
    Last edited by Battalion; Jun 7th, 2009 at 01:08 PM. Reason: resolved

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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)

  3. #3
    New Member xCalliba's Avatar
    Join Date
    Jun 2009
    Posts
    8

    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..

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How to have text automatically filled when the process starts?

    Quote Originally Posted by xCalliba View Post
    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.

  5. #5
    New Member xCalliba's Avatar
    Join Date
    Jun 2009
    Posts
    8

    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?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Location
    Washington, D.C
    Posts
    26

    Re: How to have text automatically filled when the process starts?

    Quote Originally Posted by keystone_paul View Post
    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.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Location
    Washington, D.C
    Posts
    26

    Re: How to have text automatically filled when the process starts?

    Quote Originally Posted by jmcilhinney View Post
    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

  9. #9
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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".

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Location
    Washington, D.C
    Posts
    26

    Re: How to have text automatically filled when the process starts?

    Quote Originally Posted by keystone_paul View Post
    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

  11. #11
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width