function GetRegDataType(const strRegPath, strRegValue: string): string;
var
s: string;
objRegistry: TRegistry;
begin
try
// creates the registru manager object
objRegistry := TRegistry.Create;
objRegistry.RootKey := HKEY_LOCAL_MACHINE;
// opens the specified key if exists
if objRegistry.OpenKey(strRegPath, false) then begin
case objRegistry.GetDataType(strRegValue) of
rdUnknown: s := 'Unknown';
rdString: s := 'String';
rdExpandString: s := 'ExpandString';
rdInteger: s := 'Integer';
rdBinary: s := 'Binary';
end;
end else
s := '(Can't get data type)';
finally
// destroys the registry manager object
objRegistry.Free;
end;
// set the return
result := s;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure ReadFromRegistry;
var
R : TRegistry;
begin
R := TRegistry.Create;
try
R.RootKey := HKEY_CURRENT_USER;
if R.OpenKey('\Software\fdehell\srf', True) then
begin
Form1.left:=R.ReadInteger('left');
Form1.top:=R.ReadInteger('top');
Form1.height:=R.ReadInteger('height');
Form1.width:=R.ReadInteger('width');
end;
Finally
R.CloseKey;
R.Free;
end;
end;
procedure WriteToRegistry;
var
R : TRegistry;
begin
R := TRegistry.Create;
try
R.RootKey := HKEY_CURRENT_USER;
if R.OpenKey('\Software\fdehell\srf', True) then
R.WriteInteger('left',Form1.Left);
R.WriteInteger('top',Form1.Top);
R.WriteInteger('height', Form1.Height);
R.WriteInteger('width', Form1.Width);
Finally
R.CloseKey;
R.Free;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
R : TRegistry;
begin
R := TRegistry.Create;
try
R.RootKey := HKEY_CURRENT_USER;
if R.OpenKey('\Software\fdehell\srf', True) then
R.WriteInteger('left',Form1.Left);
R.WriteInteger('top',Form1.Top);
R.WriteInteger('height', Form1.Height);
R.WriteInteger('width', Form1.Width);
Finally
R.CloseKey;
R.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ReadFromRegistry;
end;
procedure TForm1.FormClick(Sender: TObject);
var
AppName : PChar;
begin
AppName := PChar( Application.ExeName );
ShellExecute( Handle, 'open', AppName, nil, nil, SW_SHOWNORMAL );
close;
end;
end.
var strIni: array[0..MAX_PATH] of Char; arrWindows: array[0..64] of Char; begin GetWindowsDirectory(strIni, SizeOf(strIni)); StrCat(strIni, '\win.ini'); with TIniFile.Create(strIni) do try WriteString('windows', 'device', 'HP LaserJet 4 Plus,HPPCL5MS,LPT1:'); finally Free; end; StrCopy(arrWindows, 'windows'); SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@arrWindows)); end;
uses Registry;
procedure TForm1.SimpanSetting;
var
Reg : TRegistry;
begin
Reg := TRegistry.Create;
try
if Reg.OpenKey('\Software\www.kursusdelphi.com', True) then
begin
Reg.WriteInteger('Setting1', Strtoint(Edit1.text));
Reg.WriteString('Setting2', Edit2.text);
Reg.WriteTime('Setting3', StrToTime(Edit3.text));
Reg.CloseKey;
end;
finally
Reg.Free;
inherited;
end;
end;
procedure TForm1.BacaSetting;
var
Reg : TRegistry;
begin
Reg := TRegistry.Create;
try
if Reg.OpenKey('\Software\www.kursusdelphi.com', True) then
begin
if Reg.ValueExists('Setting1') then
Edit4.Text := inttostr(Reg.ReadInteger('Setting1'));
if Reg.ValueExists('Setting2') then
Edit5.Text := Reg.ReadString('Setting2');
if Reg.ValueExists('Setting3') then
Edit6.Text := TimeToStr(Reg.ReadTime('Setting3'));
Reg.CloseKey;
end;
finally
Reg.Free;
inherited;
end;
end;
procedure LockUSB(RegName: String;sRegPolicies:WideString);
var
Reg : TRegistry;
Begin
Reg := TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey(sRegPolicies, True) then
begin
Reg.WriteInteger(RegName,4);
Reg.CloseKey;
//ShowMessage('Lock USB Berhasil.'+#13+'Restart Komputer !!');
end;
finally
Reg.Free;
//inherited;
end;
end;
Cara memanggil procedure
LockSUB('Start','\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR')