Sign in to follow this  
Followers 0
emmanuel

Prompt To Reboot After A Critical Patch.

14 posts in this topic

#1 ·  Posted (edited)

I know it's simple, but maybe someone else won't have to reinvent the 'wheel' if they see this first:

edited above again, added that extra case to set to defaults...

AutoItSetOption("TrayIconHide", 1)
Break(0)
HotKeySet("^q", "bye")

$HLPMSGTXT = 'designed by Emmanuel Pleshe <emmanuel.pleshe@pse.com> to prompt users to close all apps after crit patch and before reboot.' & @CRLF & '/? or /h summons this dialog' & @CRLF & '      /custtext "window title" "window text" adds custom window title and text' & @CRLF & 'putting * in place of either the text or the title will use the default text or title' & @CRLF & '      /custtext * "title is default, text is custom"' & @CRLF & 'press ctrl-q to escape without rebooting, just wait for the msgbox to timeout'
;don't think this part will work:
; & @CRLF & 'use @CRLF for next line, only in window text'

;default window title and text
$DEFAULTTITLE = 'PSE IT Critical Patch'
$DEFAULTTEXT = 'A critical patch has been applied to your computer and you must reboot.' & @CRLF & 'Save all work that needs to be saved and close all applications then click OK' & @CRLF & 'Clicking OK will reboot your computer'

Select
   Case ($CMDLINE[0] > 0) and ( ($CMDLINE[0] <> 1 And $CMDLINE[0] <> 3) Or ($CMDLINE[0] = 1 And ($CMDLINE[1] = '/h' Or $CMDLINE[1] = '/?' Or $CMDLINE[1] = '/custtext')))
      MsgBox(0, "crit patch reboot", $HLPMSGTXT)
      Exit
   Case $CMDLINE[0] = 3 And $CMDLINE[1] = '/custtext'  
      If $CMDLINE[2] = '*' Then;this way, if they put * for the title the default is used.
         $TITLE = $DEFAULTTITLE
      Else
         $TITLE = $CMDLINE[2]
      EndIf
      If $CMDLINE[3] = '*' Then;this way, if they put * for the text the default is used.
         $TEXT = $DEFAULTTEXT
      Else
         $TEXT = $CMDLINE[3]
      EndIf
   Case $CMDLINE[0] = 0
      $TEXT = $DEFAULTTEXT
      $TITLE = $DEFAULTTITLE
EndSelect

$CLICK = 0

Do
   $CLICK = MsgBox(4144, $TITLE, $TEXT & @CRLF & 'This message box will repeat every thirty seconds until you reboot.', 30)
Until $CLICK = 1

Shutdown(6)

Func bye()
   Exit 0
EndFunc  ;==>bye

Here's the story, the Server folks were ready to launch a auto-rebooting patch in the logon script, I said "that could screw up the users" and then "how about if I just write a exe to popup a message that your batch file can call?" I did this in under an hour, so if you see any improvements that would make it extra groovy, let me know.

Thanks,

Emmanuel

edited, streamlined the script a bit

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites



I've made some more changes above, one question, how should I combine these into one line?

Case $cmdline[0] = 1 And ($cmdline[1] = '/h' Or $cmdline[1] = '/?' Or $cmdline[1] = '/custtext')
      MsgBox(0, "crit patch reboot", $hlpmsgtxt) 
      Exit
   Case $cmdline[0] <> (1 or 3)
      MsgBox(0, "crit patch reboot", $hlpmsgtxt) 
      Exit

since they both do the same thing, I'd like to have it in one line :D but my brain isn't quite there.


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

I got it:

Case ($cmdline[0] <>  (1 Or 3)) Or ($cmdline[0] = 1 And ($cmdline[1] = '/h' Or $cmdline[1] = '/?' Or $cmdline[1] = '/custtext'))
      MsgBox(0, "crit patch reboot", $hlpmsgtxt)
      Exit


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

I got it:

Case ($cmdline[0] <>  (1 Or 3)) Or ($cmdline[0] = 1 And ($cmdline[1] = '/h' Or $cmdline[1] = '/?' Or $cmdline[1] = '/custtext'))
      MsgBox(0, "crit patch reboot", $hlpmsgtxt)
      Exit
don't think this bit will work: $cmdline[0] <> (1 Or 3)

you need to write: ($cmdline[0] <> 1 AND $cmdline[0] <> 3)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

damn, you're right. now it pops the help message no matter what's in the cmdline... however, it needs to be able to run without any command line options, so it should run as defaults if cmdline[0] = 0

edit: used your fix, it I put critpatch-reboot.exe /custtext * * it runs with the default text, anything else, including not having the /custtext pops the help message....

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

got this error

---------------------------

AutoIt Error

---------------------------

Line 0:

$CLICK = MsgBox(4144, $TITLE, $TEXT & @CRLF & 'This message box will repeat every thirty seconds until you reboot.', 30)

$CLICK = MsgBox(4144, ^ ERROR

Error: Variable used without being declared.

---------------------------

OK

---------------------------

when I ran this modified code:

AutoItSetOption("TrayIconHide", 1)
Break(0)
HotKeySet("^q", "bye")

$HLPMSGTXT = 'designed by Emmanuel Pleshe <emmanuel.pleshe@pse.com> to prompt users to close all apps after crit patch and before reboot.' & @CRLF & '/? or /h summons this dialog' & @CRLF & '      /custtext "window title" "window text" adds custom window title and text' & @CRLF & 'putting * in place of either the text or the title will use the default text or title' & @CRLF & '      /custtext * "title is default, text is custom"' & @CRLF & 'press ctrl-q to escape without rebooting, just wait for the msgbox to timeout'
;don't think this part will work:
; & @CRLF & 'use @CRLF for next line, only in window text'

;default window title and text
$DEFAULTTITLE = 'PSE IT Critical Patch'
$DEFAULTTEXT = 'A critical patch has been applied to your computer and you must reboot.' & @CRLF & 'Save all work that needs to be saved and close all applications then click OK' & @CRLF & 'Clicking OK will reboot your computer'

Select
   Case $cmdline[0] > 0 AND (($cmdline[0] <> 1 AND $cmdline[0] <> 3) Or ($CMDLINE[0] = 1 And ($CMDLINE[1] = '/h' Or $CMDLINE[1] = '/?' Or $CMDLINE[1] = '/custtext')))
      MsgBox(0, "crit patch reboot", $HLPMSGTXT)
      Exit
   Case $CMDLINE[0] = 3 And $CMDLINE[1] = '/custtext'  
      If $CMDLINE[2] = '*' Then;this way, if they put * for the title the default is used.
         $TITLE = $DEFAULTTITLE
      Else
         $TITLE = $CMDLINE[2]
      EndIf
      If $CMDLINE[3] = '*' Then;this way, if they put * for the text the default is used.
         $TEXT = $DEFAULTTEXT
      Else
         $TEXT = $CMDLINE[3]
      EndIf
EndSelect

$CLICK = 0

Do
   $CLICK = MsgBox(4144, $TITLE, $TEXT & @CRLF & 'This message box will repeat every thirty seconds until you reboot.', 30)
Until $CLICK = 1

;Shutdown(6)

Func bye()
   Exit 0
EndFunc  ;==>bye

I changed this line:

Case $cmdline[0] <> 1 AND $cmdline[0] <> 3) Or ($CMDLINE[0] = 1 And ($CMDLINE[1] = '/h' Or $CMDLINE[1] = '/?' Or $CMDLINE[1] = '/custtext'))

to this:

$cmdline[0] > 0 AND (($cmdline[0] <> 1 AND $cmdline[0] <> 3) Or ($CMDLINE[0] = 1 And ($CMDLINE[1] = '/h' Or $CMDLINE[1] = '/?' Or $CMDLINE[1] = '/custtext')))

I rem'd the shutdown for testing purposes, if you want to try it yourselves...


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

if you don't specify any parameter then $Title and $text aren't set so you get this error..

EDIT: Why don't you do it this way?

AutoItSetOption("TrayIconHide", 1)
Break(0)
HotKeySet("^q", "bye")
Global
$HLPMSGTXT = 'designed by Emmanuel Pleshe <emmanuel.pleshe@pse.com> to prompt users to close all apps after crit patch and before reboot.' & @CRLF & '/? or /h summons this dialog' & @CRLF & '      /custtext "window title" "window text" adds custom window title and text' & @CRLF & 'putting * in place of either the text or the title will use the default text or title' & @CRLF & '      /custtext * "title is default, text is custom"' & @CRLF & 'press ctrl-q to escape without rebooting, just wait for the msgbox to timeout'
;don't think this part will work:
; & @CRLF & 'use @CRLF for next line, only in window text'

;default window title and text
$TITLE = 'PSE IT Critical Patch'
$TEXT = 'A critical patch has been applied to your computer and you must reboot.' & @CRLF & 'Save all work that needs to be saved and close all applications then click OK' & @CRLF & 'Clicking OK will reboot your computer'

Select
  Case $cmdline[0] > 0 AND (($cmdline[0] <> 1 AND $cmdline[0] <> 3) Or ($CMDLINE[0] = 1 And ($CMDLINE[1] = '/h' Or $CMDLINE[1] = '/?' Or $CMDLINE[1] = '/custtext')))
     MsgBox(0, "crit patch reboot", $HLPMSGTXT)
     Exit
  Case $CMDLINE[0] = 3 And $CMDLINE[1] = '/custtext'  
     If $CMDLINE[2] <> '*' Then;this way, if they put * for the title the default is used.
        $TITLE = $CMDLINE[2]
     EndIf
     If $CMDLINE[3] <> '*' Then;this way, if they put * for the text the default is used.
        $TEXT = $CMDLINE[3]
     EndIf
EndSelect

$CLICK = 0

Do
  $CLICK = MsgBox(4144, $TITLE, $TEXT & @CRLF & 'This message box will repeat every thirty seconds until you reboot.', 30)
Until $CLICK = 1

;Shutdown(6)

Func bye()
  Exit 0
EndFunc;==>bye
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

gah. I've been too witty for my own good. putting this down for a minute to do some "real work"

so another case, cmdline[0] = 0

$text = $defaulttext

... etcetera. ok

thanks. really. brain, melting, need food.


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

edited above again, added that extra case to set to defaults...

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#10 ·  Posted

just wanted to thank JdeB for the contructive criticism and invite anyone else to point out flaws... I'd like to think that the more of this I do, even on small scripts, the better I'll get at making complete product, and therefor the better I'll be able to please my scripting audience (mostly me so far :D )


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

thank you, so, what do you think is better, how it is above, or how it is here?

$DEFAULTTITLE = 'PSE IT Critical Patch'
$DEFAULTTEXT = 'A critical patch has been applied to your computer and you must reboot.' & @CRLF & 'Save all work that needs to be saved and close all applications then click OK' & @CRLF & 'Clicking OK will reboot your computer'
$TEXT = $DEFAULTTEXT
$TITLE = $DEFAULTTITLE
Select
   Case ($CMDLINE[0] > 0) and ( ($CMDLINE[0] <> 1 And $CMDLINE[0] <> 3) Or ($CMDLINE[0] = 1 And ($CMDLINE[1] = '/h' Or $CMDLINE[1] = '/?' Or $CMDLINE[1] = '/custtext')))
      MsgBox(0, "crit patch reboot", $HLPMSGTXT)
      Exit
   Case $CMDLINE[0] = 3 And $CMDLINE[1] = '/custtext'  
      If $CMDLINE[2] = '*' Then;this way, if they put * for the title the default is used.
         $TITLE = $DEFAULTTITLE
      Else
         $TITLE = $CMDLINE[2]
      EndIf
      If $CMDLINE[3] = '*' Then;this way, if they put * for the text the default is used.
         $TEXT = $DEFAULTTEXT
      Else
         $TEXT = $CMDLINE[3]
      EndIf
;   Case $CMDLINE[0] = 0
;      $TEXT = $DEFAULTTEXT
;      $TITLE = $DEFAULTTITLE
EndSelect

(the diff being setting the defaults in the case, only if needed, or ahead of time, to be replaced only if needed)

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#14 ·  Posted

I generally set defaults and then replace only those neccessary.

that's what I was leaning towards as well...

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0