Posted September 1, 201113 yr 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, 201213 yr by rotem156
September 7, 201113 yr Author 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, 201113 yr by rotem156
Create an account or sign in to comment