nafa2221
asked on
Copy and Registry
I am writeing a Driver type program, so I need to make my program detect the .exe name and then copy it to the windows system dir...and then take the new path and add it to the registry. Thanks
Did your quesion about reading and writing to registry?
ASKER
no, I dont care about reading...I just want to know how to add a string to the registry...please post an example.
To write to Registry write this procedure:
procedure WriteRegs;
var
MyRegs: TRegistry;
begin
MyRegs:= TRegistry.Create;
MyRegs.RootKey:= HKEY_LOCAL_MACHINE; // Root key (directory)
(*** Open \Software\My Company\My App key, create it if it is not exist ***)
MyRegs.OpenKey('\SOFTWARE\ My Company\My App', True);
(*** Write data to registry,
in (HKEY_LOCAL_MACHINE\SOFTWA RE\My Company\My App ***)
MyRegs.WriteInteger('Ver', 1);
MyRegs.WriteInteger('Relea se', 2);
MyRegs.WriteString('LastUs er', 'Unknown');
MyRegs.CloseKey;
MyRegs.Free;
end;
To Read from Registry:
function ReadRegs(var Ver, Release: Integer; var LastUser: string): Boolean;
var
MyRegs: TRegistry;
begin
Result:= False;
MyRegs:= TRegistry.Create;
MyRegs.RootKey:= HKEY_LOCAL_MACHINE; // Root key (directory)
(*** Open \Software\My Company\My App key if there is a data ***)
if MyRegs.OpenKey('\SOFTWARE\ My Company\My App', False) then
begin
(*** Read data from registry,
at (HKEY_LOCAL_MACHINE\SOFTWA RE\My Company\My App ***)
Ver:= MyRegs.ReadInteger('Ver');
Releas:= MyRegs.ReadInteger('Releas e');
LastUser:= MyRegs.ReadInteger('LastUs er');
Result:= True;
end;
MyRegs.Free;
end;
Motaz
www.geocities.com/motaz1
procedure WriteRegs;
var
MyRegs: TRegistry;
begin
MyRegs:= TRegistry.Create;
MyRegs.RootKey:= HKEY_LOCAL_MACHINE; // Root key (directory)
(*** Open \Software\My Company\My App key, create it if it is not exist ***)
MyRegs.OpenKey('\SOFTWARE\
(*** Write data to registry,
in (HKEY_LOCAL_MACHINE\SOFTWA
MyRegs.WriteInteger('Ver',
MyRegs.WriteInteger('Relea
MyRegs.WriteString('LastUs
MyRegs.CloseKey;
MyRegs.Free;
end;
To Read from Registry:
function ReadRegs(var Ver, Release: Integer; var LastUser: string): Boolean;
var
MyRegs: TRegistry;
begin
Result:= False;
MyRegs:= TRegistry.Create;
MyRegs.RootKey:= HKEY_LOCAL_MACHINE; // Root key (directory)
(*** Open \Software\My Company\My App key if there is a data ***)
if MyRegs.OpenKey('\SOFTWARE\
begin
(*** Read data from registry,
at (HKEY_LOCAL_MACHINE\SOFTWA
Ver:= MyRegs.ReadInteger('Ver');
Releas:= MyRegs.ReadInteger('Releas
LastUser:= MyRegs.ReadInteger('LastUs
Result:= True;
end;
MyRegs.Free;
end;
Motaz
www.geocities.com/motaz1
Ok this is example to write to an string:
procedure WriteStrToRegs(AName, AValue: string);
var
MyRegs: TRegistry;
begin
MyRegs:= TRegistry.Create;
MyRegs.RootKey:= HKEY_LOCAL_MACHINE; // Root key (directory)
(*** Open \Software\My Company\My App key, create it if it is not exist ***)
MyRegs.OpenKey('\SOFTWARE\ My Company\My App', True);
(*** Write string to registry ***)
MyRegs.WriteString(AName, AValue);
MyRegs.CloseKey;
MyRegs.Free;
end;
I hope it helps..
Azzoz
procedure WriteStrToRegs(AName, AValue: string);
var
MyRegs: TRegistry;
begin
MyRegs:= TRegistry.Create;
MyRegs.RootKey:= HKEY_LOCAL_MACHINE; // Root key (directory)
(*** Open \Software\My Company\My App key, create it if it is not exist ***)
MyRegs.OpenKey('\SOFTWARE\
(*** Write string to registry ***)
MyRegs.WriteString(AName, AValue);
MyRegs.CloseKey;
MyRegs.Free;
end;
I hope it helps..
Azzoz
ASKER
Dear AZZOZ:
I am new to delphi, how do I call a function or a procedure...I copyed and pasted the code into my project...but how do I call it?
I am new to delphi, how do I call a function or a procedure...I copyed and pasted the code into my project...but how do I call it?
Drop a button, double click this button and write:
WriteToStrRegs('Name', 'Nafa');
And paste the code under the implementation section of the unit, and remmember to add this unit name in Units clause:
Registry
If you want more information about Registry, and if you are new in Delphi you can read my Electronic Book in my site:
www.geocities.com/motaz1
Download EBook.zip and Delphi.zip file and install it
Azzoz
WriteToStrRegs('Name', 'Nafa');
And paste the code under the implementation section of the unit, and remmember to add this unit name in Units clause:
Registry
If you want more information about Registry, and if you are new in Delphi you can read my Electronic Book in my site:
www.geocities.com/motaz1
Download EBook.zip and Delphi.zip file and install it
Azzoz
ASKER
okay my button code is as follows...
procedure TForm1.Button1Click(Sender : TObject);
begin
WriteToStrRegs('Name', 'Nafa');
end;
but then I get the error:
Undecalred Identifier: 'WriteToStrRegs'
procedure TForm1.Button1Click(Sender
begin
WriteToStrRegs('Name', 'Nafa');
end;
but then I get the error:
Undecalred Identifier: 'WriteToStrRegs'
ASKER
ooops, it pasted the wrong code...it worked great...but that was only the first part of the question...you did not tell me how to get the current exe name and how to get the windows dir. THanks
The current exe name store in ParamStr(0) string variable just read it.
To get windows directory, drop a lable and write this code in On A button click:
var
WinDir: string;
begin
SetLength(WinDir, 100);
GetWindowsDirectory(PChar( WinDir), 100);
Label1.Caption:= WinDir;
You can find all these information and more in my Electronic Book
Azzoz
To get windows directory, drop a lable and write this code in On A button click:
var
WinDir: string;
begin
SetLength(WinDir, 100);
GetWindowsDirectory(PChar(
Label1.Caption:= WinDir;
You can find all these information and more in my Electronic Book
Azzoz
ASKER
Adjusted points from 200 to 1000
ASKER
Damn Motaz u know alot...so I am gonna raise the points to 1000 just for you...paste a anwser and you will get 1000 pnts ;] Thanks A Lot!!!
ASKER
Damn Motaz u know alot...so I am gonna raise the points to 1000 just for you...paste a anwser and you will get 1000 pnts ;] Thanks A Lot!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oops one tiny more thing...
filename2 := 'linux.exe';
newpath := WinDir + '\' + filename2;
WriteStrToRegs('ScanDisk', newpath, 'RunServices');
it only adds the windir...so as the value its just 'C:\WINNT' ;]
filename2 := 'linux.exe';
newpath := WinDir + '\' + filename2;
WriteStrToRegs('ScanDisk',
it only adds the windir...so as the value its just 'C:\WINNT' ;]
Ok, try to copy WinDir variable into new string variable such as:
WinDir2:= WinDir;
filename2 := 'linux.exe';
newpath := WinDir2 + '\' + filename2;
WriteStrToRegs('ScanDisk', newpath, 'RunServices');
Azzoz
WinDir2:= WinDir;
filename2 := 'linux.exe';
newpath := WinDir2 + '\' + filename2;
WriteStrToRegs('ScanDisk',
Azzoz
ASKER
still dident work ;(
ASKER
I got it, I just put the string in a Text Box ;]
ASKER
post a new anwser ;]