25
25
using System . Globalization ;
26
26
using System . Reflection ;
27
27
using MaterialDesignThemes . Wpf ;
28
+ using System . IO . Pipes ;
28
29
29
30
namespace CMWTAT_DIGITAL
30
31
{
@@ -133,9 +134,10 @@ public void ExportTempFile()
133
134
134
135
ConsoleLog ( "开始写入缓存文件" ) ;
135
136
File . WriteAllBytes ( tempfile + "ClipUp" + ".exe" , Properties . Resources . ClipUp ) ;
136
- //File.WriteAllBytes(tempfile + "LibHWIDx86" + ".dll", Properties.Resources.LibHWIDx86);
137
- //File.WriteAllBytes(tempfile + "LibHWIDx64" + ".dll", Properties.Resources.LibHWIDx64);
138
137
File . WriteAllBytes ( tempfile + "slmgr" + ".vbs" , Properties . Resources . slmgr ) ;
138
+ File . WriteAllBytes ( tempfile + "gatherosstate" + ".exe" , Properties . Resources . gatherosstate ) ;
139
+ File . WriteAllBytes ( tempfile + "gatherosstateltsc" + ".exe" , Properties . Resources . gatherosstateltsc ) ;
140
+ File . WriteAllBytes ( tempfile + "slc" + ".dll" , Properties . Resources . slc ) ;
139
141
ConsoleLog ( "写入缓存文件完毕" ) ;
140
142
}
141
143
@@ -1115,19 +1117,28 @@ private void RunAct()
1115
1117
}
1116
1118
}
1117
1119
1118
- //写入Win7特征
1119
- //ChangePKAction(changepk + " /ProductKey " + key);
1120
+ //写入旧系统特征(用于旧版保底方案)
1121
+ actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
1122
+ {
1123
+ this . activatingtext . Text = ( string ) this . Resources [ "RunAct_Writing_old_OS" ] ; // "Writing feature of old Windows version";
1124
+ ShowBallSameDig ( ) ;
1125
+ } ) ) ;
1120
1126
1121
1127
if ( mode == "4" )
1122
1128
{
1123
1129
//长期KMS
1124
1130
ConsoleLog ( RunCScript ( slmgr_self , "-skms 1.1.45.14:1919" ) . Trim ( ) ) ; // いいよ、来いよ www
1125
- //ConsoleLog(RunCMD(@"cscript.exe /nologo %systemroot%\system32\slmgr.vbs -skms 1.1.45.14:1919").Trim()); // いいよ、来いよ www
1126
- //if (runend.EndsWith("successfully."))
1127
- //{
1128
- //}
1131
+ RunCMD ( @"reg add ""HKLM\SYSTEM\Tokens"" /v ""Channel"" /t REG_SZ /d ""Volume:GVLK"" /f" ) ; // 用于旧版保底方案
1132
+ }
1133
+ else
1134
+ {
1135
+ RunCMD ( @"reg add ""HKLM\SYSTEM\Tokens"" /v ""Channel"" /t REG_SZ /d ""Retail"" /f" ) ; // 用于旧版保底方案
1129
1136
}
1130
1137
1138
+ // 写入注册表模拟激活和产品信息(用于旧版保底方案)
1139
+ RunCMD ( @"reg add ""HKLM\SYSTEM\Tokens\Kernel"" /v ""Kernel-ProductInfo"" /t REG_DWORD /d " + sku + " /f" ) ;
1140
+ RunCMD ( @"reg add ""HKLM\SYSTEM\Tokens\Kernel"" /v ""Security-SPP-GenuineLocalStatus"" /t REG_DWORD /d 1 /f" ) ;
1141
+
1131
1142
actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
1132
1143
{
1133
1144
this . activatingtext . Text = ( string ) this . Resources [ "RunAct_Installing_Key" ] ; //提示正在安装密钥
@@ -1156,25 +1167,29 @@ private void RunAct()
1156
1167
{
1157
1168
//长期KMS
1158
1169
licenseType = LibGatherOsState . GatherOsState . LicenseType . GVLK ;
1170
+ RunCLI ( tempfile + "gatherosstateltsc.exe" , tempfile ) ;
1171
+ ConsoleLog ( "进入下一步(CUR:LTSC OLD)" ) ;
1172
+ }
1173
+ else
1174
+ {
1175
+ RunCLI ( tempfile + "gatherosstate.exe" , tempfile ) ;
1176
+ ConsoleLog ( "进入下一步(CUR:OLD)" ) ;
1159
1177
}
1160
-
1178
+
1161
1179
var result = LibGatherOsState . GatherOsState . GenActivateLicenseXML ( licenseType ) ;
1162
1180
1163
1181
if ( result . state == LibGatherOsState . GatherOsState . ActivateLicenseXMLResultState . OK )
1164
1182
{
1165
- File . WriteAllText ( tempfile + "GenuineTicket.xml" , result . xml , Encoding . UTF8 ) ;
1166
- ConsoleLog ( "进入下一步" ) ;
1167
-
1168
- int try_max_count = 30 ;
1169
- for ( int i = 0 ; i < try_max_count + 1 && ! File . Exists ( tempfile + "GenuineTicket.xml" ) ; i ++ )
1170
- {
1171
- Thread . Sleep ( 1000 ) ;
1172
- ConsoleLog ( $ "检查许可证 重试 { i } /{ try_max_count } ") ;
1173
- }
1183
+ File . WriteAllText ( tempfile + "GenuineTicketvNext.xml" , result . xml , Encoding . UTF8 ) ;
1184
+ ConsoleLog ( "进入下一步(CUR:VNEXT)" ) ;
1174
1185
}
1175
-
1176
- if ( File . Exists ( tempfile + "GenuineTicket.xml" ) )
1186
+
1187
+ var hasOldTicket = File . Exists ( tempfile + "GenuineTicket.xml" ) ;
1188
+ var hasvNextTicket = File . Exists ( tempfile + "GenuineTicketvNext.xml" ) ;
1189
+
1190
+ if ( hasOldTicket || hasvNextTicket )
1177
1191
{
1192
+
1178
1193
actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
1179
1194
{
1180
1195
this . activatingtext . Text = ( string ) this . Resources [ "RunAct_Getting_digital_license" ] ; // "Getting digital license";
@@ -1199,8 +1214,13 @@ private void RunAct()
1199
1214
} ) ) ;
1200
1215
1201
1216
int try_max_count = 30 ;
1202
- for ( int i = 0 ; i < try_max_count + 1 && File . Exists ( tempfile + "GenuineTicket.xml" ) ; i ++ )
1217
+ for ( int i = 0 ; i < try_max_count + 1 ; i ++ )
1203
1218
{
1219
+ if ( hasOldTicket && ! File . Exists ( tempfile + "GenuineTicket.xml" ) )
1220
+ {
1221
+ break ;
1222
+ }
1223
+ if ( hasvNextTicket && ! File . Exists ( tempfile + "GenuineTicketvNext.xml" ) )
1204
1224
Thread . Sleep ( 1000 ) ;
1205
1225
ConsoleLog ( $ "应用许可证 重试 { i } /{ try_max_count } ") ;
1206
1226
}
@@ -1241,6 +1261,21 @@ private void RunAct()
1241
1261
}
1242
1262
//string runend = RunCScript(slmgr_self, "-upk").Trim();
1243
1263
EndLine : ;
1264
+ // 此处确保注册表清理一定进行
1265
+ try
1266
+ {
1267
+ actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
1268
+ {
1269
+ this . activatingtext . Text = ( string ) this . Resources [ "RunAct_Cleaning_changes" ] ; // "Cleaning changes";
1270
+ ShowBallSameDig ( ) ;
1271
+ } ) ) ;
1272
+
1273
+ RunCMD ( @"reg delete ""HKLM\SYSTEM\Tokens"" /f" ) ;
1274
+ }
1275
+ catch
1276
+ {
1277
+ ConsoleLog ( "Delete Reg Error" ) ;
1278
+ }
1244
1279
if ( code != "200" )
1245
1280
{
1246
1281
actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
@@ -1306,7 +1341,7 @@ private void RunCMD_old(string var)
1306
1341
p . StartInfo . RedirectStandardOutput = true ; //由调用程序获取输出信息
1307
1342
p . StartInfo . CreateNoWindow = true ; //不显示程序窗口
1308
1343
p . Start ( ) ; //启动程序
1309
- //向CMD窗口发送输入信息:
1344
+ //向CMD窗口发送输入信息:
1310
1345
p . StandardInput . WriteLine ( var ) ;
1311
1346
ConsoleLog ( var ) ;
1312
1347
//p.WaitForExit();
@@ -1321,7 +1356,7 @@ public static string RunCLI(string path, string wdPath, string var = "")
1321
1356
{
1322
1357
ConsoleLog ( path + " " + var ) ;
1323
1358
Wow64EnableWow64FsRedirection ( false ) ; //关闭文件重定向
1324
- //执行命令行函数
1359
+ //执行命令行函数
1325
1360
try
1326
1361
{
1327
1362
System . Diagnostics . Process myProcess = new System . Diagnostics . Process ( ) ;
@@ -1336,7 +1371,7 @@ public static string RunCLI(string path, string wdPath, string var = "")
1336
1371
//myProcess.Arguments = "/c " & Commands
1337
1372
//myProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;
1338
1373
myProcess . Start ( ) ;
1339
- myProcess . WaitForExit ( 60 * 1000 ) ;
1374
+ myProcess . WaitForExit ( 120 * 1000 ) ;
1340
1375
StreamReader myStreamReader = myProcess . StandardOutput ;
1341
1376
string myString = myStreamReader . ReadToEnd ( ) ;
1342
1377
myProcess . Close ( ) ;
0 commit comments