0xFF Posted September 1, 2011 Posted September 1, 2011 (edited) I no longer use this routine, and if i were not to post it somewhere, it'll be a waste of code (why reinvent the wheel, right?) so i thought someone might find it useful or want to know how to use the Registry in Delphi..procedure EnableBalloonTips(Enable: Boolean);const RegVal = 'EnableBalloonTips';var Reg: TRegistry;begin Reg := TRegistry.Create( KEY_WRITE or KEY_READ ); with Reg do try RootKey := HKEY_CURRENT_USER; if OpenKey( 'Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\', True ) then case Ord( Enable ) of 1: begin if ValueExists( RegVal ) then DeleteValue( RegVal ); end; 0: begin if not ValueExists( RegVal ) then WriteInteger( RegVal, Ord( False ) ); end; end; finally CloseKey; Free; end;end;function UACEnabled: Boolean;const Val = 'EnableLUA';var Reg: TRegistry; n : Integer;begin Result := False; Reg := TRegistry.Create( KEY_READ ); with Reg do try try RootKey := HKEY_LOCAL_MACHINE; if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System', False) then if ValueExists(Val) then begin n := ReadInteger(Val); case n of 0: Result := False; 1: Result := True; end; end; finally CloseKey; Free; end; except Exit; end;end;Procedure DisableUAC;Var Reg: TRegistry;Begin Reg := TRegistry.Create( KEY_WRITE ); with Reg do try try RootKey := HKEY_LOCAL_MACHINE; if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System', False) then begin WriteInteger('EnableLUA', 0); WriteInteger('ConsentPromptBehaviorAdmin', 0); WriteInteger('ConsentPromptBehaviorUser' , 0); end; finally CloseKey; Free; end; except Exit; end;End;Procedure SetRunAsAdminFlag(PathToExe: String);Var Reg: TRegistry;Begin Reg := TRegistry.Create( KEY_WRITE ); with Reg do try try RootKey := HKEY_CURRENT_USER; if OpenKey('Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers', True) then WriteString( PathToExe, 'RUNASADMIN' ); finally CloseKey; Free; end; except Exit; end;End;procedure AddRunOnce( ValueName, ExePath: String);var Reg: TRegistry;begin Reg := TRegistry.Create( KEY_WRITE ); with Reg do try RootKey := HKEY_LOCAL_MACHINE; LazyWrite := False; try OpenKey( 'Software\Microsoft\Windows\CurrentVersion\RunOnce', True ); WriteString( ValueName, ExePath ); finally CloseKey; Free; end; except Exit; end;end; Edited March 23, 2012 by rotem156
0xFF Posted September 7, 2011 Author Posted September 7, 2011 (edited) btw, SetRunAsAdminFlag() doesn't run your App as admin directly, it just masks the flag in the Compatibility tab to your file...do not get confused..Edit: To mess with Windows Firewall, here's its Registry settings...HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services\SharedAccess\Parameters\FirewallPolicyAlthough, controling it via Com Objects is not hard also... Edited September 8, 2011 by rotem156
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now