Solved

Copy and Registry

Posted on 2000-04-01
18
194 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:nafa2221
  • 11
  • 7
18 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2677226
Did your quesion about reading and writing to registry?
0
 

Author Comment

by:nafa2221
ID: 2677227
no, I dont care about reading...I just want to know how to add a string to the registry...please post an example.
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2677236
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\SOFTWARE\My Company\My App ***)
  MyRegs.WriteInteger('Ver', 1);
  MyRegs.WriteInteger('Release', 2);
  MyRegs.WriteString('LastUser', '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\SOFTWARE\My Company\My App ***)
    Ver:= MyRegs.ReadInteger('Ver');
    Releas:= MyRegs.ReadInteger('Release');
    LastUser:= MyRegs.ReadInteger('LastUser');
    Result:= True;
  end;
  MyRegs.Free;

end;


Motaz
www.geocities.com/motaz1
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2677240
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
0
 

Author Comment

by:nafa2221
ID: 2677243
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?
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2677255
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
0
 

Author Comment

by:nafa2221
ID: 2677259
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'
0
 

Author Comment

by:nafa2221
ID: 2677263
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
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2677268
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


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:nafa2221
ID: 2677272
Adjusted points from 200 to 1000
0
 

Author Comment

by:nafa2221
ID: 2677273
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!!!
0
 

Author Comment

by:nafa2221
ID: 2677282
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!!!
0
 
LVL 7

Accepted Solution

by:
Motaz earned 1000 total points
ID: 2677284
Thanks, very much

If you need any help you can e-mail me,,

Motaz
www.geocities.com/motaz1
motaz1@yahoo.com

0
 

Author Comment

by:nafa2221
ID: 2677293
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' ;]
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2677297
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
0
 

Author Comment

by:nafa2221
ID: 2677302
still dident work ;(
0
 

Author Comment

by:nafa2221
ID: 2677304
I got it, I just put the string in a Text Box ;]
0
 

Author Comment

by:nafa2221
ID: 2677305
post a new anwser ;]
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now