Jump to content
Tuts 4 You

[Delphi] Snippets (Rev 0.1)


0xFF

Recommended Posts

Posted (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 by rotem156
Posted (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\FirewallPolicy

Although, controling it via Com Objects is not hard also...

Edited by rotem156
  • 3 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...