Solved

startup and copy dirs

Posted on 2001-07-09
9
152 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

17 Experts available now in Live!

Get 1:1 Help Now