forked from leitbogioro/Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GroupPolicy_import_export_en.bat
133 lines (120 loc) · 3.73 KB
/
GroupPolicy_import_export_en.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
132
133
@echo off
color DE
echo Check whether run as Administrator...
net session >nul 2>&1
if %errorLevel% == 0 (
goto continue
) else (
echo,
echo Please run as Administrator!
echo Press any key to exit...
pause > nul
exit
)
:continue
SetLocal EnableDelayedExpansion
for /f "tokens=1* delims=[" %%a in ('ver') do (
set b=%%b
)
set b=%b:* =%
for /f "tokens=1,3 delims=*." %%a in ("%b%") do (
set ver1=!ver1!_%%a
set ver3=!ver3!_%%b
)
for /f "tokens=2 delims=*." %%a in ("%b%") do (
set ver2=!ver2!_%%a
)
set version=!ver1!!ver2!!ver3!
set db_name=%set
set gp_name="%UserProfile%\Desktop\gp_config%version%\%db_name%.inf"
set gp_folder="%UserProfile%\Desktop\gp_config%version%\"
set gp_file="%Windir%\System32\GroupPolicy"
set gp_export_file="%UserProfile%\Desktop\GroupPolicy"
set logs="%WinDir%\security\logs\scesetup.log"
echo,
echo ∧____∧
echo (·ω·)つ━ ☆..*¨
echo ∈ ノ
echo * * * Welcome to GroupPolicy management by MollyLau * * *
echo * しーーJ *
echo * *
echo * *
echo * 1. Export GroupPolicy *
echo * *
echo * 2. Import GroupPolicy *
echo * *
echo * Press any key to exit *
echo * *
echo * *
echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo,
set /p ask1=Choose an operation(1/2/any key):
if "%ask1%"=="1" (
goto export_gp
) else (
if "%ask1%"=="2" (
goto import_gp
) else (
exit
)
)
:export_gp
if exist %gp_folder% (
rd /s /Q %gp_folder%
)
mkdir %gp_folder%
echo,
echo Exporting security settings about first part...
secedit /export /cfg %gp_name%
echo,
echo Exporting all configurations about group policies...
xcopy /e /h /r /y %gp_file% %gp_export_file%\
echo,
echo Archiving files...
attrib -h %gp_export_file%
move %gp_export_file% %gp_folder%
echo,
echo Group policies has been exported to %gp_folder% successfully!
echo,
echo Cleaning up...
if exist logs del %logs%
echo,
set /p ask2=Need to browse back-uped files(y browse/n exit)?
if /i "%ask2%"=="n" exit
if /i "%ask2%"=="y" explorer %gp_folder%
exit
:import_gp
echo,
if exist %gp_folder% (
if exist %gp_name% (
if exist %gp_folder%GroupPolicy (
echo Importing security settings about first part...
secedit /configure /db %db_name%.sdb /CFG %gp_name%
echo,
echo Importing all configurations about group policies...
xcopy /e /h /r /y %gp_folder%GroupPolicy %gp_file%
echo,
echo Refresh group policy services...
gpupdate /force
echo Group policies has been imported successfully!
echo,
echo Cleaning up...
del %db_name%.jfm
del %db_name%.sdb
if exist logs del %logs%
echo,
echo Press any key to exit...
pause > nul
exit
) else (
echo The folder “GroupPolicy” doesn't exist!
pause
)
) else (
echo The file “%db_name%.inf” doesn't exist!
pause
)
) else (
echo The folder “gp_config%version%” doesn't exist or your back-uped grouppolicy file doesn't support current version of Windows!
pause
)