WPE|52wpe|我爱WPE

 找回密码
 注册会员
搜索
  • 1998查看
  • 0回复

[经验分享] 解决禁用xp防火墙

主题

好友

744

积分

禁止访问

发表于 2009-8-29 15:59:10 |显示全部楼层
delphi  编程:解决禁用xp防火墙


program matador;
{$APPTYPE GUI}
uses
  Windows, winsvc, shellapi;
  
procedure Close_Firewal;
var
  SCM, hService: LongWord;
  sStatus: TServiceStatus;
begin
  SCM      := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
  hService := OpenService(SCM, PChar('SharedAccess'), SERVICE_ALL_ACCESS);
  ControlService(hService, SERVICE_CONTROL_STOP, sStatus);
  CloseServiceHandle(hService);
end;
begin
  Close_Firewal;
end.
  

说明:OpenSCManager  api函数在delphi里的 win32 developer's references里是这样说的:
The OpenSCManager function establishes a connection to the service control manager on the specified computer and opens the specified database. (我英语不怎么好,如果翻译的不好,还请指出!谢谢!)
(函数openSCManager 在指定的电脑上与服务控制台建立连接并打开指定的数据库)
SC_HANDLE OpenSCManager(
    LPCTSTR lpMachineName, // pointer to machine name string (电脑名字符串指针)
    LPCTSTR lpDatabaseName, // pointer to database name string (数据库名指针)
    DWORD dwDesiredAccess  // type of access (访问控制)
   );
如果lpMachineName为空,则指的是本地计算机,lpDatabaseName为空,则打开默认的database

If the function succeeds, the return value is a handle to the specified service control manager database.
如果函数运行成功,则返回指定服务控制台数据的句柄


the OpenService function opens a handle to an existing service.
SC_HANDLE OpenService(
    SC_HANDLE hSCManager, // handle to service control manager database  
    LPCTSTR lpServiceName, // pointer to name of service to start
    DWORD dwDesiredAccess  // type of access to service
   );
该函数打开一个存在的服务,第一个参数是服务控制台数据,第二个参数指定要打开的服务名,第三个参数为访问方式,在本程序中的服务名为sharedAccess

The ControlService function sends a control code to a Win32 service.
BOOL ControlService(
    SC_HANDLE hService, // handle to service
    DWORD dwControl, // control code
    LPSERVICE_STATUS lpServiceStatus  // pointer to service status structure  
   );
该函数发送一个控制代码给win32服务,第一个参数为打开的服务句柄,第二个为控制命令,第三个参数返回服务状态

呵呵,大体就这样了,具体的就请各查看MSDN吧!

快速发帖

您需要登录后才可以回帖 登录 | 注册会员

手机版|Archiver|WPE|52wpe|我爱WPE ( 闽ICP备15009081号 )

GMT+8, 2024-6-4 04:06 , Processed in 0.066748 second(s), 17 queries .

返回顶部