用AutoIT能不能做出ICS共享网络的软件?
本帖最后由 ajian55 于 2009-11-14 15:20 编辑如题,能不能用AutoIT做出ICS共享网络的软件?请教高手。 没试过,可以研究下 不知道~~~帮顶!!!! 考大家分错别字 可以,参考VBS脚本
Option Explicit
On Error Resume Next
' *** Configuration Option
' 0 - Only check ICS status on all interfaces
' 1 - Disable if ICS is Enabled on any interface
Const DISABLE_ICS = 1
' *****************************************************************************
' Function - CheckPerInterfaceICSSetting
' Description - Checks the ICS setting on each of the interfaces and if
' it is Enabled and DISABLE_ICS = 1, diables it.
' Note: Disabling ICS on an interface require Admin privileges
' Returns - Exits from the script with the following errorlevel
' 0 - If ICS is disabled on all the interfaces
' 1 - If ICS is enabled on any interface
' 2 - If unable to query ICS setting on interface due to
' COM object not being initialized etc.
' 3 - If unable to disabled ICS on any interface
' ****************************************************************************
Sub CheckPerInterfaceICSSetting()
On Error Resume Next
Dim objShare
Dim objEveryColl
Dim objShell
Set objShare = Wscript.CreateObject("HNetCfg.HNetShare")
If (IsObject(objShare) = FALSE ) Then
WScript.Echo("Unable to create object : HNetCfg.HNetShare")
WScript.Quit (2)
End If
Set objEveryColl = objShare.EnumEveryConnection
If (IsObject(objEveryColl) = FALSE) Then
WScript.Echo("Unable to Enumerate Connections")
WScript.Quit (2)
END IF
Dim objNetConn
For each objNetConn in objEveryColl
Dim objShareCfg, ConnectionProps
Set objShareCfg = objShare.INetSharingConfigurationForINetConnection(objNetConn)
If (IsObject(objShareCfg) = FALSE) Then
WScript.Echo("Unable to retrieve Sharing Cfg Object")
WScript.Quit (2)
End If
Set ConnectionProps = objShare.NetConnectionProps(objNetConn)
If (IsObject(ConnectionProps) = FALSE) Then
WSCript.Echo("Unable to retrieve ConnectionProps object")
WScript.Quit (2)
End If
WScript.Echo "Connection : " & ConnectionProps.Name
If (objShareCfg.SharingEnabled) Then
WScript.Echo("ICS is Enabled on this Interface")
'Disable Connection Sharing on this interface if configured to do so
If (DISABLE_ICS = 1) Then
DisableICS(objShareCfg)
Else
WScript.Echo("Connection Sharing is Enabled on a interface. Validation Failed")
WScript.Quit (1)
End If
Else
WScript.Echo("ICS is Disabled on this Interface")
End If
Next
Set objShare = Nothing
Set objEveryColl = Nothing
Set objShell = Nothing
WScript.Echo("Connection Sharing is Disabled on all interfaces. Validation Passed")
WScript.Quit (0)
End Sub
' *****************************************************************************
' Function - DisableICS
' Description - Checks for Admin privileges and Disables ICS on the interface
' passed
' Returns - Nothing
' ****************************************************************************
Sub DisableICS(objShareCfg)
On Error Resume Next
WScript.Echo("Disabling Connection Sharing...")
objShareCfg.DisableSharing
If (Err.Number <> 0) Then
WScript.Echo("Unable to Disable ICS on the Interface")
WSCript.Quit (3)
End If
End Sub
' *****************************************************************************
' Function - Main
' Description - Invokes routines to validate the ICS setting on all the interfaces
' Returns - Nothing
' ****************************************************************************
Sub Main()
CheckPerInterfaceICSSetting()
End Sub
Main()
页:
[1]