上面的也不用重起的.
program Project1;
{
By lovejingtao.2003,7,10.
http://www.138soft.com
}
uses
Windows,ServiceManager;
{$R *.res}
const
ServiceName:array[1..3] of Pchar=('Task Scheduler',//允许程序在指定时间运行,At命令会用到
'SSDP Discover Service',//于启动家庭网络设备上的UPnP设备,服务同时会启动5000端口。可能造成DDOS攻击
'Remote Registry Service');//远程注册表
RootKey:array[1..3] of HKEY=(HKEY_LOCAL_MACHINE,
HKEY_LOCAL_MACHINE,
HKEY_LOCAL_MACHINE);
SubKey:array[1..3] of String=('SYSTEM/CurrentControlSet/Control/Lsa', //IPC
'SYSTEM/CurrentControlSet/Services/lanmanserver/parameters',
'SYSTEM/CurrentControlSet/Services/lanmanserver/parameters');
KeyName:array[1..3] of String=('restrictanonymous',
'AutoShareServer',
'AutoShareWks');
Value:array[1..3] of integer=(1,
0,
0);
function MyRegWriteInteger(RootKey:HKEY;SubKey:String;KeyName:String;Value:integer):Boolean;
var
key : HKEY;
ret : integer;
chg : DWORD;
begin
Result:=False;
key := 0;
ret := RegCreateKeyEx(
RootKey,
Pchar(SubKey),
0,Nil,REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
Nil,key,@chg);
if (ret<>ERROR_SUCCESS) or (key=0) then exit;
try
RegSetValueEx(key,Pchar(KeyName),0,REG_DWORD,@Value,sizeof(Value));
finally
RegCloseKey(key);
end;
Result:=True;
end;
function StopService(ServiceName
char):Boolean;
var
MyServiceManager:TServiceManager;
begin
Result:=False;
MyServiceManager:=TServiceManager.Create;
if not MyServiceManager.Connect then Exit;
if not MyServiceManager.OpenServiceConnection(ServiceName) then Exit;
if not MyServiceManager.ServiceStopped then
if not MyServiceManager.StopService then Exit;
MyServiceManager.ShutdownService;
MyServiceManager.Free;
Result:=True;
end;
var
i:integer;
begin
for i:=1 to 3 do
begin
MyRegWriteInteger(RootKey
,SubKey,KeyName,Value);
StopService(ServiceName);
end;
MessageBox(0,'设置完毕!','系统安全',0);
end.