I managed to make a working script to schedule a shutdown however it only executes when AC power is plugged in. I'm trying to make it work even with battery as the source of power. I'm stuck trying to change the settings of the script.
The script works fine on it's own and can execute properly with a power source or power adapter attached. I know that I can change it manually through task scheduler by unticking the box however I'm wondering if there's away to do it as a script for a more automated script.
I don't want to use XML or powershell to resolve the issues.
On Error Resume Next
Dim objSHA ,objFSO ,objWSH ,objInStream ,objOutStream ,RC, settings, taskDefinition
Dim strCurrentPath ,strFwTmpPath ,strText ,intReturnCode
Set objSHA = CreateObject("Shell.Application")
'管理者権限で実行
do while WScript.Arguments.Count = 0 and WScript.Version >= 5.7
objSHA.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ uac", "", "runas"
WScript.Quit
loop
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSH = CreateObject("WScript.Shell")
Set WshShell = wscript.CreateObject("wscript.Shell")
WScript.Sleep 1000
strCurrentPath = Replace(WScript.ScriptFullName ,WScript.ScriptName ,"") 'カレントパス
strFwPrepCmdPath = objFSO.BuildPath(strCurrentPath,"fw_prepcmd.bat") 'FW設定書き換えバッチ用
strFwTmpPath = objFSO.BuildPath(strCurrentPath,"fw_temp.log") '規則名リスト書き出し用
'既にファイルがある場合、削除
if objFSO.FileExists(strFwTmpPath) Then objFSO.DeleteFile strFwTmpPath
if objFSO.FileExists(strFwPrepCmdPath) Then objFSO.DeleteFile strFwPrepCmdPath
WScript.Sleep 1000
objFSO.CreateTextFile strFwPrepCmdPath
Set objOutStream = objFSO.OpenTextFile(strFwPrepCmdPath, 2, True)
objOutStream.WriteLine "schtasks /create /F /tn ""情報システム課定時10分前アラート1820"" /tr ""C:\windows\System32\shutdown.exe -s -f -t 2100 -c '定時10分前になりました。ご都合の良いタイミングで片付けの準備をお願いします。また、電源のつけっぱなしを抑止するため、35分後【18:55】に電源を強制的にオフにします。【保存されていないデータは、失われますのでご注意ください】'"" /sc daily /st 16:32:00 /rl highest >> " & strFwTmpPath
objOutStream.WriteLine "schtasks /create /F /tn ""情報システム課シャットダウンタイマー1855"" /tr ""C:\windows\System32\shutdown.exe -s -f -t 60 -c '電源のつけっぱなしを抑止するため、10分後【18:55】に電源を強制的にオフにします。【保存されていないデータは、失われますのでご注意ください】'"" /sc daily /st 16:33:00 /rl highest >> " & strFwTmpPath
objOutStream.Close
intReturnCode = objWSH.Run(strFwPrepCmdPath, 1, True)
Set taskDefinition = objWSH
Set settings = taskDefinition.Settings
settings.StartWhenAvailable = True
settings.Hidden = False
settings.DisallowStartIfOnBatteries = False
if objFSO.FileExists(strFwPrepCmdPath) Then objFSO.DeleteFile strFwPrepCmdPath
objInStream.Close
objOutStream.Close
Set objInStream = Nothing
Set objOutStream = Nothing
'if objFSO.FileExists(strFwTmpPath) Then objFSO.DeleteFile strFwTmpPath
'objFSO.DeleteFile(Wscript.ScriptFullName)
Set objFSO = Nothing
WScript.Quit(0)