Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.02.02;
Скачать: 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 вся ветка

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

Наверх




Память: 0.47 MB
Время: 0.016 c
1-2072
Bers01
2004-01-20 11:49
2004.02.02
Работа с MSWord


1-2104
mixa
2004-01-19 19:41
2004.02.02
Очень быстрый цикл.


3-2037
Bolek
2004-01-09 17:39
2004.02.02
Доступ к данным


1-2060
SayreX
2004-01-19 20:04
2004.02.02
Inno Setup 3 HELP!


3-1998
SerKom
2004-01-08 05:39
2004.02.02
Как считать