Главная страница
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.02 c
14-2273
Kviz
2004-01-07 14:44
2004.02.02
Вот собрался новый мониторчик ЖК брать, прошу помощи.


3-1971
Veetoyk
2004-01-10 13:07
2004.02.02
Объясните пожалуйста, ......


1-2106
killer
2004-01-18 00:33
2004.02.02
Ярлык около кнопки


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


1-2074
T__Alex
2004-01-20 12:56
2004.02.02
Как програмно определить кодировку текст. файла