admin管理员组

文章数量:1122850

[Delphi]

 

private{ Private declarations }public{ Public declarations }function WriteAppNameToReg:Boolean;function GetIEVersionStr: string;function IsWin64:Boolean;varForm3: TForm3;implementationfunction TForm3.IsWin64:Boolean;   // 判断系统
varKernel32Handle:THandle;IsWow64Process: function(Handle:Windows.THandle;var Res:Windows.BOOL):Windows.BOOL;stdcall;GetNativeSystemInfo:procedure(var lpSystemInfo:TSystemInfo);stdcall;isWoW64: Bool;SystemInfo: TSystemInfo;
constPROCESSOR_ARCHITECTURE_AMD64=9;PROCESSOR_ARCHITECTURE_IA64=6;
beginKernel32Handle:=GetModuleHandle('KERNEL32.DLL');if Kernel32Handle=0 thenKernel32Handle:=LoadLibrary('KERNEL32.DLL');if Kernel32Handle<>0 thenbeginIsWOW64Process:=GetProcAddress(Kernel32Handle,'IsWow64Process');GetNativeSystemInfo:=GetProcAddress(Kernel32Handle,'GetNativeSystemInfo');if Assigned(IsWow64Process) thenbeginIsWow64Process(GetCurrentProcess,isWoW64);Result:=isWoW64 and Assigned(GetNativeSystemInfo);if Result thenbeginGetNativeSystemInfo(SystemInfo);Result:=(SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64)or(SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_IA64);end;endelseResult:=False;endelseResult:=False;
end;
function TForm3.GetIEVersionStr: string;   //获取IE版本
varReg: TRegistry; // registry access object
beginResult := '';Reg := TRegistry.Create;tryReg.RootKey := Windows.HKEY_LOCAL_MACHINE;if Reg.OpenKeyReadOnly('Software\Microsoft\Internet Explorer') thenbegin//这儿新版本IE的取值位置不同所以要判断if Reg.ValueExists('svcVersion') thenResult := Reg.ReadString('svcVersion')elseif Reg.ValueExists('Version') thenResult := Reg.ReadString('Version');end;finallyReg.Free;end;
end;function TForm3.WriteAppNameToReg: Boolean;  //写入到注册表
varreg:TRegistry;sPath,sAppName:String;Sver:string;lenver:Integer;
beginResult:=True;reg:=TRegistry.Create;tryreg.RootKey:=HKEY_LOCAL_MACHINE;sPath:='SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';if isWin64 thensPath:='SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';if reg.OpenKey(sPath,True) thenbeginsAppName:=ExtractFileName(Application.ExeName);Sver:=GetIEVersionStr;lenver:=StrToInt( Copy(Sver,1,Pos('.',Sver)-1) );if lenver<=7 thenreg.WriteInteger(sAppName,7000)elseif lenver=8 thenbeginreg.WriteInteger(sAppName,8000)endelseif lenver=9 thenbeginreg.WriteInteger(sAppName,9000)endelseif lenver=10 thenbeginreg.WriteInteger(sAppName,10000)endelseif lenver=11 thenbeginreg.WriteInteger(sAppName,11001)end;end;reg.CloseKey;finallyFreeAndNil(reg);end;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
WriteAppNameToReg;
end;

 

本文标签: DELPHI