-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun.ps1
221 lines (207 loc) · 8.37 KB
/
run.ps1
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# 强制以管理员权限以运行
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if ($testadmin -eq $false) {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
exit $LASTEXITCODE
}
$script:LICENCE = @"
**********************************************
* Author: Mogeko *
* Github: https://github.com/Mogeko/KMS *
* LICENCE: GNU General Public License v3.0 *
**********************************************
"@
$script:KMS_SERVER = 'kms.mogeko.me'
$script:DATA_JSON_URL = 'https://mogeko.github.io/kms/data.json'
# $script:DATA_JSON_URL = 'http://localhost:8000/data.json' # TEST
if (Test-Path .\data.json) {
$script:MENU_INFO = Get-Content .\data.json | ConvertFrom-Json
} else {
for ($i = 0; $i -lt 5; $i++) {
try {
Write-Host "正在加载 data.json..." -f green
$tmp = New-TemporaryFile
Invoke-WebRequest $script:DATA_JSON_URL -OutFile $tmp
$script:MENU_INFO = Get-Content $tmp | ConvertFrom-Json
} catch {
Write-Host "加载 data.json 失败!重试"($i+1) -f red
} finally {
Remove-Item $tmp
}
if ($script:MENU_INFO) {
break
} elseif ($i -eq 4) {
Write-Host "$nl"
Write-Host "无法加载 data.json,程序即将退出" -f red
Start-Sleep -s 5
exit 1
}
}
}
function Main {
param (
$main
)
$flag = $true;
while ($flag) {
# Drew Menu
Invoke-Expression 'cls';
Write-Host $script:LICENCE;
Write-Host "$nl";
Write-Host $main.description;
Write-Host "$nl";
for ($i = 0; $i -lt $main.option.Count; $i++) {
" {0}) {1}" -f ($i+1), $main.option[$i].Name;
}
Write-Host " $nl";
Write-Host " 0) 返回上级菜单 (没有则退出程序)";
Write-Host " q) 退出程序";
Write-Host " $nl";
# INPUT
$input = Read-Host "输入序号 (可多选)";
$input = $input.ToCharArray() | Sort-Object -Unique;
# Menu logic
foreach($inputItem in $input) {
if ($inputItem -eq "q") {
Invoke-Expression 'cls';
exit 0;
} elseif($inputItem -eq "0") {
Invoke-Expression 'cls';
$flag = $false;
} elseif ($main.option[$inputItem-49].submenu) {
Main $main.option[$inputItem-49].submenu;
} elseif ($main.option[$inputItem-49].action -eq "ActivateWindows") {
ActivateWindows $main.option[$inputItem-49].name;
} elseif ($main.option[$inputItem-49].action -eq "ActivateOffice") {
ActivateOffice $main.Option[$inputItem-49].name $main.option[$inputItem-49].key $main.option[$inputItem-49].osppdir;
} elseif ($main.option[$inputItem-49].action -eq "ConvertOffice") {
ConvertOffice $main.Option[$inputItem-49].name $main.option[$inputItem-49].osppdir $main.option[$inputItem-49].licenses;
}
}
}
}
function ActivateWindows {
param (
[String]$name
)
$cmd = 'slmgr'
$WARNING = @"
作者用爱发电,出了任何问题都是不会负责的
回车后就没有回头路了,你是否真的想好了?
"@
Invoke-Expression 'cls';
"正在{0}..." -f $name
"使用 KMS Server: {0}" -f $script:KMS_SERVER;
Write-Host $WARNING -f red
Invoke-Expression 'Pause'
Invoke-Expression "$cmd /skms $script:KMS_SERVER";
Invoke-Expression "$cmd /ato";
}
function CheckOSPP {
param (
[String]$verion
)
if (Test-Path "$env:ProgramFiles\Microsoft Office\$verion\ospp.vbs") {
return "$env:ProgramFiles\Microsoft Office\$verion\ospp.vbs"
} elseif (Test-Path "$env:ProgramFiles(x86)\Microsoft Office\$verion\ospp.vbs") {
return "$env:ProgramFiles(x86)\Microsoft Office\$verion\ospp.vbs"
} else {
while ($true) {
Invoke-Expression 'cls'
Write-Host "错误!未找到 ospp.vbs 文件" -f red
Write-Host "请输入 ospp.vbs 文件的位置 (一般在 Office 的安装目录中)" -f green
Write-Host "使用 Ctrl+C 强制退出" -f green
$ospp = Read-Host "ospp.vbs"
if (Test-Path $ospp) {
return $ospp
}
}
}
}
function ActivateOffice {
param (
[String]$name, [String]$key, [String]$osppPath
)
$cmd = 'cscript'
$ospp = CheckOSPP $osppPath
$WARNING = @"
作者用爱发电,出了任何问题都是不会负责的
回车后就没有回头路了,你是否真的想好了?
如果 ospp.vbs 位置不对请立即 Ctrl+C 强制退出
"@
Invoke-Expression 'cls';
"正在激活 {0}..." -f $name
"ospp.vbs 位置: {0}" -f $ospp;
"使用 KMS Server: {0}" -f $script:KMS_SERVER;
"使用 KMS Key: {0}" -f $key
Write-Host $WARNING -f red
Invoke-Expression 'Pause'
Invoke-Expression "$cmd `"$ospp`" /inpkey:$key"
Invoke-Expression "$cmd `"$ospp`" /sethst:$script:KMS_SERVER"
Invoke-Expression "$cmd `"$ospp`" /act"
Write-Host "$nl"
Write-Host "激活完成!!"-f green
Write-Host "当前 $name 的激活状态:" -f green
Write-Host "$nl"
Invoke-Expression "$cmd `"$ospp`" /dstatus"
Invoke-Expression 'Pause'
}
function ConvertOffice {
param (
[String]$name, [String]$osppPath, [Array]$licenses
)
$cmd = 'cscript'
$ospp = CheckOSPP $osppPath
$WARNING = @"
作者用爱发电,出了任何问题都是不会负责的
回车后就没有回头路了,你是否真的想好了?
如果 ospp.vbs 位置不对请立即 Ctrl+C 强制退出
"@
Invoke-Expression 'cls';
"正在{0}..." -f $name
"ospp.vbs 位置: {0}" -f $ospp;
foreach ($licitem in $licenses) {
"license 位置(相对于 ospp.vbs): ..\root\{0}" -f $licitem
}
Write-Host $WARNING -f red
Invoke-Expression 'Pause'
# cscript "%ospp%" /inslic:"..\root\Licenses16\ProPlusVL_KMS_Client-ppd.xrm-ms"
foreach ($licitem in $licenses) {
Write-Host "$cmd `"$ospp`" /inslic:`"..\root\$licitem`""
# Invoke-Expression "$cmd `"$ospp`" /inslic:$licitem"
}
Invoke-Expression 'Pause'
}
Main $script:MENU_INFO
# SIG # Begin signature block
# MIIFUgYJKoZIhvcNAQcCoIIFQzCCBT8CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUwXWU5Nbw9eIjwIMVdOm117f9
# tiOgggL2MIIC8jCCAdqgAwIBAgIQGNwy8u+VzZBHfUOc/PT1AzANBgkqhkiG9w0B
# AQsFADARMQ8wDQYDVQQDDAZtb2dla28wHhcNMjAwNTExMjMzMjMxWhcNMjEwNTEx
# MjM1MjMxWjARMQ8wDQYDVQQDDAZtb2dla28wggEiMA0GCSqGSIb3DQEBAQUAA4IB
# DwAwggEKAoIBAQDF0u8Pg+54y62xklE9MDi9RdAmV46KrEZYTb9K914wLCWRJ6es
# QzTEdJPfZVn+kvob+mPUQ1WHi1qv94YTwagmrgr+k3Pu7nmhQ9FL0/mQmbo/xiT4
# x5zmmI1Ib4VQhwJcKMO6LldiOsoBYjYkVx70oOpikjL0Z6bl13/4ARhQNAbAL0mZ
# 8DAJuzZarx/p+bKHeKmr/4Gj/9e2ql5YbBO7N6FWNvSWAIfrVuOhcHW9A2YSNxxa
# +QwLu3bnjvm07JkysQ6BdA+/aK9o5g96Rq+xjwELNWkHcDyy4Mxba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