Вниз
Скачать: CL | DM;

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

 
Doomin   (2003-11-25 15:55) [0]

Есть программа на Дельфи, которая использует базу. Клиент хочет, чтобы оператор не мог унести базу на диске. Система Windows XP. Для реализации решил использовать имперсонацию на основе функции CreateProcessWithLogonW. Почитал MSDN, написал модуль:


unit ProcessWithLogon;

interface

uses Windows, SysUtils;

const
LOGON_WITH_PROFILE = $1;
LOGON_NETCREDENTIALS_ONLY = $2;

function CreateProcessWithLogonW(
UserName,
Domain,
Password: PChar;
dwLogonFlags: DWORD;
lpApplicationName,
lpCommandLine: PChar;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: PChar;
const lpStartupInfo: TStartupInfo;
var lpProcessInformation: TProcessInformation): BOOL; stdcall;

function StrToPChar(const InStr: String): PAnsiChar;

function StartProcessWithLogon(
const strUsername, //


 
Игорь Шевченко ©   (2003-11-25 16:21) [1]

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.


Все дело в WideChar


 
Doomin   (2003-11-25 17:54) [2]

Спасибо большое! Заработало!



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

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.015 c
1-2197
snake1977
2004-01-20 15:09
2004.02.02
TDataBase в DLL


1-2085
Игорь
2004-01-20 12:01
2004.02.02
WaitForSingleObject( pi.hProcess, INFINITE )?


3-2017
Ермек
2004-01-06 17:57
2004.02.02
помогите с генератором


3-1956
ish
2004-01-09 16:07
2004.02.02
SQL Query


14-2315
goga
2004-01-11 18:40
2004.02.02
Я бы добавил в FAQ следующее.




   Наверх