看看我的程序:<br>program AppServer;<br><br>uses<br> SvcMgr,<br> Forms,<br> Windows,<br> SysUtils,<br> WinSvc,<br> PipeAppServer_TLB in 'PipeAppServer_TLB.pas',<br> RDM_GDgh_svr in 'Replace/RDM_GDgh_svr.pas' {RDM_gdgh: TRemoteDataModule},<br> DM_PIPEMIS in 'Overhaul/DM_PIPEMIS.pas' {DM_PipeServer: TRemoteDataModule},<br> U_rdm_jxjh_print in 'Overhaul/U_rdm_jxjh_print.pas' {RDM_Jxjh_Print: TRemoteDataModule},<br> U_datamodule in 'BaseInfo/data/U_datamodule.pas' {DM_LINFU: TRemoteDataModule} {DM_LINFU: CoClass},<br> RDM_GDCBFX in 'Lacuna/RDM_GDCBFX.pas' {RDM_cbqxfx: TRemoteDataModule} {RDM: CoClass},<br> U_rdm_zxjc in 'OnLine/Check/U_rdm_zxjc.pas' {Rdm_zxjc: TRemoteDataModule} {Rdm_zxjc: CoClass},<br> U_DMJBXXCX in 'BaseInfo/Query/U_DMJBXXCX.pas' {DM_jbxxcx: TRemoteDataModule},<br> DM_chfx in 'OnLine/MeasureThickNess/DM_chfx.pas' {Mid_CH: TRemoteDataModule} {Mid_CH: CoClass},<br> U_RDM_AcdntRgdt in 'AcdntRgdt/U_RDM_AcdntRgdt.pas' {RDM_AcdntRgdt: TRemoteDataModule} {RDM_AcdntRgdt: CoClass},<br> U_RDMLnJxjlcx in 'Overhaul/U_RDMLnJxjlcx.pas' {RDMLnJxjlcx: TRemoteDataModule} {RDMLnJxjlcx: CoClass},<br> ScktMain in 'SocketServer/ScktMain.pas' {SocketForm},<br> ScktCnst in 'SocketServer/ScktCnst.pas';<br><br>{$R *.TLB}<br><br>{$R *.RES}<br><br>function Installing: Boolean;<br>begin<br> Result := FindCmdLineSwitch('INSTALL',['-','/','/'], True) or<br> FindCmdLineSwitch('UNINSTALL',['-','/','/'], True);<br>end;<br><br>function StartService: Boolean;<br>var<br> Mgr, Svc: Integer;<br> UserName, ServiceStartName: string;<br> Config: Pointer;<br> Size: DWord;<br>begin<br> Result := False;<br> Mgr := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);<br> if Mgr <> 0 then<br> begin<br> Svc := OpenService(Mgr, PChar(SServiceName), SERVICE_ALL_ACCESS);<br> Result := Svc <> 0;<br> if Result then<br> begin<br> QueryServiceConfig(Svc, nil, 0, Size);<br> Config := AllocMem(Size);<br> try<br> QueryServiceConfig(Svc, Config, Size, Size);<br> ServiceStartName := PQueryServiceConfig(Config)^.lpServiceStartName;<br> if CompareText(ServiceStartName, 'LocalSystem') = 0 then<br> ServiceStartName := 'SYSTEM';<br> finally<br> Dispose(Config);<br> end;<br> CloseServiceHandle(Svc);<br> end;<br> CloseServiceHandle(Mgr);<br> end;<br> if Result then<br> begin<br> Size := 256;<br> SetLength(UserName, Size);<br> GetUserName(PChar(UserName), Size);<br> SetLength(UserName, StrLen(PChar(UserName)));<br> Result := CompareText(UserName, ServiceStartName) = 0;<br> end;<br>end;<br><br>begin<br> if not Installing then<br> begin<br> CreateMutex(nil, True, 'SCKTSRVR');<br> if GetLastError = ERROR_ALREADY_EXISTS then<br> begin<br> Application.MessageBox('服务器已经运行!','错误',MB_OK+MB_ICONERROR);<br> Halt;<br> end;<br> end;<br> if Installing or StartService then<br> begin<br> SvcMgr.Application.Initialize;<br> SocketService := TSocketService.CreateNew(SvcMgr.Application, 0);<br> SvcMgr.Application.Title := '应用程序服务器';<br> Application.CreateForm(TForm1, Form1);<br> SvcMgr.Application.Run;<br> end else<br> begin<br> Forms.Application.ShowMainForm := False;<br> Forms.Application.Initialize;<br> Forms.Application.CreateForm(TForm1, Form1);<br> SocketForm.Initialize(False);<br> Forms.Application.Run;<br> end; <br>end.