PageRenderTime 9ms CodeModel.GetById 8ms app.highlight 0ms RepoModel.GetById 0ms app.codeStats 0ms

/jcl/examples/windows/asuser/CreateProcAsUserDemoMain.pas

https://github.com/the-Arioch/jcl
Pascal | 93 lines | 78 code | 14 blank | 1 comment | 5 complexity | 66931b65e172eee615b20f5f1abffa6f MD5 | raw file
Possible License(s): BSD-3-Clause
 1unit CreateProcAsUserDemoMain;
 2
 3interface
 4
 5uses
 6  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 7  StdCtrls;
 8
 9type
10  TForm1 = class(TForm)
11    edtDomain: TEdit;
12    Label1: TLabel;
13    edtUserName: TEdit;
14    Label2: TLabel;
15    edtPassword: TEdit;
16    Label3: TLabel;
17    edtCommandLine: TEdit;
18    Label4: TLabel;
19    btnCreateProcAsUser: TButton;
20    btnCreateProcAsUserEx: TButton;
21    lbEnvironment: TListBox;
22    Label5: TLabel;
23    edtEnvString: TEdit;
24    btnAddEnvString: TButton;
25    btnRemoveEnvString: TButton;
26    btnClearEnvStrings: TButton;
27    chkEnvAdditional: TCheckBox;
28    chkEnvCurrentUser: TCheckBox;
29    chkEnvLocalMachine: TCheckBox;
30    procedure btnAddEnvStringClick(Sender: TObject);
31    procedure btnClearEnvStringsClick(Sender: TObject);
32    procedure btnRemoveEnvStringClick(Sender: TObject);
33    procedure btnCreateProcAsUserClick(Sender: TObject);
34    procedure btnCreateProcAsUserExClick(Sender: TObject);
35  private
36  public
37  end;
38
39var
40  Form1: TForm1;
41
42implementation
43
44uses
45  JclMiscel, JclStrings, JclSysInfo;
46
47{$R *.dfm}
48
49procedure TForm1.btnAddEnvStringClick(Sender: TObject);
50begin
51  lbEnvironment.Items.Add(edtEnvString.Text);
52end;
53
54procedure TForm1.btnClearEnvStringsClick(Sender: TObject);
55begin
56  lbEnvironment.Items.Clear;
57end;
58
59procedure TForm1.btnRemoveEnvStringClick(Sender: TObject);
60var
61  I: Integer;
62begin
63  for I := lbEnvironment.Items.Count - 1 downto 0 do
64    if lbEnvironment.Selected[I] then
65      lbEnvironment.Items.Delete(I);
66end;
67
68procedure TForm1.btnCreateProcAsUserClick(Sender: TObject);
69begin
70  CreateProcAsUser(edtDomain.Text, edtUserName.Text,
71    edtPassWord.Text, edtCommandline.Text);
72end;
73
74procedure TForm1.btnCreateProcAsUserExClick(Sender: TObject);
75var
76  Env: PChar;
77  EnvOptions: TEnvironmentOptions;
78begin
79  EnvOptions := [];
80  if chkEnvAdditional.Checked then
81    EnvOptions := EnvOptions + [eoAdditional];
82  if chkEnvCurrentUser.Checked then
83    EnvOptions := EnvOptions + [eoCurrentUser];
84  if chkEnvLocalMachine.Checked then
85    EnvOptions := EnvOptions + [eoLocalMachine];
86
87  Env := CreateEnvironmentBlock(EnvOptions, lbEnvironment.Items);
88  CreateProcAsUserEx(edtDomain.Text, edtUserName.Text,
89    edtPassWord.Text, edtCommandline.Text, Env);
90  DestroyEnvironmentBlock(Env);
91end;
92
93end.