.NetC#限定某个web应用只能在固定的机器上运行

编程

Powershell : Read local windows server"s MachineGUID then set it in c# code.

(Get-ItemProperty registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftCryptography -Name MachineGuid).MachineGUID

C# : Code under,  read Local windows" machineguid to compare with seted value though powershell in c#.

            string machineGuid = string.Empty;

            RegistryKey keyBaseX64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

            RegistryKey keyBaseX86 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);

            RegistryKey keyX64 = keyBaseX64.OpenSubKey(@"SOFTWAREMicrosoftCryptography"RegistryKeyPermissionCheck.ReadSubTree);

            RegistryKey keyX86 = keyBaseX86.OpenSubKey(@"SOFTWAREMicrosoftCryptography"RegistryKeyPermissionCheck.ReadSubTree);

            object resultObjX64 = keyX64.GetValue("MachineGuid", (object)"default");

            object resultObjX86 = keyX86.GetValue("MachineGuid", (object)"default");

            keyX64.Close();

            keyX86.Close();

            keyBaseX64.Close();

            keyBaseX86.Close();

            keyX64.Dispose();

            keyX86.Dispose();

            keyBaseX64.Dispose();

            keyBaseX86.Dispose();

            //keyX64 = null;

            //keyX86 = null;

            //keyBaseX64 = null;

            //keyBaseX86 = null;

            if (resultObjX64 != null && resultObjX64.ToString() != "default")

            {

                Console.WriteLine($"X64:{resultObjX64.ToString()}");

                machineGuid = resultObjX64.ToString();

            }

            if (resultObjX86 != null && resultObjX86.ToString() != "default")

            {

                Console.WriteLine($"X86:{resultObjX86.ToString()}");

                machineGuid = resultObjX86.ToString();

            }

以上是 .NetC#限定某个web应用只能在固定的机器上运行 的全部内容, 来源链接: utcz.com/z/514706.html

回到顶部