I am trying to write a script to allow the current signed in user temp admin rights for say 10 minutes as follows:-
Can anyone advise where I have gone wrong please?
Got this working now.
Your main issue with the first part is the indention level of your Else and the following sendmessage statement..
"outdent" those two lines and you would probably be fine. The else needs to be at the same indention level as the if that it matches.
In addition to Jonathan's comment (spot on), with your current method, if the user says "No" to your "Logoff Now" question, they simply retain their elevated rights, probably until they do logoff, shutdown or reboot. I dont recall exactly whats behind the elevate rights command set, but most likely it elevates in one command then pauses for 10 mins then executes another cmd to lower them... which will require a new login to enforce.
Also, if you do want to pop a modal dialog box as an else to deliver a "send message", make sure you change the default action from "flash icon" to "display immediately"... as the flashing icon is unlikely to be seen.
Thanks for all the comments.
This is how I did it in the end.
I have set the logoff prompt to display a message rather than flash the K icon.
Any advice to improve on this would be welcome as I am still learning.
You might take the IF isYesFromUser and put it into a procedure that this one calls as its final step... so you can Nag the user. For example, say we name this new IF proc userLogOffNag
IF isYesFromUser THEN (the then is implied, but helps for readability here)
Schedule Procedure [userLogOffNag] in 5 mins
So if they opt not to log off, you nag them for as long as they are elavated.
if the IF isYesFromUser step has a 0 for timeout, then the Procedure will pause until the user sees it and responds. The issue can be, if they don't see it (for long weekend or what ever) or if they drag it off screen and ignore it so it stops popping... then NO Procedures will run on this machine until the prompt is handled. Reason for this is, the prompt pauses the procedure... and all procedures run linerly, in order that they are called. A hung procedure hands all procedures. KLC, KRC and KSM will work, because they are a different service... but procedures will halt in perpetuity till its addressed. .
Many thanks for the suggestion which makes sense.
I will look to incorporate this into the procedure.