Feedback on a Script

Welcome Forums General PowerShell Q&A Feedback on a Script

Viewing 3 reply threads
  • Author
    Posts
    • #67303
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      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
      Participant
      Topics: 0
      Replies: 16
      Points: 1
      Rank: Member

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

    • #67389
      Participant
      Topics: 6
      Replies: 658
      Points: 47
      Rank: Member

      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
      Participant
      Topics: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

      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.

Viewing 3 reply threads
  • The topic ‘Feedback on a Script’ is closed to new replies.