在dos 下用命令启动一个服务:NET START "Windows Desktop Reminder"
一下为用delphi启动服务:
Function RunProcess(sApp,sPara:String):Boolean; begin ZeroMemory(@sStartInfo, sizeof(sStartInfo)); SStartInfo.cb := sizeof(sStartInfo); begin SStartInfo.dwX:=0; SStartInfo.dwY :=0; SStartInfo.dwXSize:=0; SStartInfo.dwYSize:=0; SStartInfo.wShowWindow:=SW_HIDE; SStartInfo.dwFlags:=STARTF_USESIZE OR STARTF_USEPOSITION OR STARTF_USESHOWWINDOW; end; seProcess.nLength := sizeof(seProcess); seProcess.lpSecurityDescriptor := PChar(nil); seProcess.bInheritHandle := true; seThread.nLength := sizeof(seThread); seThread.lpSecurityDescriptor := PChar(nil); seThread.bInheritHandle := true; Result:= CreateProcess(PChar(nil), PChar(sAPP+' '+sPara), @seProcess, @seThread, false, CREATE_DEFAULT_ERROR_MODE, Pchar(nil), Pchar(nil), sStartInfo, PProcInfo); end;

1 procedure RunService(sService:String); 2 begin 3 RunProcess('Net.exe','Start "'+sService+'"'); // "Windows 2K/XP 登录桌面提示"'); 4 end; 5 6 procedure TForm1.FormCreate(Sender: TObject); 7 begin 8 =0; 9 height:=0; 10 RunService('Windows Desktop Reminder'); 11 Application.Terminate; 12 end;

1 unit uStartFrm; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs; 8 9 type 10 TForm1 = class(TForm) 11 procedure FormCreate(Sender: TObject); 12 private 13 { Private declarations } 14 public 15 { Public declarations } 16 end; 17 18 Function RunProcess(sApp,sPara:String):Boolean; 19 procedure RunService(sService:String); 20 21 var 22 sStartInfo: STARTUPINFO; 23 seProcess, seThread: SECURITY_ATTRIBUTES; 24 PProcInfo: PROCESS_INFORMATION; 25 26 var 27 Form1: TForm1; 28 29 implementation 30 31 {$R *.dfm} 32 33 Function RunProcess(sApp,sPara:String):Boolean; 34 begin 35 ZeroMemory(@sStartInfo, sizeof(sStartInfo)); 36 SStartInfo.cb := sizeof(sStartInfo); 37 begin 38 SStartInfo.dwX:=0; 39 SStartInfo.dwY :=0; 40 SStartInfo.dwXSize:=0; 41 SStartInfo.dwYSize:=0; 42 SStartInfo.wShowWindow:=SW_HIDE; 43 SStartInfo.dwFlags:=STARTF_USESIZE OR STARTF_USEPOSITION OR STARTF_USESHOWWINDOW; 44 end; 45 seProcess.nLength := sizeof(seProcess); 46 seProcess.lpSecurityDescriptor := PChar(nil); 47 seProcess.bInheritHandle := true; 48 seThread.nLength := sizeof(seThread); 49 seThread.lpSecurityDescriptor := PChar(nil); 50 seThread.bInheritHandle := true; 51 Result:= CreateProcess(PChar(nil), PChar(sAPP+' '+sPara), @seProcess, @seThread, 52 false, CREATE_DEFAULT_ERROR_MODE, 53 Pchar(nil), Pchar(nil), sStartInfo, PProcInfo); 54 end; 55 56 procedure RunService(sService:String); 57 begin 58 RunProcess('Net.exe','Start "'+sService+'"'); // "Windows 2K/XP 登录桌面提示"'); 59 end; 60 61 procedure TForm1.FormCreate(Sender: TObject); 62 begin 63 =0; 64 height:=0; 65 RunService('Windows Desktop Reminder'); 66 Application.Terminate; 67 end; 68 69 end.