1

My problem is that I need to send a shutdown command to my NAS when the UPS tells my home server that there's a power cut. I want to do this by using the (Windows 10 Home) PC server's closedown notification, which can trigger a batch file as part of the closedown event, rather than by using extra hardware. I have determined that opening a particular URL will cause the NAS to close down gracefully.

https://192.168.1.10/get_handler?PAGE=System&OUTER_TAB=tab_shutdown&INNER_TAB=NONE&shutdown_option1=1&command=poweroff&OPERATION=set

The problems seem to be related to trying to bypass dialogues that result in the browser. First it asks for credentials. I can bypass this one by including them in the URL call, like this:

start "" "C:\Program Files\Mozilla Firefox\firefox.exe" "https://username:password@192.168.1.10/get_handler?PAGE=System&OUTER_TAB=tab_shutdown&INNER_TAB=NONE&shutdown_option1=1&command=poweroff&OPERATION=set"

Now it pops up a dialogue asking me to confirm that I want to log on as "username", again defeating my attempt to make this run unattended (I might be anywhere when a power cut strikes). Is there a way around this? Just FYI, I gave up trying to work with Microsoft Edge as it kept cutting the URL paramaeters into pieces by inserting spaces everywhere. It also kept manually complaining about the security certificate each and every time I tried it. I think I'll have the same confirmation request problems with that browser too. So I need a way to surpress all these dialogues and just make the URL call. Any thoughts please?

Frankie
  • 596
  • 3
  • 24

1 Answers1

0

The lack of any answers after this question had been posted over 24 hours told me that this was a tricky one & kept me trying. After I tried everything I could think of to solve it with Window's own tool set and finding nothing worked I realised I'd need something additional to solve the problem. Finally I gave up and installed the free Autohotkey and wrote a script to do the entire job, including handling the dialogue boxes. Once it was all working I made an executable from the script for convenience so I can easily call it from the close down batch (.bat) file. This solution works. Here is the script for anyone who needs to solve a similar problem:

> runWait, C:\Program Files\Mozilla Firefox\firefox.exe
> https://admin:password@192.168.1.10/get_handler?PAGE=System&OUTER_TAB=tab_shutdown&INNER_TAB=NONE&shutdown_option1=1&command=poweroff&OPERATION=set
> 
> #Persistent SetTimer, MsgBoxCheck, 3000 return
> 
> MsgBoxCheck: If WinExist("ahk_class MozillaDialogClass") {   
> SetControlDelay -1    ControlClick, , Confirm,    SetTimer,
> MsgBoxCheck, off    exitApp } else {    SetTimer, MsgBoxCheck, off   
> MsgBox, 4, , Debug - No Confirm Window Found.    exitApp } return

Please note, to make this work with non-Mozilla programs you will need to change the ahk_class parameter. I suggest you use Windows Spy to determine the class of window you want to close. You will also need to change 'Confirm' to whatever your window's title might be.

Frankie
  • 596
  • 3
  • 24
  • I watched your post for an answer as well. Was able to get it done with a few lines of powershell code that I executed from my bat file. LMK if you want that. – RGuggisberg Jun 15 '17 at 21:06
  • Thank you Guggisberg, but the Autohotkey solution works fine, and it doesn't require me to learn 'powershell' - yet another technology I am unfamilair with - but thanks for the offer! – Frankie Jun 23 '17 at 23:31