?
Solved

startup and copy dirs

Posted on 2001-07-09
9
Medium Priority
?
160 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 210 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

Technology Partners: 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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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