2525using System . Globalization ;
2626using System . Reflection ;
2727using MaterialDesignThemes . Wpf ;
28+ using System . IO . Pipes ;
2829
2930namespace CMWTAT_DIGITAL
3031{
@@ -133,9 +134,10 @@ public void ExportTempFile()
133134
134135 ConsoleLog ( "开始写入缓存文件" ) ;
135136 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);
138137 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 ) ;
139141 ConsoleLog ( "写入缓存文件完毕" ) ;
140142 }
141143
@@ -1115,19 +1117,28 @@ private void RunAct()
11151117 }
11161118 }
11171119
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+ } ) ) ;
11201126
11211127 if ( mode == "4" )
11221128 {
11231129 //长期KMS
11241130 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" ) ; // 用于旧版保底方案
11291136 }
11301137
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+
11311142 actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
11321143 {
11331144 this . activatingtext . Text = ( string ) this . Resources [ "RunAct_Installing_Key" ] ; //提示正在安装密钥
@@ -1156,25 +1167,29 @@ private void RunAct()
11561167 {
11571168 //长期KMS
11581169 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)" ) ;
11591177 }
1160-
1178+
11611179 var result = LibGatherOsState . GatherOsState . GenActivateLicenseXML ( licenseType ) ;
11621180
11631181 if ( result . state == LibGatherOsState . GatherOsState . ActivateLicenseXMLResultState . OK )
11641182 {
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)" ) ;
11741185 }
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 )
11771191 {
1192+
11781193 actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
11791194 {
11801195 this . activatingtext . Text = ( string ) this . Resources [ "RunAct_Getting_digital_license" ] ; // "Getting digital license";
@@ -1199,8 +1214,13 @@ private void RunAct()
11991214 } ) ) ;
12001215
12011216 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 ++ )
12031218 {
1219+ if ( hasOldTicket && ! File . Exists ( tempfile + "GenuineTicket.xml" ) )
1220+ {
1221+ break ;
1222+ }
1223+ if ( hasvNextTicket && ! File . Exists ( tempfile + "GenuineTicketvNext.xml" ) )
12041224 Thread . Sleep ( 1000 ) ;
12051225 ConsoleLog ( $ "应用许可证 重试 { i } /{ try_max_count } ") ;
12061226 }
@@ -1241,6 +1261,21 @@ private void RunAct()
12411261 }
12421262 //string runend = RunCScript(slmgr_self, "-upk").Trim();
12431263 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+ }
12441279 if ( code != "200" )
12451280 {
12461281 actbtn . Dispatcher . Invoke ( new Action ( ( ) =>
@@ -1306,7 +1341,7 @@ private void RunCMD_old(string var)
13061341 p . StartInfo . RedirectStandardOutput = true ; //由调用程序获取输出信息
13071342 p . StartInfo . CreateNoWindow = true ; //不显示程序窗口
13081343 p . Start ( ) ; //启动程序
1309- //向CMD窗口发送输入信息:
1344+ //向CMD窗口发送输入信息:
13101345 p . StandardInput . WriteLine ( var ) ;
13111346 ConsoleLog ( var ) ;
13121347 //p.WaitForExit();
@@ -1321,7 +1356,7 @@ public static string RunCLI(string path, string wdPath, string var = "")
13211356 {
13221357 ConsoleLog ( path + " " + var ) ;
13231358 Wow64EnableWow64FsRedirection ( false ) ; //关闭文件重定向
1324- //执行命令行函数
1359+ //执行命令行函数
13251360 try
13261361 {
13271362 System . Diagnostics . Process myProcess = new System . Diagnostics . Process ( ) ;
@@ -1336,7 +1371,7 @@ public static string RunCLI(string path, string wdPath, string var = "")
13361371 //myProcess.Arguments = "/c " & Commands
13371372 //myProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;
13381373 myProcess . Start ( ) ;
1339- myProcess . WaitForExit ( 60 * 1000 ) ;
1374+ myProcess . WaitForExit ( 120 * 1000 ) ;
13401375 StreamReader myStreamReader = myProcess . StandardOutput ;
13411376 string myString = myStreamReader . ReadToEnd ( ) ;
13421377 myProcess . Close ( ) ;
0 commit comments