Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.09.24;
Скачать: CL | DM;

Вниз

Запуск приложения от имени Администратора   Найти похожие ветки 

 
Stanislav ©   (2006-05-23 13:16) [0]

Подскажите можно ли запустить приложение от имени Администратора, хотя компьютер запущен аод другим пользователем, а так же чтобы процесс этого приложения пользователь не мог завершить ?
Пароль и логин администратора известны.


 
Eraser ©   (2006-05-23 13:23) [1]


> Stanislav ©   (23.05.06 13:16)

смотрите функцию CreateProcessAsUser.


 
Игорь Шевченко ©   (2006-05-23 13:34) [2]

или CreateProcessWithLogonW
или просто runas


 
Stanislav ©   (2006-05-23 13:50) [3]

Спасибо!


 
Stanislav ©   (2006-05-23 13:53) [4]

Игорь Шевченко ©
Runas это где?


 
Stanislav ©   (2006-05-23 13:55) [5]

Спасибо разобрался!


 
Stanislav ©   (2006-05-23 15:14) [6]

Делаю так:
if LogonUser ("login","domain","pasword",LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,h) then
if not
CreateProcessAsUser(h, nil, PChar(cmdline), sa,nil,false,0,nil,nil,si,pi)
then ShowMessage ("Ошибка!")
Выдает ошибку
хотя
CreateProcess (nil, PChar(cmdline), sa,nil,false,0,nil,nil,si,pi)
Работает, почему?


 
Игорь Шевченко ©   (2006-05-23 15:25) [7]

А что выдает GetLastError ?


 
Stanislav ©   (2006-05-23 15:33) [8]

Выдает 0


 
Игорь Шевченко ©   (2006-05-23 15:45) [9]


> Выдает 0


if not CreateProcessAsUser (...) then
 ShowMessage(SysErrorMessage(GetLastError))


 
Stanislav ©   (2006-05-23 16:09) [10]

Тип маркера не соответствует выполняемой операции


 
Игорь Шевченко ©   (2006-05-23 16:12) [11]

Stanislav ©   (23.05.06 16:09) [10]

Попробуй CreateProcessWithLogonW, он сам маркер нужный делает


 
Stanislav ©   (2006-05-23 16:32) [12]

А где эта функция  (CreateProcessWithLogonW) ?


 
BiN ©   (2006-05-23 16:35) [13]


> Stanislav ©   (23.05.06 16:09) [10]
>
> Тип маркера не соответствует выполняемой операции


LOGON32_LOGON_NETWORK замени на LOGON32_LOGON_INTERACTIVE.

или же прислушайся к совету:

> Игорь Шевченко ©   (23.05.06 16:12) [11]
>
> Stanislav ©   (23.05.06 16:09) [10]
>
> Попробуй CreateProcessWithLogonW, он сам маркер нужный делает


CreateProcessWithLogonW также избавляет от необходимости корректировки DACL-a десктопа при создании процесса с окнами.


 
Игорь Шевченко ©   (2006-05-23 16:41) [14]


> А где эта функция  (CreateProcessWithLogonW) ?


В advapi32.dll


 
Stanislav ©   (2006-05-23 17:27) [15]

Игорь Шевченко ©   (23.05.06 16:41) [14]
Понял спасибо, а она есть в делфийском модуле или напрямую из Dll нужно вызывать, если напрямую где можно почитать описание параметров?


 
Игорь Шевченко ©   (2006-05-23 17:36) [16]

unit main;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TfMain = class(TForm)
   Button: TButton;
   procedure ButtonClick(Sender: TObject);
 end;

var
 fMain: TfMain;

implementation
uses
 HSAdvApi;

{$R *.dfm}

procedure TfMain.ButtonClick(Sender: TObject);
begin
 MyCreateProcess();
end;

procedure TfMain.MyCreateProcess;
const
 UserName : WideString = "TESTUSER";
 Password : WideString = "testuser";
 ConstCommandLine : String = "CMD.EXE";
 Title : WideString = "Test process";
 Domain : WideString = "WORKGROUP";
var
 MyStartupInfo : STARTUPINFO;
 ProcessInfo : PROCESS_INFORMATION;
 CommandLine : array[0..512] of WideChar;
begin
 FillChar(MyStartupInfo, SizeOf(MyStartupInfo), 0);
 MyStartupInfo.cb := SizeOf(MyStartupInfo);
 StringToWideChar(ConstCommandLine, CommandLine,
    Sizeof(CommandLine) div SizeOf(WideChar));
 MyStartupInfo.lpTitle := PWideChar(Title);
 if not CreateProcessWithLogonW (PWideChar(UserName), PWideChar(Domain),
     PWideChar(Password), LOGON_WITH_PROFILE, nil,
     CommandLine, 0, nil, nil, @MyStartupInfo, @ProcessInfo) then
   RaiseLastWin32Error()
 else begin
   CloseHandle(ProcessInfo.hProcess);
   CloseHandle(ProcessInfo.hThread);
 end;
end;

end.


unit HSAdvApi;

interface
uses
 Windows;

function CreateProcessWithLogonW (const lpUsername : PWideChar;
 const lpDomain : PWideChar; const lpPassword : PWideChar;
 dwLogonFlags : DWORD; const lpApplicationName : PWideChar;
 lpCommandLine : PWideChar; dwCreationFlags : DWORD;
 lpEnvironment : Pointer; const lpCurrentDirectory : PWideChar;
 lpStartupInfo : PStartupInfo;
 lpProcessInfo : PProcessInformation) : Boolean; stdcall;

const
 LOGON_WITH_PROFILE = $00000001;
 LOGON_NETCREDENTIALS_ONLY = $00000002;
 LOGON_ZERO_PASSWORD_BUFFER = $80000000;

implementation
uses
 SysUtils;

{ ADVAPI32.DLL functions }
type
 TCreateProcessWithLogonW =
   function (const lpUsername : PWideChar;
 const lpDomain : PWideChar; const lpPassword : PWideChar;
 dwLogonFlags : DWORD; const lpApplicationName : PWideChar;
 lpCommandLine : PWideChar; dwCreationFlags : DWORD;
 lpEnvironment : Pointer; const lpCurrentDirectory : PWideChar;
 lpStartupInfo : PStartupInfo;
 lpProcessInfo : PProcessInformation) : Boolean; stdcall;

const
 DllName = "advapi32.dll";

var
 DllHandle : THandle;
 _CreateProcessWithLogonW : TCreateProcessWithLogonW;

function InitLib : Boolean;
begin
 if DllHandle = 0 then
   if Win32Platform = VER_PLATFORM_WIN32_NT then begin
     DllHandle := LoadLibrary(DllName);
     if DllHandle <> 0 then begin
       @_CreateProcessWithLogonW := GetProcAddress(DllHandle,
         "CreateProcessWithLogonW");
     end;
   end;
 Result := (DllHandle <> 0);
end;

function NotImplementedBool : Boolean;
begin
 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
 Result := false;
end;

function CreateProcessWithLogonW (const lpUsername : PWideChar;
 const lpDomain : PWideChar; const lpPassword : PWideChar;
 dwLogonFlags : DWORD; const lpApplicationName : PWideChar;
 lpCommandLine : PWideChar; dwCreationFlags : DWORD;
 lpEnvironment : Pointer; const lpCurrentDirectory : PWideChar;
 lpStartupInfo : PStartupInfo;
 lpProcessInfo : PProcessInformation) : Boolean; stdcall;
begin
 if InitLib and Assigned(_CreateProcessWithLogonW) then
   Result := _CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword,
     dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags,
     lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInfo)
 else
   Result := NotImplementedBool;
end;

initialization
finalization
 if DllHandle <> 0 then
   FreeLibrary(DllHandle);
end.


 
Stanislav ©   (2006-05-24 10:45) [17]

Спасибо!


 
Stanislav ©   (2006-05-24 10:55) [18]

Все работает СПАСИБО!!!



Страницы: 1 вся ветка

Текущий архив: 2006.09.24;
Скачать: CL | DM;

Наверх




Память: 0.51 MB
Время: 0.029 c
15-1157185940
мнм
2006-09-02 12:32
2006.09.24
программист <> кодер


15-1157577798
не ББаба
2006-09-07 01:23
2006.09.24
Закрыть тему Прочее(Потрепаться)


1-1155282476
Zilog_
2006-08-11 11:47
2006.09.24
Ребята помогите разобраться с переводом с С++ в Делфи


8-1141738221
Vitaly73
2006-03-07 16:30
2006.09.24
mp3-проигрыватель


15-1157493318
Palladin
2006-09-06 01:55
2006.09.24
Гэндальф