Hello all,
I have the following script that will create a Schduled Task to remove a user from the Administrators group after an amount of time has elapsed. It defaults to 2 hours, but via the command line, I'd like to schedule for any number of hours or days. The problem I have is how do I take a number of hours passed from the command line and convert it to days, or days + hours? Which can then be properly passed to SCHTASKS as /SD (startdate) and /ST (starttime)?
Here is what I have so far:
Any suggestions, or a post you can point me toward?
Thanks,
-Mike
I have the following script that will create a Schduled Task to remove a user from the Administrators group after an amount of time has elapsed. It defaults to 2 hours, but via the command line, I'd like to schedule for any number of hours or days. The problem I have is how do I take a number of hours passed from the command line and convert it to days, or days + hours? Which can then be properly passed to SCHTASKS as /SD (startdate) and /ST (starttime)?
Here is what I have so far:
[ autoit ]
#include <Date.au3> If $CmdLine[0] = 1 Then $objName = $CmdLine[1] $sDateTime = _DateAdd('h', 2, _NowCalc()) ElseIf $CmdLine[0] = 2 Then $objName = $CmdLine[1] If $CmdLine[2] > 0 And $CmdLine[2] < 24 Then $sDateTime = _DateAdd('h', $CmdLine[2], _NowCalc()) ElseIf $CmdLine[2] > 23 Then $sDateTime = _DateAdd('D', 1, _NowCalc()) Else $sDateTime = _DateAdd('h', 2, _NowCalc()) EndIf Else $objName = "domain\username" $sDateTime = _DateAdd('h', 2, _NowCalc()) EndIf If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_7" Or @OSVersion = "WIN_8" Then Run('SCHTASKS /Create /SC ONCE /TN DeleteAdmin /TR "net localgroup administrators /delete "' & $objName & ' /ST ' & $sRunTime & ' /RU SYSTEM /Z /V1', "", @SW_HIDE) ElseIf @OSVersion = "WIN_XP" Then Run('SCHTASKS /Create /SC ONCE /TN DeleteAdmin /TR "net localgroup administrators /delete "' & $objName & ' /ST ' & $sRunTime & ' /RU SYSTEM', "", @SW_HIDE) Else Exit EndIf
Any suggestions, or a post you can point me toward?
Thanks,
-Mike