Hello guys! Here is all my code
Why the execution of the CreateProcessWithLogonW may not work?
program Launch;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows,
Dialogs;
function CreateProcessWithLogonW(lpUsdeerName,lpDomain,lpPassword: LPCWSTR;
dwLogonFlags:dword; lpApplicationName : LPCWSTR; lpCommandLine: LPWSTR; dwCreateionFlags:dword;
lpEnvironment:Pointer; lpCurrentDirectory: LPCWSTR; lpstartupinfo:tstartupinfo;
lpProcessInfo:TProcessInformation): BOOL; external 'C:\WINNT\system32\advapi32.dll';
const
pProgramName = 'ClipBoarder.exe';
pUserName = 'Administrator';
pUserDomain = '';
pUserPassword = 'pwd';
pNullStr = '';
var
StartInfo : TStartupInfo;
ProcInfo : TProcessInformation;
CreateOK : Boolean;
Count : Integer;
ProgramName,
UserName,
UserDomain,
UserPassword,
NullStr : PWideChar;
begin
ProgramName := StringToOleStr(pProgramName);
UserName := StringToOleStr(pUserName);
UserDomain := StringToOleStr(pUserDomain);
UserPassword := StringToOleStr(pUserPassword);
NullStr := StringToOleStr(pNullStr);
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
StartInfo.dwFlags := startf_UseShowWindow;
StartInfo.wShowWindow := 4;
try
{ CreateOK := CreateProcess(pProgramName,nil, nil, nil,False,
CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
nil, nil, StartInfo, ProcInfo);
}
CreateOK := CreateProcessWithLogonW(
UserName,
UserDomain,
UserPassword,
0,
ProgramName,
nil,
CREATE_DEFAULT_ERROR_MODE or NORMAL_PRIORITY_CLASS,
nil,
nil,
startinfo,
procinfo);
if not CreateOK then RaiseLastWin32Error;
except
on E: Exception do
begin
writeln(E.Message );
end;
end
end.
function CreateProcessWithLogonW(lp
dwLogonFlags:dword; lpApplicationName : LPCWSTR; lpCommandLine: LPWSTR; dwCreateionFlags:dword;
lpEnvironment:Pointer; lpCurrentDirectory: LPCWSTR; const lpstartupinfo:tstartupinfo
var lpProcessInfo:TProcessInfo
function CreateProcessWithLogon(use
var si : TStartupInfo;
begin
ZeroMemory(@si, sizeOf(si));
si.cb := sizeOf(si);
ZeroMemory(@pi, sizeOf(pi));
result := CreateProcessWithLogonW(PW
PWideChar(wideString(domai
PWideChar(wideString(passw
0, nil,
PWideChar(wideString(cmdLi
CREATE_DEFAULT_ERROR_MODE or NORMAL_PRIORITY_CLASS,
nil, nil, si, pi);
if not result then
result := GetLastError
else result := 0;
end;
Regards, Madshi.