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

Вниз

Как использовать CreateProcessAsUser?   Найти похожие ветки 

 
МАКСЮХА ©   (2004-02-18 16:18) [0]

Помогите разобраться в использовании CreateProcessAsUser.
Нужно запустить приложение в ХР из другой учетной записи


 
Cobalt ©   (2004-02-18 16:26) [1]

Справку читал? И...?
Рассказывай, что понял из справки/MSDN.
А мы тебе потом объясним, что ты понял неправильно.


 
Игорь Шевченко ©   (2004-02-18 18:08) [2]

Поиск, дружище, поиск...оно рулез.

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.


 
МАКСЮХА ©   (2004-02-18 18:35) [3]

Спасибо


 
МАКСЮХА ©   (2004-02-19 14:14) [4]

Это снова Я! С плохими новостями...
Проверил приведенный пример - НЕ Работает!!!

Win32 Error
Code 1326

Все ввожу правильно, но есть вопрос - что подразумеваеться под параметром lpDomain???


 
Игорь Шевченко ©   (2004-02-19 14:20) [5]

//  Logon failure: unknown user name or bad password.
//
#define ERROR_LOGON_FAILURE              1326L


> что подразумеваеться под параметром lpDomain???


Имя домена или рабочей группы, в которую входит пользователь.


 
МАКСЮХА ©   (2004-02-19 14:32) [6]


> Имя домена или рабочей группы, в которую входит пользователь.

Например?
Будем считать что комп к сети не подключен, никаких сетевых роб. групп нет.
Тогда как определить этот параметр, может по имени компьютера?
Это я уже пробовал, но ничего не выходит...


 
Игорь Шевченко ©   (2004-02-19 14:36) [7]

МАКСЮХА ©   (19.02.04 14:32)

Открой control panel, найди там Сеть и ткни на нее. Там будет написано имя компьютера и рабочая группа (раз к сети не подключен).

P.S. Пример этот изначально был написан в точно такой же ситуации (дома, без сети)



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

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

Наверх




Память: 0.49 MB
Время: 0.053 c
7-1077117818
XandeR
2004-02-18 18:23
2004.04.25
определить температуру процессора


3-1080537249
WondeRu
2004-03-29 09:14
2004.04.25
ADOConnection.ConnectionString


3-1080200885
avgur
2004-03-25 10:48
2004.04.25
Киньте, кому не жалко библиотеку netdir.dll по мылу


3-1080799942
race1
2004-04-01 10:12
2004.04.25
filter by date


3-1080213577
Domkrat
2004-03-25 14:19
2004.04.25
SQL