Here I will talk aboutC #Small column child (Attackers can bypass this area!), We usually develop a lot in xp, but now many developers have developed it in win7.
Below isLocalMachineThe following registry operations will not be detailed.
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-pregnancy
Aimdir. 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; read configuration information recorded in 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;
}
For example, when we run Writevalue ("version", "v1.0.0.1") in the XP system, everything is OK! Then happy was thrown to the customer without thinking.
One day, the customer changed the win7 system and ran the software. The customer pulled the face of the No. 42 shoes and said, how can the software not run in win7 ..... The problem is what we mentioned above.
SolutionIt's a land ....
Several types are listed here.
First, Teach customers, or technical service personnel. This method does not need to modify our code, which is one of the advantages. Right-click .exe.
In the pop-up menu, select Properties, select compatibility, and select run this program as administrator. Easy to use
SecondIt's easy, but we needRegenerate Software. First, add the MANIFEST resource to the program, right-click the project, choose Properties> Security, and select enable ClickOnce security settings on the page.PropertiesAutomatically generated underApp. manifestFile.
The file content is as follows:
<? 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 configuration options
If you want to change the Windows User Account Control level, replace it with one of the following nodes:
RequestedExecutionLevel node.
<RequestedExecutionLevel level = "asInvoker" uiAccess = "false"/>
<RequestedExecutionLevel level = "requireAdministrator" uiAccess = "false"/>
<RequestedExecutionLevel level = "highestAvailable" uiAccess = "false"/>
If you want to use file and Registry virtualization to provide
For backward compatibility, delete the requestedExecutionLevel node.
-->
<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>
Set <requestedExecutionLevel ="AsInvokerChange asInvoker of "uiAccess =" false "/>"RequireAdministrator". Recompile it and you will be OK.
See this!
This isUAC(User Account Control)
<! -- UAC configuration options
If you want to change the Windows User Account Control level, replace it with one of the following nodes:
RequestedExecutionLevel node.
<RequestedExecutionLevel level = "asInvoker" uiAccess = "false"/>
<Span> <requestedExecutionLevel level = "highestAvailable" uiAccess = "false"/>
If you want to use file and Registry virtualization to provide
For backward compatibility, delete the requestedExecutionLevel node.
-->
There are other methods. However, the above two methods are relatively simple ....