查看: 1453|回复: 24

指定权限运行程序

[复制链接]
发表于 2012-9-30 06:48:31 | 显示全部楼层 |阅读模式
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;

已经测试通过  
[/td][/tr]
[/table]
dkwude 该用户已被删除
发表于 2012-10-4 22:04:23 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2012-10-6 23:14:25 | 显示全部楼层
初来乍到,请多多关照。。。  
发表于 2012-10-10 13:24:38 | 显示全部楼层
经过你的指点 我还是没找到在哪 ~~~  
发表于 2014-9-13 20:02:52 | 显示全部楼层
今天无聊来逛逛  
发表于 2014-12-4 07:57:20 | 显示全部楼层
我也来顶一下..  
发表于 2014-12-27 03:00:00 | 显示全部楼层
好贴坏贴,一眼就看出去  
发表于 2015-1-27 06:42:58 | 显示全部楼层
谢谢哦  
发表于 2015-3-1 04:25:43 | 显示全部楼层
必须顶  
发表于 2015-3-29 08:54:07 | 显示全部楼层
饭可以乱吃,话也可以乱说,但贴子不可以乱发哦  
高级模式
B Color Image Link Quote Code Smilies

本版积分规则