请问用ShellExecute如何调用ping程序.
比如我想ping 10.11.22.1 这个地址,用ShellExecute调用的话应该怎么写啊,谢谢.
[解决办法]
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\xxxxx.exe ";
ShExecInfo.lpParameters = " ";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
或: PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo; //This is an [in] parameter
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
if(CreateProcess( "c:\\winnt\\notepad.exe ", NULL,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
}
else
{
MessageBox( "The process could not be started... ");
}
[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute (Handle,nil, 'cmd.exe ', '/K ping 127.0.0.1 ',nil,SW_NORMAL);
//-----这句是使用参数 /K,Ping完 IP 127.0.0.1 后,cmd.exe窗口静静的等你看结果哦...
//ShellExecute (Handle,nil, 'cmd.exe ', '/C ping 127.0.0.1 ',nil,SW_NORMAL);
//-----这句是使用参数 /C,Ping完 IP 127.0.0.1 后,cmd.exe窗口消失了...
end;
end.
[解决办法]
为什么不用ICMP控件做?