HanDs
管理员

[Delphi文章] 指定权限运行程序 





学习中请遵循国家相关法律法规,黑客不作恶。没有网络安全就没有国家安全

本站需要登陆后才能查看

type
  _STARTUPINFOW = record
    cb: DWORD;
    lpReserved: LPWSTR;
    lpDesktop: LPWSTR;
    lpTitle: LPWSTR;
    dwX: DWORD;
    dwY: DWORD;
    dwXSize: DWORD;
    dwYSize: DWORD;
    dwXCountChars: DWORD;
    dwYCountChars: DWORD;
    dwFillAttribute: DWORD;
    dwFlags: DWORD;
    wShowWindow: Word;
    cbReserved2: Word;
    lpReserved2: PByte;
    hStdInput: THandle;
    hStdOutput: THandle;
    hStdError: THandle;
  end;
  STARTUPINFOW = _STARTUPINFOW;

function CreateProcessWithLogonW(lpUserName, lpDomain, lpPassword: LPCWSTR;
  dwLogonFlags: DWORD; lpApplicationName: LPCWSTR; lpCommandLine: LPWSTR;
  dwCreationFlags: DWORD; lpEnvironment: Pointer; lpCurrentDirectory: LPCWSTR;
  const lpStartupInf STARTUPINFOW; var lpProcessInformation: PROCESS_INFORMATION): BOOL; stdcall;
  external advapi32 Name 'CreateProcessWithLogonW'

procedure TForm1.Button2Click(Sender: TObject);
var
  STARTUPINF StartupInfoW;
  ProcessInf TProcessInformation;
  AUser, ADomain, APass, AExe: WideString;
const
  LOGON_WITH_PROFILE = $00000001;
  LOGON_NETCREDENTIALS_ONLY = $00000002;
begin
  FillChar(STARTUPINFO, SizeOf(StartupInfoW), #0);
  STARTUPINFO.cb := SizeOf(StartupInfoW);
  STARTUPINFO.dwFlags := STARTF_USESHOWWINDOW;
  STARTUPINFO.wShowWindow := SW_SHOW;
  AUser := edtUser.Text;
  ADomain := edtDomain.Text;
  APass := edtPass.Text;
  AExe := edtExe.Text;
  if not CreateProcessWithLogonW(PWideChar(AUser), PWideChar(ADomain),
    PWideChar(APass),
    LOGON_WITH_PROFILE, nil, PWideChar(AExe),
    NORMAL_PRIORITY_CLASS, nil, nil, STARTUPINFO, ProcessInfo) then
    RaiseLastOSError;
end;

已经测试通过  


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
上一主题 下一主题
指定 权限 运行 程序
#1楼