Вниз
Скачать: 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
14-2355
Can_kill
2004-01-10 05:31
2004.02.02
Паскаль


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


3-1997
Innokenty
2004-01-08 10:03
2004.02.02
База в access и поля Дата/Время. Проблема.


14-2351
Nick-From
2004-01-09 11:31
2004.02.02
Вред от компа людям, болеющим онкологическим заболеванием


3-1953
sergg
2004-01-08 22:14
2004.02.02
Помогите создать SQL-запрос, заменяющий индексы




   Наверх