Solved

startup and copy dirs

Posted on 2001-07-09
9
158 Views
Last Modified: 2010-04-06
1- How can i start my program when windows starts??
2- How can i copy 3 dirs (dir1, dir2, dir3) to d:\backup??

thanx..
0
Comment
Question by:sophiesas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 2

Accepted Solution

by:
Tasomia earned 70 total points
ID: 6265056
1)

Uses
  Registry;

procedure SetAutoStart(AppName, AppTitle: string; register: boolean);
const
   RegKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
   // or: RegKey = '\Software\Microsoft\Windows\CurrentVersion\RunOnce';
var
  Registry: TRegistry;
begin
  Registry := TRegistry.Create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKey(RegKey, False) then
    begin
      if register = false then
        Registry.DeleteValue(AppTitle)
      else
        Registry.WriteString(AppTitle, AppName);
    end;
  finally
    Registry.CloseKey;
    Registry.Free;
  end;
end;


// Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  // 1.Parameter: Path to your Exe-File
  // 2. Parameter: the Title of your Application
  // 3. Set (true) or Unset (false) Autorun
  SetAutoStart(ParamStr(0),'Title of your Application',true);

end;

2) Have a look at
http://www.advdelphisys.com/Code_Lib/ads_File.html#File_DirOperations_Detail
0
 

Author Comment

by:sophiesas
ID: 6265139
Thank you but how can i delete the key that we added to registry?? (For not open at startup)
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6265149
Hi.

// Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
 // 1.Parameter: Path to your Exe-File
 // 2. Parameter: the Title of your Application
 // 3. Set (true) or Unset (false) Autorun
 SetAutoStart(ParamStr(0),'Title of your Application',true); //Just put in False instead of True


Dennis
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sophiesas
ID: 6265171
tasomia your code gives this error : (iam newbie)
Undeclared identifier : SetAutoStart

how can i declare it and also i can't add parameters on Button1Click can you give this programs complete source code??

Thanks
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6265185
1)

Uses
  Registry;

procedure SetAutoStart(AppName, AppTitle: string; register: boolean);
const
   RegKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
   // or: RegKey = '\Software\Microsoft\Windows\CurrentVersion\RunOnce';
var
  Registry: TRegistry;
begin
  Registry := TRegistry.Create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKey(RegKey, False) then
    begin
      if register = false then
        Registry.DeleteValue(AppTitle)
      else
        Registry.WriteString(AppTitle, AppName);
    end;
  finally
    Registry.CloseKey;
    Registry.Free;
  end;
end;


// Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  // 1.Parameter: Path to your Exe-File
  // 2. Parameter: the Title of your Application
  // 3. Set (true) or Unset (false) Autorun
  SetAutoStart(ParamStr(0),'Title of your Application',true);

end;

2) Have a look at
http://www.advdelphisys.com/Code_Lib/ads_File.html#File_DirOperations_Detail
0
 

Author Comment

by:sophiesas
ID: 6265197
Also i can't copy dirs with the source above please give examples...
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6265332
Procedure CopyDir(fromDir, toDir : String);
var
 fileOp: TShFileOpStruct;
begin
 FillChar(fileOp, Sizeof(TShFileOpStruct), 0);
 fromDir := fromDir + '\*.*'#0;
 toDir := toDir + #0;
 with fileOp do begin
   wnd := Application.Handle;
   wfunc := FO_COPY;
   pFrom := PChar(fromDir);
   pTo := PChar(toDir);
   fFlags := FOF_ALLOWUNDO;
   fAnyOperationsAborted := false;
   hNameMappings := nil;
   lpszProgressTitle := nil;
 end;
 SHFileOperation(fileOp);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 CopyDir('c:\test1','d:\test2');
end;
0
 

Author Comment

by:sophiesas
ID: 6265341
It says Undeclared Identifier Copy Dir When i try to call procedure from Button1. Can you also give an example to startup?
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6265474
Include ShellApi in your Uses-Clause.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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