如何用delphi运行一个外部程序,同时指定其安全权限为最小?谢谢!(50分)

  • 主题发起人 主题发起人 hzx317
  • 开始时间 开始时间
H

hzx317

Unregistered / Unconfirmed
GUEST, unregistred user!
如何用delphi运行一个外部程序,同时指定其安全权限为最小?谢谢!
我的思路是:
BOOL CreateProcess
(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes。
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
并指定:
LPSECURITY_ATTRIBUTES lpProcessAttributes。
LPSECURITY_ATTRIBUTES lpThreadAttributes,
这两个参数,但不是知道行不行,也不知道如何设置这两个参数,大虾们帮帮小弟。谢谢!
 
FillChar( lpStartupInfo,sizeof(lpStartupInfo),0);
FillChar(lpProcessInformation,sizeof(lpProcessInformation),0);
lpStartupInfo.cb:=sizeof(lpStartupInfo);
if CreateProcess(nil,PChar(Application.ExeName),nil,nil,false,THREAD_PRIORITY_NORMAL,nil,nil,lpStartupInfo,lpProcessInformation) then
begin
CloseHandle(lpProcessInformation.hThread);
CloseHandle(lpProcessInformation.hProcess);
end;
 
小弟不才,看不太明白,可否解释一下。
 
创建一个最小权限用户,或者就用Guest用户权限执行就行了.
const
LOGON_WITH_PROFILE = 1;
LOGON_NETCREDENTIALS_ONLY = 2;
CREATE_DEFAULT_ERROR_MODE = $04000000;

function CreateProcessWithLogon(
lpUsername: PWChar;
lpDomain: PWChar;
lpPassword: PWChar;
dwLogonFlags: DWORD;
lpApplicationName: PWChar;
lpCommandLine: PWChar;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: PWChar;
const lpStartupInfo: TStartupInfo;
var lpProcessInfo: TProcessInformation
): BOOL; stdcall; external 'advapi32.dll' name 'CreateProcessWithLogonW';
 
wr960204 的方法似乎简单又实用,谢了。不过:
const
LOGON_WITH_PROFILE = 1;
LOGON_NETCREDENTIALS_ONLY = 2;
CREATE_DEFAULT_ERROR_MODE = $04000000;
这几句什么用呀?谢谢!
 
后退
顶部