
16.07.2012, 10:35
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
честный код:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
LOGON_WITH_PROFILE = $00000001;
LOGON_NETCREDENTIALS_ONLY = $00000002;
function CreateProcessWithLogonW(
lpUsername: LPCWSTR;
lpDomain: LPCWSTR;
lpPassword: LPCWSTR;
dwLogonFlags: DWORD;
lpApplicationName: LPCWSTR;
lpCommandLine: LPCWSTR;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: LPCWSTR;
const lpStartupInfo: TStartupInfo;
var lpProcessInfo: TProcessInformation
): BOOL; stdcall; external 'advapi32' name'CreateProcessWithLogonW';
function RunWithLogon(lpUsername: String; lpDomain: String; lpPassword: String;
lpApplicationName: String): Integer;
var
si: TStartupInfo;
pi: TProcessInformation;
begin
ZeroMemory(@si, SizeOf(TStartupInfo));
ZeroMemory(@pi, SizeOf(TProcessInformation));
si.cb:=SizeOf(TStartupInfo);
if CreateProcessWithLogonW(
PWideChar(WideString(lpUsername)),
PWideChar(WideString(lpDomain)),
PWideChar(WideString(lpPassword)),
LOGON_WITH_PROFILE,
PWideChar(WideString(lpApplicationName)),
nil, 0, nil, nil, si, pi) then Result:=0
else Result:=GetLastError;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(SysErrorMessage(RunWithLogon('Test', '', '123', 'c:\WINDOWS\NOTEPAD.EXE')));
end;
end.
от имени доменного пользователя тоже работает.
__________________
Пишу программы за еду.
__________________
|