Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2006.09.24;
Скачать: [xml.tar.bz2];

Вниз

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

 
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 вся ветка

Форум: "WinAPI";
Текущий архив: 2006.09.24;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.037 c
2-1157217824
olevacho_
2006-09-02 21:23
2006.09.24
ввод пароля


2-1157627610
lessard
2006-09-07 15:13
2006.09.24
Определить содержимое variant


5-1139839358
Святослав
2006-02-13 17:02
2006.09.24
Как запустить процедуру после установки Parent?


15-1157461067
memo
2006-09-05 16:57
2006.09.24
Разница дат....


15-1157172791
tButton
2006-09-02 08:53
2006.09.24
поймал момент)





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский