
07.01.2013, 13:50
|
Активный
|
|
Регистрация: 07.08.2012
Сообщения: 258
Версия Delphi: Delphi 7
Репутация: 11
|
|
Спасибо большое! Я совсем немного переделал вот так:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FileName : PWideChar;
implementation
{$R *.dfm}
function CreateProcessWithLogonW(
lpUsername: LPCWSTR;
lpDomain: LPCWSTR;
lpPassword: LPCWSTR;
dwLogonFlags: DWORD;
lpApplicationName: LPCWSTR;
lpCommandLine: LPWSTR;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: LPCWSTR;
const lpStartupInfo: _STARTUPINFOA;
var lpProcessInfo: _PROCESS_INFORMATION
): Boolean; stdcall; external 'Advapi32.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
startupinfo: _STARTUPINFOA;
processinformation: _PROCESS_INFORMATION;
begin
ZeroMemory(@startupinfo, SizeOf(_STARTUPINFOA));
startupinfo.cb:=SizeOf(_STARTUPINFOA);
startupinfo.dwFlags:=STARTF_USESHOWWINDOW;
startupinfo.wShowWindow:=SW_SHOW;
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
FileName := PWideChar(WideString(Edit1.Text));
if CreateProcessWithLogonW('Гость', nil, '', 0, nil, FileName, 0, nil, nil, startupinfo, processinformation) then
begin
CloseHandle(processinformation.hThread);
CloseHandle(processinformation.hProcess);
end else RaiseLastOSError;
end;
end.
|