這里講一C#小列子(高手請繞過此地!), 我們平時(shí)都是在xp開發(fā)比較多...不過現(xiàn)在很多開發(fā)人員也在win7下開發(fā)了。
下面是在LocalMachine下的 一下注冊表操作 ,就不詳說了
PRivate static void DeleteRegistry(string name){string[] aimnames;RegistryKey hkml = Registry.LocalMachine;RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);RegistryKey aimdir = software.OpenSubKey("Microsoftss", true);aimnames = aimdir.GetSubKeyNames();foreach (string aimKey in aimnames){if (aimKey == name)during-pregnancyaimdir.DeleteSubKeyTree(name);}}private static string GetData(string name){string registData;RegistryKey hkml = Registry.LocalMachine;RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);RegistryKey aimdir = software.OpenSubKey("Microsoftss", true);registData = aimdir.GetValue(name).ToString();return registData;}private static void WriteValue(string name, string tovalue){RegistryKey hklm = Registry.LocalMachine;RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);RegistryKey aimdir = software.CreateSubKey("Microsoftss");aimdir.SetValue(name, tovalue);}private static bool IsExit(string name){bool _exit = false;android中記錄讀取配置信息string[] subkeyNames;RegistryKey hkml = Registry.LocalMachine;RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);RegistryKey aimdir = software.OpenSubKey("Microsoftss", true);subkeyNames = aimdir.GetValueNames();foreach (string keyName in subkeyNames){if (keyName == name){_exit = true;return _exit;}}return _exit;}
比如,當(dāng)我們在xp系統(tǒng)下 軟件執(zhí)行Writevalue("版本號","v1.0.0.1"),一切都o(jì)k! 然后樂的就拋給了客戶...沒有思考。
一天客戶換了win7系統(tǒng) ,運(yùn)了軟件了。客戶拉著42號鞋子的臉說,怎么軟件在win7不能運(yùn)行了....。問題就是上面開頭說的了。
解決方法是有地....
這里列舉幾種.
第一種、教教客戶、或者技術(shù)服務(wù)人員就好了。這個(gè)方法不需要修改我們的代碼這是好處之一。只要, 點(diǎn)擊.exe 右鍵
,在彈出的菜單中選擇【屬性】,選擇【兼容性】項(xiàng),并勾選【以管理員身份運(yùn)行此程序】就ok了。簡單吧
第二種、也算簡單,不過我們就要重新生成軟件了。首先、在程序中加入MANIFEST資源,右擊工程在菜單->【屬性】->【安全性】,在界面中勾選【啟用ClickOnce安全設(shè)置】,在項(xiàng)目的Properties下就有自動生成app.manifest文件。
文件內(nèi)容如下:
<?xml version="1.0" encoding="utf-8"?><asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><assemblyIdentity version="1.0.0.0" name="Myapplication.app" /><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><!-- UAC 清單選項(xiàng)如果希望更改 Windows 用戶帳戶控制級別,請用以下節(jié)點(diǎn)之一替換requestedExecutionLevel 節(jié)點(diǎn)。<requestedExecutionLevel level="asInvoker" uiaccess="false" /><requestedExecutionLevel level="requireAdministrator" uiAccess="false" /><requestedExecutionLevel level="highestAvailable" uiAccess="false" />如果您希望利用文件和注冊表虛擬化提供向后兼容性,請刪除 requestedExecutionLevel 節(jié)點(diǎn)。--><requestedExecutionLevel level="asInvoker" uiAccess="false" /></requestedPrivileges><applicationRequestMinimum><defaultAssemblyRequest permissionSetReference="Custom" /><PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" /></applicationRequestMinimum></security></trustInfo></asmv1:assembly>
把 <requestedExecutionLevel level="asInvoker"uiAccess="false"/> 的asInvoker 改為"requireAdministrator"。重新編譯一下就ok了。
看到這個(gè)了吧!
這就是UAC(用戶帳戶控制)了
<!-- UAC 清單選項(xiàng)
如果希望更改 Windows 用戶帳戶控制級別,請用以下節(jié)點(diǎn)之一替換
requestedExecutionLevel 節(jié)點(diǎn)。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<span style="color: #ff0000;"><strong> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /></strong></span>
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
如果您希望利用文件和注冊表虛擬化提供
向后兼容性,請刪除 requestedExecutionLevel 節(jié)點(diǎn)。
-->
還有其他的方法。不過上面兩種比較簡單...。
新聞熱點(diǎn)
疑難解答
圖片精選