Форум: "WinAPI";
Текущий архив: 2002.09.26;
Скачать: [xml.tar.bz2];
ВнизФункция CreateProcessWithLogonW Найти похожие ветки
← →
denisX_555 (2002-08-09 06:31) [0]Всем привет!!! Ребята помогите!!! Напешите, как запусть программу с использованием фукции: CreateProcessWithLogonW
У меня есть код, но он не срабатывает, в чем ошибка?
uses Windows;
{$R *.RES}
function CreateProcessWithLogonW(lpUsdeerName,lpDomain,lpPassword:Pchar; dwLogonFlags:dword; lpApplicationName,lpCommandLine:Pchar; dwCreateionFlags:dword; lpEnvironment:Pointer; lpCurrentDirectory:Pchar; lpstartupinfo:tstartupinfo; lpProcessInfo:TProcessInformation): BOOL; external "C:\WINNT\system32\advapi32.dll";
var ProcInfo:TProcessInformation;
StartInfo:TStartUpInfo;
begin
FillChar(StartInfo,SizeOf(StartInfo),0);
with StartInfo do begin
cb := SizeOf(StartInfo);
dwFlags := startf_UseShowWindow;
wShowWindow := 4;
end;
createprocesswithlogonW(Pchar("Administrator"),Pchar("Domain"),
Pchar ("Password"),0,Pchar("proga.exe"),nil,CREATE_DEFAULT_ERROR_MODE or NORMAL_PRIORITY_CLASS,nil,nil,startinfo,procinfo);
end.
Или может есть другой вариант? Заранее спасибо!!!
← →
denisX_555 (2002-08-09 09:26) [1]Извеняюсь, уже нашел на http://rsdn.ru/, но если кому-то интересна эта тема вот код:
type
TCreateProcessWithLogonW = function(
lpUsername : PWideChar;
lpDomain : PWideChar;
lpPassword : PWideChar;
dwLogonFlags : DWORD;
lpApplicationName : PWideChar;
lpCommandLine : PWideChar;
dwCreationFlags : DWORD;
lpEnvironment : Pointer;
lpCurrentDirectory : PWideChar;
const lpStartupInfo : _STARTUPINFOA;
var lpProcessInfo : PROCESS_INFORMATION):BOOL;stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var hLib:THandle;
CreateProcessWithLogon : TCreateProcessWithLogonW;
si : _STARTUPINFOA;
pi : Process_Information;
begin
hLib:=LoadLibrary("advapi32.dll");
ZeroMemory(@Si,Sizeof(si));
si.cb:=SizeOf(si);
CreateProcessWithLogon:=GetProcAddress(hLib,"CreateProcessWithLogonW");
CreateProcessWithLogon("login",nil,"password",1,nil,"cmd.exe",0,nil,nil,si,pi);
end;
← →
Ученик (2002-08-09 09:30) [2]Это из Project JEDI Code Library (JCL), JclMiscel.pas, то что не будет компилироваться попробуй комментарить (было на http://delphi-jedi.org/scripts/runisa.dll?Jedi:CODELIBJCL, но сейчас вроде не работает).
procedure CreateProcAsUserEx(const UserDomain, UserName, Password, CommandLine: string;
const Environment: PChar);
const
// default values for window stations and desktops
CreateProcDEFWINSTATION = "WinSta0";
CreateProcDEFDESKTOP = "Default";
CreateProcDOMUSERSEP = "\";
var
ConsoleTitle: string;
Help: string;
WinStaName: string;
DesktopName: string;
hUserToken: THandle;
hWindowStation: HWINSTA;
hDesktop: HDESK;
StartUpInfo: TStartUpInfo;
ProcInfo: TProcessInformation;
begin
// Step 1: check for the correct OS version
CheckOSVersion;
// Step 2: logon as the specified user
if not LogonUser(PChar(UserName), PChar(UserDomain), PChar(Password),
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hUserToken) then
begin
case GetLastError of
ERROR_PRIVILEGE_NOT_HELD:
raise EJclCreateProcessError.CreateResRecFmt(@RsCreateProcPrivilegeMissing,
[GetPrivilegeDisplayName(SE_TCB_NAME), SE_TCB_NAME]);
ERROR_LOGON_FAILURE:
raise EJclCreateProcessError.CreateResRec(@RsCreateProcLogonUserError);
ERROR_ACCESS_DENIED:
raise EJclCreateProcessError.CreateResRec(@RsCreateProcAccessDenied);
else
raise EJclCreateProcessError.CreateResRec(@RsCreateProcLogonFailed);
end;
end;
// Step 3: give the new user access to the current WindowStation and Desktop
hWindowStation:= GetProcessWindowStation;
WinStaName := GetUserObjectName(hWindowStation);
if WinStaName = "" then
WinStaName := CreateProcDEFWINSTATION;
if not SetUserObjectFullAccess(hWindowStation) then
begin
CloseHandle(hUserToken);
raise EJclCreateProcessError.CreateResRecFmt(@RsCreateProcSetStationSecurityError, [WinStaName]);
end;
hDesktop := GetThreadDesktop(GetCurrentThreadId);
DesktopName := GetUserObjectName(hDesktop);
if DesktopName = "" then
DesktopName := CreateProcDEFDESKTOP;
if not SetUserObjectFullAccess(hDesktop) then
begin
CloseHandle(hUserToken);
raise EJclCreateProcessError.CreateResRecFmt(@RsCreateProcSetDesktopSecurityError, [DesktopName]);
end;
// Step 4: set the startup info for the new process
ConsoleTitle := UserDomain + UserName;
FillChar(StartUpInfo, SizeOf(StartUpInfo), #0);
with StartUpInfo do
begin
cb:= SizeOf(StartUpInfo);
lpTitle:= PChar(ConsoleTitle);
Help := WinStaName + "\" + DeskTopName;
lpDesktop:= PChar(Help);
end;
// Step 5: create the child process
if not CreateProcessAsUser(hUserToken, nil, PChar(CommandLine),
nil, nil, False, CREATE_NEW_CONSOLE or CREATE_NEW_PROCESS_GROUP,
Environment, nil, StartUpInfo, ProcInfo) then
begin
case GetLastError of
ERROR_PRIVILEGE_NOT_HELD:
raise EJclCreateProcessError.CreateResRecFmt(@RsCreateProcPrivilegesMissing,
[GetPrivilegeDisplayName(SE_ASSIGNPRIMARYTOKEN_NAME), SE_ASSIGNPRIMARYTOKEN_NAME,
GetPrivilegeDisplayName(SE_INCREASE_QUOTA_NAME), SE_INCREASE_QUOTA_NAME]);
ERROR_FILE_NOT_FOUND:
raise EJclCreateProcessError.CreateResRecFmt(@RsCreateProcCommandNotFound, [CommandLine]);
else
raise EJclCreateProcessError.CreateResRec(@RsCreateProcFailed);
end;
end;
// clean up
CloseWindowStation(hWindowStation);
CloseDesktop(hDesktop);
CloseHandle(hUserToken);
// if this code should be called although there has
// been an exception during invocation of CreateProcessAsUser,
// it will quite surely fail. you should make sure this doesn"t happen.
// (it shouldn"t happen due to the use of exceptions in the above lines)
CloseHandle(ProcInfo.hThread);
CloseHandle(ProcInfo.hProcess);
end;
← →
Ученик (2002-08-09 09:30) [3]Опоздал :)
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2002.09.26;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.007 c