Home > Back-end >  What code can install the software automatically
What code can install the software automatically

Time:10-07

Such as automatic installation qq2013, give a piece of code, heard that need wait functions,

CodePudding user response:

If silent installation is to be clear is the installer what register the DLL, changed what key values, released what document, write their own code instead of the line,

CodePudding user response:

General installation point details can see these information,

CodePudding user response:

Give a DELPHI code

CodePudding user response:

Thinking: 1, create a virtual desktop
2, write a automatically open the installer, and the next step to complete the procedure, next to operate according to handle click
3, in the virtual desktop to run programs written in step 2

Sample code below, note the following code is not I write, I realized automatic installation,
OpenDesktop//access to handle to the desktop

SwitchDesktop//activate/go to the specified desktop

Globaladdatom//to create global atom

Globalfindatom//find global atom

Globaldeleteatom//delete global atom

Getasynckeystate//judge the state of the virtual keys

CreateProcess//open the specified process

GetCurrentThreadId//get the current ID

GetThreadDesktop//get the current desktop handle

Ok that's it, below I said the process

Just watching the information on the net, it feels like as long as CreateDesktop to create the desktop using SwitchDesktop to turn again to the specified desktop, but things are not so simple. Create a virtual desktop, after I input the SwitchDesktop function into the program button events, I press the button, I cried happens -- -- -- -- -- - go to the desktop clean nothing, no desktop icon no task bar or even can't open the task manager, can't, tearful press reset button on the computer (thousands of? 555).

I continue to find information on the Internet and found that should be displayed in the newly created the desktop icon, you must first create desktop on the new open desktop process explorer. Exe (general ask we end off this process under the desktop will disappear) that is the reason why, now use the CreateProcess function, how the CreateProcess function can create process in other desktop? CreateProcess a TStartupInfo structure parameters, the structure of a certain lpDesktop member, which specifies the create process in which the desktop (not the assignment for the current desktop), please have a look at the code:

Var sin: TStartupInfo; S: a string;

Sin. Cb:=sizeof (sin);
Sin. WShowWindow:=SW_SHOW;
Sin. DwFlags:=STARTF_USESHOWWINDOW;

S:='a';
Sin. LpDesktop:=pchar (s);

CreateProcess (' c: \ WINDOWS \ explorer exe, nil, nil, nil, False, 0, nil, nil, sin, pin);

Among them the names of the characters to create a desktop, the name specified in the create desktop function.

The next question is transferred to the new desktop, after their own programs to run out of his sight, how to turn back to the original desktop? I used a foolish way, while creating a new desktop and in the process of new desktop in new desktop will open again this procedure, so in fact created a few new desktop application itself will run several instances, see code:

CreateProcess (pchar (extractfilepath (application. ExeName) + 'here is the name of the program), nil, nil, nil, False, 0, nil, nil, sin, pin);

To this line of code in the process of creating a desktop, this problem was solved, a wave of open something new creates a problem, but also two serious problems:

1, I create a desktop code is written in the form in the process of loading, that means that each create a instance itself is more N virtual desktop,

2, the newly created instance processes can not be the first instance to save the handle, which makes it impossible to the desktop,

To the first question I is to use global atom method to solve, the program is started to use globalfindatom find global atom, if do not commend in said not running process instance, then create a global atoms and create virtual desktop, if any, instead of creating virtual desktops, but still want to create a global atoms (the reason I don't need to tell!), in the form of the exit code and don't forget to globaldeleteatom off to create global atom,

For your second question, namely however cannot inherit from already handle to find it; Said earlier when creating virtual desktop to create desktop assigned a name, now show the name of the function, the OpenDesktop function is one of the parameters for the desktop name, the function of the return value is the handle to the desktop, the newly created virtual desktop can use this method to obtain handle, but how to get the default desktop? This is more simple, because the default desktop name is "default", as long as the characters in the OpenDesktop function can easily handle to get the default desktop, in the handle, as long as using SwitchDesktop parameter is the handle to the desktop () function can be turned to the specified desktop,

PS: the name of the default desktop I began to also don't know, but I accidentally found a function on the Internet: getuserobjectinformation, this function can be obtained according to the handle to the desktop desktop, the name of the handle to the desktop can use GetThreadDesktop and GetCurrentThreadId () to obtain, GetCurrentThreadId () function is to get the current ID, this ID as the parameter used to retrieve the current desktop GetThreadDesktop handle, so it got the name of the desktop

Not much said attach my source code:

 
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ExtCtrls;

Type
TForm1=class (TForm)
For: TButton;
Button2: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Timer1: TTimer;
Timer2: TTimer;
Procedure Button1Click (Sender: TObject);
Procedure FormCreate (Sender: TObject);
Procedure Button2Click (Sender: TObject);
Procedure Button4Click (Sender: TObject);
Procedure Button5Click (Sender: TObject);
Procedure Button6Click (Sender: TObject);
Procedure Button7Click (Sender: TObject);
Procedure Timer1Timer (Sender: TObject);
Procedure FormDestroy (Sender: TObject);
Procedure Timer2Timer (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;
H1: thandle;
H2: thandle;
H3: thandle;
H4: thandle;
H5: thandle;
H6: thandle;
Si: TStartupInfo;
Sin: TStartupInfo;
Pin: TProcessInformation;
S: a string;
Desk: thandle;
Implementation

{$R *. DFM}
Procedure TForm1. FormCreate (Sender: TObject);//create a desktop
The begin
Timer1. Interval:=50;
Timer2. Interval:=1000;
Sin. Cb:=sizeof (sin);
Sin. WShowWindow:=SW_SHOW;
Sin. DwFlags:=STARTF_USESHOWWINDOW;

If globalfindatom (' MFK ')=0 then
The begin
Globaladdatom (' MFK ');
H1:=GetThreadDesktop (GetCurrentThreadId ());

S:='a';
Sin. LpDesktop:=pchar (s);
H2:=CreateDesktop (pchar (s), nil, nil, DF_ALLOWOTHERACCOUNTHOOK, GENERIC_ALL, nil);
CreateProcess (' c: \ WINDOWS \ explorer exe, nil, nil, nil, False, 0, nil, nil, sin, pin);
CreateProcess (pchar (extractfilepath (application. ExeName) + 'double open tools. Exe'), nil, nil, nil, False, 0, nil, nil, sin, pin);

S:='b';
Sin. LpDesktop:=pchar (s);
H3:=CreateDesktop (' b ', nil nil, 0, MAXIMUM_ALLOWED, nil);
CreateProcess (' c: \ WINDOWS \ explorer exe, nil, nil, nil, False, 0, nil, nil, sin, pin);
CreateProcess (pchar (extractfilepath (application. ExeName) + 'double open tools. Exe'), nil, nil, nil, False, 0, nil, nil, sin, pin);

S:='c';
Sin. LpDesktop:=pchar (s);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related