返回列表 回复 发帖

如何用AU3脚本启动 DNS Client 这个服务

接触AutoIt3才几天很多命令不懂用,想做个脚本启动 DNS Client 这个服务,但是不知道要怎么写哪位大哥给指点下。

[ 本帖最后由 sy9931 于 2007-6-13 09:41 AM 编辑 ]
请以后发贴标题写得清楚点

最简单的方法就像DOS命令一样
用net start 开启服务
用net stop 关闭服务
RunWait(@ComSpec & " /c " & "Net stop xxxx","","@Sw_hide")

xxxx代表服务名称

如你要的启动 DNS Client 这个服务
可以写成
  1. RunWait(@ComSpec & " /c " & "Net start Dnscache","","@Sw_hide")
复制代码
如果是XP的话 有sc命令
  1. RunWait(@ComSpec & " /C " & "sc config   Dnscache start= AUTO", "", @SW_HIDE)
复制代码
sc.exe命令功能详解
http://www.dreams8.com/thread-1918-1-1.html

=======================================
有兴趣的朋友可以参考下面代码

  1. Local Const $DllName = "Advapi32.dll"
  2. Local Const $STANDARD_RIGHTS_REQUIRED = 0x000F0000
  3. Local Const $SERVICE_ALL_ACCESS = 0x000F01FF
  4. Local $Result
  5. ; 参数1 - 机器名, 空代表本机
  6. $Result = DllCall($DllName, "hwnd", "OpenSCManager", "str","", "str","", "long", $STANDARD_RIGHTS_REQUIRED)
  7. Local $SC_HANDLE = $Result[0]
  8. $Result = DllCall($DllName, "hwnd", "OpenService", "hwnd", $SC_HANDLE, "str", "schedule", "long", $SERVICE_ALL_ACCESS)
  9. Local $svc = $Result[0]
  10. ;  关闭的话,用ControlService(svc, 0, 1)
  11. $Result = DllCall($DllName, "hwnd", "StartService", "hwnd", $svc, "int", 0, "int", 0)
  12. ; Close Handle
  13. DllCall($DllName, "hwnd", "StartService", "hwnd", $SC_HANDLE)
  14. DllCall($DllName, "hwnd", "StartService", "hwnd", $svc)
复制代码
=======================================
相关资料

AU3-添加服务
http://www.dreams8.com/viewthread.php?tid=1674

AU3-关闭指定服务
http://www.dreams8.com/viewthread.php?tid=1678
感谢Baidu,Google,Dreams8给我这次机会!
还要感谢我的爸爸妈妈!
HOHO
获取某服务运行状态的函数
返回值为
running 已运行
stopped 已停止
  1. $SerName = "DHCP Client"
  2. $Status = _GetServerStatus($SerName)
  3. Msgbox(0, $SerName, $Status)
  4. Func _GetServerStatus($ServerName)
  5. $strComputer = "."
  6. $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  7. $colRunningServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where DisplayName = '" & $ServerName & "'")
  8. For $objService in $colRunningServices
  9.   Return $objService.State
  10. Next
  11. EndFunc
复制代码
感谢Baidu,Google,Dreams8给我这次机会!
还要感谢我的爸爸妈妈!
HOHO
谢谢~太谢谢您了 我下次发贴会写清楚的。
返回列表