header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
typing RETURN in psh script?
Last Post 31 Aug 2010 10:45 AM by carabus. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
carabusUser is Offline
New Member
New Member
Posts:4
Avatar

--
29 Aug 2010 09:17 PM
    New to PSH 2 and feel this must be a fairly simple thing to do... Am using PSH to glue several command-line apps together. I can invoke the first one, but then need to dismiss a series of questions within it so that I can do a run with the default settings. Example: prompt in app says: "Type 'help' to get help>" (I want to enter a blank line to skip this and go on). How to type that ENTER or RETURN? Likewise, next there is a series of yes/no questions. How to type the "yes" reply to each? Many thanks for any help!
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1642
    Avatar

    --
    30 Aug 2010 01:02 AM
    Just enter:
    [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

    See here for all the codes:
    http://technet.microsoft.com/en-us/...31008.aspx

    There are other keystroke automation methods, but they involve loading 3rd party software.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    carabusUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    30 Aug 2010 10:09 PM
    Marco --
    Thanks for your reply. That's what I was looking for -- EXCEPT this particular command-line program seems to block the script completing. Here's what I have:

    -----------------------------
    .\Desktop\tnt\tnt.exe
    [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
    [Microsoft.VisualBasic.Interaction]::AppActivate("Administrator: Windows PowerShell")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
    Start-Sleep -Milliseconds 3000;
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    -----------------------------


    What I get:
    1. TNT opens and waits for "help;" or ENTER to be input.
    2. Only after manually hitting ENTER and quitting TNT does the 3 second sleep and input ENTER happen.

    I'm beginning to think that it's impossible to do this with this program, for some reason. But I'm open to any other suggestions you might have.

    Thanks for your help,
    Brian
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1642
    Avatar

    --
    31 Aug 2010 03:52 AM
    Are you open to trying 3rd party apps? Search for "AutoIT". It is one of the better keystroke automation programs. It provides a COM interface that PowerShell can use.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    carabusUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    31 Aug 2010 07:38 AM
    Yes, I downloaded AutoIT last night, but didn't try it yet because it seemed more involved (believe it compiles to an executable). But, I really need to figure out some way to run this sequence of apps, so sticking one more executable in the mix isn't a big deal, if it does the job. Here's hoping that an executable can circumvent whatever roadblocks TNT throws up blocking other scripts from running. Thanks, Brian
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1642
    Avatar

    --
    31 Aug 2010 09:50 AM
    You *can* compile scripts to an executable and have the engine run them, but you can also interface directly with the engine and send it interactive commands basically.

    I can show you an example in about 10 hours (later tonight) if you want...

    See also this link:
    http://muegge.com/blog/?p=73
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    carabusUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    31 Aug 2010 10:45 AM
    Hi Marco --

    Since my last email, I've been able (with not much fiddling at all) to solve the problem with AutoIt. I can now set the program in motion, do the run (answering all the lead-in questions automatically) and quit the program. Just what I needed! I haven't compiled a script yet, but did discover the ability to run it from the editor, which is very helpful for development.

    Thanks for the offer of help tonight, but I think I'm on my way. I very much appreciate all your help on this!

    Brian
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer