![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Запуск приложения от имени Администратора [D7, WinXP]
Stanislav © (2006-05-23 13:16:00)Подскажите можно ли запустить приложение от имени Администратора, хотя компьютер запущен аод другим пользователем, а так же чтобы процесс этого приложения пользователь не мог завершить ?
Пароль и логин администратора известны.
Stanislav (2006-05-24 10:55:00) [1]Все работает СПАСИБО!!!
Stanislav (2006-05-24 10:45:00) [2]Спасибо!
Игорь Шевченко (2006-05-23 17:36:00) [3]
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-23 17:27:00) [4]Игорь Шевченко © (23.05.06 16:41) [14]
Понял спасибо, а она есть в делфийском модуле или напрямую из Dll нужно вызывать, если напрямую где можно почитать описание параметров?
Игорь Шевченко (2006-05-23 16:41:00) [5]
> А где эта функция (CreateProcessWithLogonW) ?
В advapi32.dll
BiN (2006-05-23 16:35:00) [6]
> 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 десктопа при создании процесса с окнами.
Stanislav (2006-05-23 16:32:00) [7]А где эта функция (CreateProcessWithLogonW) ?
Игорь Шевченко (2006-05-23 16:12:00) [8]Stanislav © (23.05.06 16:09) [10]
Попробуй CreateProcessWithLogonW, он сам маркер нужный делает
Stanislav (2006-05-23 16:09:00) [9]Тип маркера не соответствует выполняемой операции
Игорь Шевченко (2006-05-23 15:45:00) [10]
> Выдает 0
if not CreateProcessAsUser (...) then
ShowMessage(SysErrorMessage(GetLastError))
Stanislav (2006-05-23 15:33:00) [11]Выдает 0
Игорь Шевченко (2006-05-23 15:25:00) [12]А что выдает GetLastError ?
Stanislav (2006-05-23 15:14:00) [13]Делаю так:
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)
Работает, почему?
Stanislav (2006-05-23 13:55:00) [14]Спасибо разобрался!
Stanislav (2006-05-23 13:53:00) [15]Игорь Шевченко ©
Runas это где?
Stanislav (2006-05-23 13:50:00) [16]Спасибо!
Игорь Шевченко (2006-05-23 13:34:00) [17]или CreateProcessWithLogonW
или просто runas
Eraser (2006-05-23 13:23:00) [18]
> Stanislav © (23.05.06 13:16)
смотрите функцию CreateProcessAsUser.