Subscribe:

Ads 468x60px

Loading

Minggu, 10 Juli 2011

create a registry entry in the autorun key

There's a RunOnce key in the registry.
When a user logs on, the programs in the run-once list are run just once,
and then the entries will be removed.
The "runonce" key is normally used by setup programs to install
software after a machine has been rebooted.


// Add the application to the registry...

procedure DoAppToRunOnce(RunName, AppName: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Microsoft\Windows\CurrentVersion\RunOnce', True);
WriteString(RunName, AppName);
CloseKey;
Free;
end;
end;

// Check if the application is in the registry...
// Prüfen, ob Anwendung in der Registry vorhanden ist...

function IsAppInRunOnce(RunName: string): Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Microsoft\Windows\CurrentVersion\RunOnce', False);
Result := ValueExists(RunName);
CloseKey;
Free;
end;
end;

// Remove the application from the registry...
// Anwendung aus der Registry entfernen...

procedure DelAppFromRunOnce(RunName: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Microsoft\Windows\CurrentVersion\RunOnce', True);
if ValueExists(RunName) then DeleteValue(RunName);
CloseKey;
Free;
end;
end;

{
Applications under the key "Run" will be executed
each time the user logs on.
{

{
Jede Anwendung, die im Schlüssel Run aufgeführt ist, wird beim
jedem Windowsstart ausgeführt. Betrifft Anwendungen, die immer
mit Windows gestartet werden sollen...
}


// Add the application to the registry...
// Anwendung in die Registry aufnehmen...

procedure DoAppToRun(RunName, AppName: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True);
WriteString(RunName, AppName);
CloseKey;
Free;
end;
end;

// Check if the application is in the registry...
// Prüfen, ob Anwendung in der Registry vorhanden ist...

function IsAppInRun(RunName: string): Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', False);
Result := ValueExists(RunName);
CloseKey;
Free;
end;
end;

// Remove the application from the registry...
// Anwendung aus der Registry entfernen...

procedure DelAppFromRun(RunName: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True);
if ValueExists(RunName) then DeleteValue(RunName);
CloseKey;
Free;
end;
end;

// Examples, Beispiele

// Add app, Anwendung aufnehmen...
DoAppToRun('Programm', 'C:\Programs\XYZ\Program.exe');

// Is app there ? Ist Anwendung vorhanden?
if IsAppInRun('Programm') then...

// Remove app, Anwendung entfernen
DelAppFromRun('Programm');

0 komentar:

Posting Komentar