-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.bat
131 lines (107 loc) · 5.44 KB
/
install.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@echo off
:: Get admin permissions
SET "params=%*"
CD /D "%~dp0"
IF EXIST "%temp%\getadmin.vbs" (
DEL /Q "%temp%\getadmin.vbs"
)
FSUTIL DIRTY QUERY %systemdrive% 1>nul 2>nul || (
ECHO SET UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/K CD ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
EXIT /B
)
:: Paths to the XML files for Task Scheduler
set "batteryTaskXML=BATTERY.XML"
set "batterySleepTaskXML=BATTERY-SLEEP.XML"
:: Check if the XML files exist
if not exist "%batteryTaskXML%" (
echo Error: %batteryTaskXML% not found.
pause
exit /b 1
)
if not exist "%batterySleepTaskXML%" (
echo Error: %batterySleepTaskXML% not found.
pause
exit /b 1
)
:: Update Task Scheduler XML files working directory
"%WINDIR%\SYSTEM32\WindowsPowerShell\v1.0\powershell.exe" -executionpolicy bypass -file "update.ps1"
:: Import the tasks into Task Scheduler
schtasks /create /xml "%batteryTaskXML%" /tn "BATTERY" /f
if %errorlevel% neq 0 (
echo Error: Importing %batteryTaskXML%.
pause
exit /b 1
)
schtasks /create /xml "%batterySleepTaskXML%" /tn "BATTERY-SLEEP" /f
if %errorlevel% neq 0 (
echo Error: Importing %batterySleepTaskXML%.
pause
exit /b 1
)
echo Success: Scheduled Tasks imported.
:: Set up environment variables for paths
set "gpedit=%WINDIR%\System32\gpedit.msc"
set "scripts=%WINDIR%\System32\GroupPolicy\Machine\Scripts\"
set "iniFile=%scripts%scripts.ini"
:: Check if gpedit.msc exists in System32
if not exist "%gpedit%" (
:: Install Group Policy Client Tools package
for /f %%i in ('dir /b %WINDIR%\servicing\packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum') do (
dism /online /norestart /add-package:"%WINDIR%\servicing\packages\%%i"
)
:: Install Group Policy Client Extensions package
for /f %%i in ('dir /b %WINDIR%\servicing\packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum') do (
dism /online /norestart /add-package:"%WINDIR%\servicing\packages\%%i"
)
)
:: Ensure the Scripts folder exists, or create it
if not exist "%scripts%" (
mkdir "%scripts%"
) else if exist "%iniFile%" (
:: If scripts.ini exists, unhide and delete it
attrib -h "%iniFile%"
del /q "%iniFile%"
)
:: Create a new scripts.ini file
(
echo [Shutdown]
echo 0CmdLine=%~dp0battery.bat
echo 0Parameters=kill
) > "%iniFile%"
:: Re-hide the scripts.ini file
attrib +h "%iniFile%"
:: Add registry entries for Group Policy Scripts
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0" /v "GPO-ID" /t REG_SZ /d "LocalGPO" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0" /v "SOM-ID" /t REG_SZ /d "Local" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0" /v "FileSysPath" /t REG_SZ /d "%systemdrive%\\Windows\\System32\\GroupPolicy\\Machine" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0" /v "DisplayName" /t REG_SZ /d "Local Group Policy" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0" /v "GPOName" /t REG_SZ /d "Local Group Policy" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0" /v "Script" /t REG_SZ /d "%~dp0battery.bat" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0" /v "Parameters" /t REG_SZ /d "kill" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0" /v "ExecTime" /t REG_BINARY /d 00000000000000000000000000000000 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0" /v "GPO-ID" /t REG_SZ /d "LocalGPO" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0" /v "SOM-ID" /t REG_SZ /d "Local" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0" /v "FileSysPath" /t REG_SZ /d "%systemdrive%\\Windows\\System32\\GroupPolicy\\Machine" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0" /v "DisplayName" /t REG_SZ /d "Local Group Policy" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0" /v "GPOName" /t REG_SZ /d "Local Group Policy" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0" /v "Script" /t REG_SZ /d "%~dp0battery.bat" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0" /v "Parameters" /t REG_SZ /d "kill" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0" /v "IsPowershell" /t REG_DWORD /d 00000000 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0" /v "ExecTime" /t REG_BINARY /d 00000000000000000000000000000000 /f
:: Force a Group Policy update
gpupdate /force
echo Success: Group Policy Task imported.
echo Installation Complete.
:: Skip reboot
if exist "%gpedit%" (
pause
exit /b 0
)
:: Prompt for reboot
set /p reboot="Would you like to reboot now? (Y/N): "
if /i "%reboot:~0,1%"=="Y" (
echo Rebooting the system...
shutdown /r /t 0
)
exit /b 0