Skip to main content

Add and Remove Startup Dephi

Technique how to put our application and other applications on the Windows start-up in the registry and startup folder directory.
Function declaration:uses
  
Registry, ActiveX, ShlObj, ComObj;
const
  
CURRENT_USER = 1;
  
ALL_USERS = 2;
  
keyReg = 'Software \ Microsoft \ Windows \ CurrentVersion \ Run';
  
ShellFolder = 'Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders';
  
strPath = "\ Start Menu \ Programs \ Startup \ ';
/ / Function to read environment variables to WindowsEnvVar function (const v: string): string;var
  
c: array [0 .. 1023] of Char;begin
  
if ExpandEnvironmentStrings (PChar (v), c, 1024) = 0 then
  
Result: = v
  
else Result: = Trim (c);end;
/ / Function to create a ShortcutCreateShortCut function (const FromFile: String; dest: widestring): Boolean;var
  
MOBJAX: IUnknown;
  
MSHLink: IShellLink;
  
MPRFile: IPersistFile;
  
HRes: HRESULT;begin
  
MOBJAX: = CreateCOMObject (CLSID_ShellLink);
  
MSHLink: = MOBJAX as IShellLink;
  
MPRFile: = MOBJAX as IPersistFile;
  
with MSHLink do
  
begin
    
SetPath (PChar (FromFile));
    
SetRelativePath (PChar (ExtractFilePath (FromFile)), 0);
    
SetWorkingDirectory (PChar (ExtractFilePath (FromFile)));
    
SetIconLocation (PChar (FromFile), 0);
  
end;
  
HRes: = MPRFile.Save (PWChar (dest), False);
  
if HRes = S_OK then Result: = True else Result: = False;end;
/ / Function to read the location of the startup directory (slightly forcing functions)StartupFolderDir function (const tStartup: Byte): String;var
  
tmpKey, tmpEnv, tmpPath: String;
  
tmpRoot: HKEY;begin
  
Result: ='';
  
if tStartup = CURRENT_USER then
  
begin
    
tmpKey: = 'startup';
    
tmpRoot: = HKEY_CURRENT_USER;
    
tmpEnv: = '% UserProfile%';
  
end
  
else
  
begin
    
tmpKey: = 'Common Startup';
    
tmpRoot: = HKEY_LOCAL_MACHINE;
    
tmpEnv: = '% AllUsersProfile%';
  
end;
  
with TRegistry.Create (KEY_READ) do
  
begin
    
try
      
RootKey: = tmpRoot;
      
if OpenKey (ShellFolder, False) then
      
begin
        
if ValueExists (tmpKey) then tmpPath: = ReadString (tmpKey);
      
end;
    
finally
      
Free;
    
end;
  
end;
  
if Trim (tmpPath) =''then tmpPath: = EnvVar (tmpEnv) + strPath;
  
Result: = IncludeTrailingBackSlash (tmpPath);end;
ToStartupRegistry procedure (const IDApp, exefile: String; tStartup: Byte);var
  
rk: HKEY;begin
  
with TRegistry.Create do
  
begin
    
if tStartup = CURRENT_USER then
      
rk: = HKEY_CURRENT_USER
    
else
      
rk: = HKEY_LOCAL_MACHINE;
    
try
      
RootKey: = rk;
      
OpenKey (keyReg, True);
      
WriteString (IDApp, exefile);
    
finally
      
Free;
    
end;
  
end;end;
RemStartupRegistry procedure (const IDApp: String; tStartup: Byte);var
  
rk: HKEY;begin
  
with TRegistry.Create do
  
begin
    
if tStartup = CURRENT_USER then
      
rk: = HKEY_CURRENT_USER
    
else
      
rk: = HKEY_LOCAL_MACHINE;
    
try
      
RootKey: = rk;
      
if OpenKey (keyReg, False) then
        
if ValueExists (IDApp) then DeleteValue (IDApp);
    
finally
      
Free;
    
end;
  
end;end;
ToStartupFolder procedure (const IDApp, exefile: String; tStartup: Byte);begin
  
CreateShortcut (exefile, StartupFolderDir (tStartup) + + IDApp. 'Lnk');end;
RemStartupFolder procedure (const IDApp: String; tStartup: Byte);var
  
F: String;begin
  
F: = StartupFolderDir (tStartup) + + IDApp '. Lnk';
  
if FileExists (F) then DeleteFile (F);end;
If you want to access start-ups in the current user, fill in the parameters and ALL_USERS CURRENT_USER tStartup with start-ups for all users.
Example of implementation:/ / To Startup in the registry/ / Add to ...ToStartupRegistry ('myapp', Application.ExeName, ALL_USERS);/ / RemoveRemStartupRegistry ('myapp', ALL_USERS);
/ / For the Startup folder on Startup/ / Add to ...ToStartupFolder ('myapp', Application.ExeName, ALL_USERS);/ / RemoveRemStartupFolder ('myapp', ALL_USERS);

Popular posts from this blog

Login Form Delphi by Connecting to Ms Access Database.

this the step by step  to making application :

Login Form Delphi by Connecting Ms Access Database.

In making/ building application in Delphi, login Form is an important to protect application so that cannot be open by irresponsible person. This login Form is connected with database so that able to keep a lot of username data and password. Before make the application, please create a database as the picture below:
Picture :Login  form Delphi database Microsoft Access
Save the database in the folder which use to save the application


Next step is create the application

Enter the component and the source code as follows.


No Component NameProperties Value1Label1CaptionUsername2Label2CaptionPassword3Edit1Text -4Edit2Text -5Button1CaptionLogin6Adoconnection1--7AdoQuery1ConnectionADOConnection1

Arrange the component as the picture below:


Figure. Login Form Delphi design form



 Create new form



Form properties can be check in the table below
No Component NameProperties Value1Form1CaptionSuccess…

Step by step Accessing SMS With Delphi: Sending SMS Using Borland Delphi 7 Exploit Comport Component (Siemens))

In this example, will present the way how making SMS delivery program with Delphi, basically, data in data communication series between Delphi and mobile phone happen in Format Protocol Data Unit (PDU). The destination number of sending Message and message that will be sent through Delphi program that is made have to be changed into PDU Form first, next is the data will be sent through serial port to mobile phone. To make the send SMS Application , please enter the following component to Form 1.

No Component NameProperties ValueButton1CaptionConnectButton2CaptionDisConnectButton3CaptionConvert to PDUButton4CaptionSend to HPButton5CaptionClearButton6CaptionStart Send SMSButton7CaptionSet PortEdit1Text-Edit2Text<Type The SMS here>Edit3Text-Label1Caption1) Destination Number :Label2Caption2Label3CaptionPDU lengthLabel4CaptionLabel lengthComLed1--Memo1--Memo2--Comport1--Arrange the Component  in such away so that the visualization program is as follows:


Then type the follow…

The Example Using Chart In Borland Delphi 7

The Example Using Chart In Borland Delphi 7




In this writing will discuss about how to use the chart in Delphi 7. In the example that is made by using Delphi 7, chart will appear 2 data in the form of incremental data number, the first data named data 1 and the second data named data 2. Data 1 is incremental data 1 that is begun from 0 until 10; while data 2 is same. Yet, in the beginning condition of data 1 start from 0 while data 2 start from 1.


To make application as the explanation above, please enter the components in the table below into design form.


NoComponentPropertiesValueNote1Form1CaptionThe Chart of Data on Delphi 72GroupBox1CaptionThe Chart of Data on Delphi 73Label1CaptionData 14Label2CaptionData 25Edit1Text06Edit2Text07Button1CaptionShow to Chart8Button2CaptionClose9Timer1EnabledFalse10Chart--Check the NoteNote:

Double click on chart component, set the property of chart as below:


Click on  Add.. Button

Then the following chart gallery will be shown:



Choose the…