还是不行,以下是我的代码。<br>function TMainForm.SetServerStatus(Action: TActionType): boolean;<br>var<br> ProcessEntry: TProcessEntry32;<br> CompleteFlg : boolean;<br> ProcessHand, HProcess : THandle;<br> StartUpInfo: TStartUpInfo;<br> ProcessInfo: TProcessInformation;<br>begin<br> result:= false;<br> ProcessHand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br> CompleteFlg := Process32First(ProcessHand, ProcessEntry);<br> ProcessEntry.dwSize:= SizeOf(ProcessEntry);<br> if Action in [ActFind, ActTerminate] then<br> while CompleteFlg do<br> begin<br> if ProcessEntry.szExeFile= GetServerName then<br> case Action of<br> ActFind:<br> begin<br> Result:= true;<br> Exit;<br> end;<br> ActTerminate:<br> begin<br> HProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessEntry.th32ProcessID);<br> TerminateProcess(HProcess,0);<br> end;<br> end;<br> CompleteFlg:= Process32Next(ProcessHand, ProcessEntry);<br> end<br> else<br> begin<br> FillChar(StartupInfo,SizeOf(StartupInfo),#0);<br> StartUpInfo.cb:=SizeOf(StartUpInfo);<br>{ StartUpInfo.dwFlags:= STARTF_USESHOWWINDOW;<br> StartUpInfo.wShowWindow:= SW_HIDE;}<br> if not CreateProcess(nil, Pchar(ServerPos), nil, nil, false, CREATE_NEW_CONSOLE or<br> NORMAL_PRIORITY_CLASS, nil, nil, StartUpInfo, PROCESSINFO) then<br> Application.MessageBox(Pchar('无法运行' + ServerPos), '错误!', MB_OK);<br> end;<br>end;<br>