[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

startup and copy dirs

Posted on 2001-07-09
9
Medium Priority
?
162 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
Industry Leaders: 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

650 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