Feedback on a Script

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 2 months, 2 weeks ago.

  • Author
    Posts
  • #67303
    Profile photo of Ian Hicks
    Ian Hicks
    Participant

    I've been working on this script and it works on my PC but I am positive it can be broken if the timing is changed slightly.

    The first problem is I can't figure out how to sendkeys to the program in order to make it start running and simultaneously keep the program from closing via the /w or | out-null commands. When I try to add the out-null lines the script will still close the app before it is done running.

    The 2nd issue is that I have inserted pauses in order to navigate the apps via sendkey commands but obviously this is gonna cause a problem if the app run speed varies even slightly.

    So yeah..... I am sure there are other problems that will arise but these are the two I can see right now. Any advice would be greatly appreciated. Thank you.

    & start "C:\program.lnk"
    sleep 1
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.AppActivate('C:\program.lnk')
    Sleep 1
    $wshell.SendKeys('{right}')
    Sleep 1
    $wshell.SendKeys('~')
    Sleep 1
    $wshell.SendKeys('{right}')
    Sleep 1
    $wshell.SendKeys('~')
    sleep 5
    get-process program | %{ $_.closemainwindow() }
    & start "C:\program.lnk"
    Sleep 3
    $wshell.SendKeys('~')
    sleep 5
    get-process program | %{ $_.closemainwindow() }
    $wshell.SendKeys('{right}')
    Sleep 3
    $wshell.SendKeys('~')
    & start "C:\program.lnk"
    sleep 3
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.AppActivate('C:\program.lnk')
    sleep 1
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('~')
    sleep 1
    $wshell.SendKeys('~')
    sleep 200
    get-process program | %{ $_.closemainwindow() }
    sleep 2
    & start "C:\program.lnk"
    $wshell = New-Object -ComObject wscript.shell;
    sleep 10
    $wshell.SendKeys('~')
    sleep 10
    $wshell.SendKeys('~')

  • #67336
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi, ultimately what are you trying to achieve with this script ? Do you want to stop an application from being closed ?

  • #67389
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    For this case, I would say use the right tool for the Job. While it can be done with PowerShell, this is a better scenario for AutoIT.

    AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

  • #67305
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Hmmm ... I think that's not what Powershell is made for. Either the program you want to control remotely has an API you can use or you should use a better fitting tool to remotely control the GUI interface of a program like AutoIT or AutoHotKey. They are made for that initially.

You must be logged in to reply to this topic.