Autor Beitrag
Nano-Ware
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: Do 20.10.11 23:17 
Hey,

ich schreibe derzeit ein Programm, dass generell ohne Adminrechte läuft, aber bei bestimmter Benutzereingabe, soll der Benutzer per UAC gefragt werden ob mein Programm Adminrechte bekommen darf. Ich weis, dass es nicht möglich ist, nachträglich für eine Anwendung diese Rechte einzufordern, daher suche ich Alternative, um das Problem trotzdem zu lösen. Eine zweite Anwendung möchte ich nicht mitliefern. Habt ihr eventuell Ideen?

Danke!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 21.10.11 06:04 
Ich starte dafür einfach die eigene Anwendung mit entsprechenden Parametern erneut. Um nicht jede Einzelaktion bestätigen zu müssen, lasse ich manchmal die zweite Anwendung auch offen und gebe per IPC weitere Befehle weiter. Zum Beispiel in diesem Quelltext:
www.delphi-forum.de/...?t=94339&start=0

Eine etwas kompliziertere Variante wäre ein out-of-process COM Server. Aber auch dafür gibt es einiges im Netz:
www.sourcecodeonline...ess_made_simple.html
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Fr 21.10.11 06:09 
ich hatte diesen Code vor einiger Zeit im Netz gefunden .....

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
procedure ExecuteNewInstance(AExplicitAdmin, AWait: Boolean; AWindow: THandle;
  AParams: string);
type
  TIsUserAnAdminFunc = function (): BOOL; stdcall;
var
  Shell32DLL: THandle;
  IsUserAnAdminFunc: TIsUserAnAdminFunc;
  AlreadyAdmin: Boolean;
  ExecuteInfo: SHELLEXECUTEINFO;
begin
  ExecuteInfo.cbSize := sizeof(SHELLEXECUTEINFO);
  ExecuteInfo.Wnd := AWindow;
  ExecuteInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
  AlreadyAdmin := False;
  Shell32DLL := LoadLibrary('shell32.dll');
  try
    if Shell32DLL <> 0 then
    begin
      @IsUserAnAdminFunc := GetProcAddress(Shell32DLL, 'IsUserAnAdmin');
      if Assigned(@IsUserAnAdminFunc) then
        AlreadyAdmin := IsUserAnAdminFunc();
    end;
  finally
    FreeLibrary(Shell32DLL);
  end;
  if AExplicitAdmin and not AlreadyAdmin then
    ExecuteInfo.lpVerb := 'runas'
  else
    ExecuteInfo.lpVerb := 'open';

  ExecuteInfo.lpFile := PChar(ParamStr(0));
  ExecuteInfo.lpParameters := PChar(AParams);
  ExecuteInfo.lpDirectory := PChar(ExtractFilePath(ParamStr(0)));
  ExecuteInfo.nShow := SW_SHOWNORMAL;

  if ShellExecuteEx(@ExecuteInfo) then
    try
      if AWait then
        WaitForSingleObject(ExecuteInfo.hProcess, INFINITE);
    finally
      CloseHandle(ExecuteInfo.hProcess);
    end;
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 21.10.11 10:12