RJ96
RJ96

Reputation: 313

Is it possible to click a button in an application using Powershell?

i am trying to write a powershell script that checks connectivity thru a continuous ping, if the ping is unsuccessful the script should start a process and when a window is opened have the script click on a specific button, i have done my research and have not found much help other than this

but this is dependant on Actions having schortcuts that's why it doesn't work for me, i would like to know if it's even possible to do this using powershell before i procced with my work. this is my script so far.

$IP = "192.X.X.X"
$TimeOut = 500
$FailureThreshold = 10
$Ping = New-Object System.Net.NetworkInformation.Ping

Do {
$Result = $Ping.Send($IP,$Timeout)
if ($Result.Status -eq "Success") {
    Write-Output "Working as intended."
    Exit 0
}
else {
    Write-Output "Ping Failed!"
    $Failures += 1
}
} until ($Failures -ge $FailureThreshold)
Write-Output "Main DHCP is Down, Starting Backup DHCP Server..."

start-process   "C:\Users\XXXX\Desktop\DHCP\dhcpsrv2.5.2\dhcpsrv.exe"

everything works great, i just need to get that button clicked. and here is a photo of the window that pops up and the button that needs to be clicked. enter image description here

Upvotes: 3

Views: 12284

Answers (2)

A_JE
A_JE

Reputation: 23

Yes it's possible, u can use an app called Auto-it where u Send a mouse click to a specific button in the Window. it's explained here in details on the Autoit website

https://www.autoitscript.com/autoit3/docs/functions/ControlClick.htm

Upvotes: 1

RJ96
RJ96

Reputation: 313

i got it! Maybe this will help someone.

start-process   "C:\Users\XXXX\Desktop\DHCP\dhcpsrv2.5.2\dhcpsrv.exe"
$StartDHCP = New-Object -ComObject wscript.shell;
Sleep 1
$StartDHCP.SendKeys('%C')

where % = ALT

Upvotes: 3

Related Questions