开发思路:编写一个Windows NT服务,在服务启动过程中,启动一个线程,在线程中执行如下代码,启动监听。运行过程中,线程一直存在,新装的系统。说明一下,程序在大多数版本中都能正常使用,在个别XP sp3的克隆版中,存在上述问题,但现在大多客户端都是使用的克隆版的XP sp3,如果都让换系统,不是很现实,只能想法改程序,或调整系统设置。procedure CommSvr.Execute;begin FreeOnTerminate := True; CoInitialize(Nil); WriteLog('正在启动监听程序'); Try GFCommService.IdTCPServer1.Active := False; GFCommService.IdTCPServer1.Bindings.Clear; With GFCommService.IdTCPServer1.Bindings.Add Do Begin IP := is_ip; Port := ii_port; End; GFCommService.IdTCPServer1.DefaultPort := ii_port; Try GFCommService.IdTCPServer1.StartListening; GFCommService.IdTCPServer1.Active := True; //GFCommService.IdTCPServer1.Bindings.Items[0].Port WriteLog('监听地址:' + GFCommService.IdTCPServer1.Bindings.Items[0].IP); WriteLog('监听端口:' + INtToStr(GFCommService.IdTCPServer1.Bindings.Items[0].Port)); //WriteLog('监听端口2:' + INtToStr(GFCommService.IdTCPServer1.DefaultPort)); Except On E1:Exception Do Begin WriteLog('启动监听程序失败。错误信息:' + E1.Message); Exit; End End; Except On E:Exception Do Begin WriteLog('启动监听程序失败。错误信息:' + E.Message); Exit; End End; WriteLog('启动监听程序成功'); While (Not Terminated) Do Begin Sleep(1000 * 3600); //Sleep(3000); //If GFCommService.IdTCPServer1.Active Then WriteLog('监听状态:正在监听...'); //在此处测试,仍然处于监听状态。 End; CoUninitialize;end;