Solved

startup and copy dirs

Posted on 2001-07-09
9
153 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 127
Delphi application Soap connection 5 96
Controlled Assessment GCSE - desperate help needed 4 76
Delphi and Access based Enumeration 9 48
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

24 Experts available now in Live!

Get 1:1 Help Now