Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Run As system (https://www.delphipraxis.net/171715-run-system.html)

sdean 21. Nov 2012 12:55

Run As system
 
Hello i've this code to launch an external Application as a system :
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  StartupInfo: TStartupInfoW;
  ProcessInformation: TProcessInformation;
begin
  ZeroMemory(@StartupInfo, SizeOf(TStartupInfoW));
  FillChar(StartupInfo, SizeOf(TStartupInfoW), 0);
  StartupInfo.cb := SizeOf(TStartupInfoW);
  StartupInfo.lpDesktop := 'WinSta0\Default';
  if CreateProcessAsSystemW(
    PWideChar(WideString(Edit1.Text)),
    PWideChar(WideString(Edit1.Text + ' -hi')),
    NORMAL_PRIORITY_CLASS,
    nil,
    nil,
    StartupInfo,
    ProcessInformation,
    SystemIntegrityLevel) then
  begin
    CloseHandle(ProcessInformation.hThread);
    CloseHandle(ProcessInformation.hProcess);
  end;
end;
my question is : how can i launch my application as a system , that's to say how to launch the application itself as a system instead of launching an external application .

many thanks

jaenicke 21. Nov 2012 14:36

AW: Run As system
 
:gruebel:
By putting your application executable in as command instead of Edit1.Text? (
Delphi-Quellcode:
ParamStr(0)
)

sdean 21. Nov 2012 14:52

AW: Run As system
 
Zitat:

Zitat von jaenicke (Beitrag 1192225)
:gruebel:
By putting your application executable in as command instead of Edit1.Text? (
Delphi-Quellcode:
ParamStr(0)
)

thank you , but what i meant is should i put it in the project.dpr if yes then should delete

Delphi-Quellcode:
Application.Initialize
thank you again

jaenicke 21. Nov 2012 15:21

AW: Run As system
 
You can not give your running executable system access rights. You can only start a new instance of your executeble with those rights. And you could do so inside your project file if you want to.

But if you need to run in system context, why don't you just write a service application?

sdean 21. Nov 2012 15:31

AW: Run As system
 
Zitat:

Zitat von jaenicke (Beitrag 1192228)
You can not give your running executable system access rights. You can only start a new instance of your executeble with those rights. And you could do so inside your project file if you want to.

is that mean my application will have 2 different PIDs ?

jaenicke 21. Nov 2012 16:19

AW: Run As system
 
The first instance can be closed, so only the second remains. But yes, your second instance will have a new PID and will be running separately from the first.

There is no other possibility.


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:59 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz