如一个程序要有以下的命令来运行
runas /env /savecred /user:hhql "c:\qlnetbar\bc2\bc2"
我现在的问题是如何在Delphi中用代码来代替 runas /env /savecred /user:hhql 的功能,因为我要监视 c:\qlnetbar\bc2\bc2 的运行情况,所以 c:\qlnetbar\bc2\bc2 必须要由我用Delphi写的程序来运行请高手指教。
runas /env /savecred /user:hhql "c:\qlnetbar\bc2\bc2"
我现在的问题是如何在Delphi中用代码来代替 runas /env /savecred /user:hhql 的功能,因为我要监视 c:\qlnetbar\bc2\bc2 的运行情况,所以 c:\qlnetbar\bc2\bc2 必须要由我用Delphi写的程序来运行请高手指教。
解决方案 »
- Delphi访问Access数据库问题
- 在delphi中的DBgrid中实现下拉框,数据在b表中,动态代码怎么实现?
- Delphi怎么把网页上的图放到程序里?
- 我在TScrollBox中放了一个图形,我想在图形放大后 让图形居中,让TScrollBox的滚动条也居中,即让TScrollBox滚动一下
- 关与取得窗口句柄......
- 请问可不可以在delphi里面同时打开两个工程??
- 如何让软件使用者在软件运行时修改报表格式以及字段等?
- 进来看一下,这段代码啊出错在那里
- 请问以下语句哪错了?
- 寻找Delphi的语法、函数、程序结构等
- 高手请进,TTcpServer/TTcpClient的使用?
- 紧急求救 这样改变Combobox的下拉窗口的宽度 为什么出错
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 lpStartupInfo: STARTUPINFOW; var lpProcessInformation: PROCESS_INFORMATION): BOOL; stdcall;
external advapi32 Name 'CreateProcessWithLogonW'procedure TForm1.Button2Click(Sender: TObject);
var
STARTUPINFO: StartupInfoW;
ProcessInfo: 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;已经测试通过
如果你用XP或2000,可以用下面的API:CreateProcessWithLogonW
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 lpStartupInfo: STARTUPINFOW; var lpProcessInformation: PROCESS_INFORMATION): BOOL; stdcall;
external advapi32 Name 'CreateProcessWithLogonW'procedure TForm1.Button2Click(Sender: TObject);
var
STARTUPINFO: StartupInfoW;
ProcessInfo: 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;已经测试通过
CreateProcessWithLogonW
runas /env /savecred /user:hhql "c:\qlnetbar\bc2\bc2"
来运行 "c:\qlnetbar\bc2\bc2" 然后监视 "c:\qlnetbar\bc2\bc2" 什么时候运行完毕,怎么办????
请再指教一次哦
里面有个参数
lpProcessInfo 的参数,访问其变量:hProcess用 waitforsingleObject(lpProcessInfo.hProcess) 可以等待 运行完毕