/build/static/layout/Breadcrumb_cap_w.png

Kace Script: Complex weekly reboot

Here is what I'd like to script, but haven't seen much similar yet in my googling:

-If no user is logged in - reboot

-If user is logged in - check to see if winword.exe or excel.exe are running

            -If either are running prompt user to save all documents and then reboot

                         -Dialog options: OK (Reboot now), Snooze (but re-prompt after 1 hour)

            -If neither process is running - reboot

 

I see that I can get Kace to check for running processes, and have done this for scripts successfully.  I don't see how I can get user prompts for input within a single Kace script (the OK or Snooze buttons), it seems like only static message boxes are an option.

 

So as a work around I was thinking seperate scripts:

-Script one: Checks for the running processes and if they are running leaves a flag file (C:\promptforreboot.txt or something)

-Script two: Anything with that flag file gets the "Alert User Before Run" dialog, with OK causing a reboot and Snooze snoozing for 1 hour

-Script three: Anything without the processes running, and without a flag file gets rebooted immediately

 

That's all pretty awkward to make work, and I feel like there is room for error.  Any tips?


0 Comments   [ + ] Show comments

Answers (2)

Posted by: dugullett 10 years ago
Red Belt
4

Have you looked at AutoIt? I use this to create exe's that perform certain tasks. 

http://www.autoitscript.com/site/autoit-script-editor/downloads/

Compile the script below into an exe. Then upload the exe as a dependency.

Sample Reboot Script:

$answer = MsgBox(1, "Reboot", "Some Text.....Click OK to reboot now.")

If $answer = 1 Then

Shutdown(6)

EndIf

If $answer = 2 Then

Exit

EndIf

Comments:
  • That tool is pretty awesome, and I've never seen it before. Thanks!

    BUT, I've been trying to avoid making scripts and executables outside of Kace and just having Kace run them because then I lose the granular reporting that Kace offers when each step is outlined separately. If I just tell it to run a .exe it only tells me that it ran or not, and doesn't say if the .exe actually did what it was meant to do.

    I'm finding out that everyone just does that and calls it a day because Kace is finnicky and the documentation is...how to say it politely...skeletal. - mpeters 10 years ago
Posted by: mpeters 10 years ago
Senior White Belt
1

Here is what I decided to do:

  • Script  One: Checks for running processes of winword.exe and excel.exe.  If running: abort. If not running: reboot.  Applied to a label I have for all desktops (NOT all computers).
  1. Launch a Program:
  2. Directory: %WINDIR%\System32
  3. File: cmd.exe
  4. Wait for completion: Yes
  5. Paramters: /C shutdown -r -c "PC will reboot in 1 minute.  Please save all work." -t 90 -d P:1:1
 
  • Smart Label that identifies desktop computers with uptime > 7 Days, and applies "Reboot Required" label
 
  • Script Two: Applies only to "Reboot Required" label.  Runs an exe, code below.  Screenshots are attached.  I built the exe in AutoIT.  Thanks dugullett!

#Region - Check for open winword.exe

If ProcessExists("winword.exe") Then

$answer = MsgBox(0, "Weekly Maintenance", "Word is open.  Please save your documents and close Word.")

ToolTip("Waiting for Word to close.", 0, 513, "Please save your documents.", 5)

ProcessWaitClose("winword.exe")

ToolTip("")

EndIf

#EndRegion

#Region - Check for open excel.exe

If ProcessExists("excel.exe") Then

$answer = MsgBox(0, "Weekly Maintenance", "Excel is open.  Please save your documents and close Excel.")

ToolTip("Waiting for Excel to close.", 0, 513, "Please save your documents.", 5)

ProcessWaitClose("excel.exe")

ToolTip("")

EndIf

#EndRegion

 

#Region - Prompt for reboot

$answer = MsgBox(292, "Weekly Maintenance", "Are you ready to reboot now?" & @CRLF & "- Be sure all of your files are saved." & @CRLF & "- You will be asked hourly until you accept.")

If $answer = 6 Then

Shutdown (18)

EndIf

 

If $answer = 7 Then

Exit

EndIf

#EndRegion

 

Comments:
  • Nice. I know this type of question has been asked before. I know they have a great forum to answer any questions. It's a very useful tool. - dugullett 10 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ