Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Programm nur mit User-Rechten starten von Admin-Prozess

  Alt 3. Dez 2018, 18:14
Eventuell mit MSDN-Library durchsuchenCreateProcessWithLogon() oder MSDN-Library durchsuchenCreateProcessAsUser() methode realisierbar, ich habe es noch nicht versucht aber sollte man damit hinbekommen vermute ich.

/edit
Falls Du die Jedi verwendest, hier findest Du ein komplettes Beispiel.

Copy/Paste von dort falls Link tot geht.

Delphi-Quellcode:
uses
  ComObj, ActiveX, JwaWinbase, JwaWtsApi32;

{$R *.DFM}

procedure ServiceController(CtrlCode: DWORD); stdcall;
begin
  ServiceExample.Controller(CtrlCode);
end;

function TServiceExample.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TServiceExample.ServiceExecute(Sender: TService);
begin
  Timer1.Enabled := True;
  while not Terminated do
    ServiceThread.ProcessRequests(True); // wait for termination
  Timer1.Enabled := False;
end;

procedure TServiceExample.Timer1Timer(Sender: TObject);
const
  ProgramName = 'C:\myTestproject1.exe';
var
  hToken: THandle;
  StartupInfo: Windows.TStartupInfo;
  ProcessInfo: Windows.TProcessInformation;
  res: boolean;
begin
  Windows.GetStartupInfo(StartupInfo);
  if WTSQueryUserToken(WtsGetActiveConsoleSessionID, hToken) then
  begin
    res := Windows.CreateProcessAsUser(hToken, ProgramName, nil, nil, nil, False, CREATE_NEW_CONSOLE, nil, nil, StartupInfo, ProcessInfo);
    if res then
      WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
  end;
end;
Gruß vom KodeZwerg

Geändert von KodeZwerg ( 3. Dez 2018 um 19:19 Uhr)
  Mit Zitat antworten Zitat