有谁研究了HNetCfg.HnetShare.1对象的?
vbs吧
全部回复
仅看楼主
level 7
hgmmym 楼主
一L防抽。。。
2012年03月05日 00点03分 1
level 7
hgmmym 楼主
HNetCfg.HnetShare.1 关于设置共享的玩意,谁给个手册或者参数属性方法使用。。。。。。
已问过度娘,度娘说我人品低。。。。
2012年03月05日 00点03分 2
level 7
hgmmym 楼主
@愚人陈 我知道你在线。。。。
2012年03月05日 01点03分 3
level 8
没用过,不知道是什么
2012年03月05日 01点03分 4
level 7
hgmmym 楼主
'↓运行命令↓
'cscript /nologo ics.vbs "无线网络连接" "本地连接" "off"
'将以上代码保存为*.bat文件运行,三个参数分别为,供别人连接的网卡名字、提供共享的网卡名称、开启(on)关闭(off)
' VBScript source code
OPTION EXPLICIT
DIM ICSSC_DEFAULT, CONNECTION_PUBLIC, CONNECTION_PRIVATE, CONNECTION_ALL
DIM NetSharingManager
DIM PublicConnection, PrivateConnection
DIM EveryConnectionCollection DIM objArgs
DIM priv_con, publ_con
dim switch ICSSC_DEFAULT = 0
CONNECTION_PUBLIC = 0
CONNECTION_PRIVATE = 1
CONNECTION_ALL = 2 Main() sub Main( )
Set objArgs = WScript.Arguments if objArgs.Count = 3 then
priv_con = objArgs(0)'内网连接名
publ_con = objArgs(1)'外网连接名
switch = objArgs(2)'状态切换开关 on 为 打开ics off 相反 if Initialize() = TRUE then
GetConnectionObjects()
FirewallTestByName priv_con,publ_con
end if
else
DIM szMsg
if Initialize() = TRUE then
GetConnectionObjects()
FirewallTestByName "list","list"
end if szMsg = "To share your internet connection, please provide the name of the private and public connections as the argument." & vbCRLF & vbCRLF & _
"Usage:" & vbCRLF & _
" " & WScript.scriptname & " " & chr(34) & "Private Connection Name" & chr(34) & " " & chr(34) & "Public Connection Name" & chr(34)
WScript.Echo( szMsg & vbCRLF & vbCRLF)
end if
end sub sub FirewallTestByName(con1,con2)
on error resume next
DIM Item
DIM EveryConnection
DIM objNCProps
DIM szMsg
DIM bFound1,bFound2 WScript.echo(vbCRLF & vbCRLF)
bFound1 = false
bFound2 = false
for each Item in EveryConnectionCollection
set EveryConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
set objNCProps = NetSharingManager.NetConnectionProps(Item)
szMsg = "Name: " & objNCProps.Name & vbCRLF & _
"Guid: " & objNCProps.Guid & vbCRLF & _
"DeviceName: " & objNCProps.DeviceName & vbCRLF & _
"Status: " & objNCProps.Status & vbCRLF & _
"MediaType: " & objNCProps.MediaType
if EveryConnection.SharingEnabled then
szMsg = szMsg & vbCRLF & _
"SharingEnabled" & vbCRLF & _
"SharingType: " & ConvertConnectionTypeToString(EveryConnection.SharingConnectionType)
end if if objNCProps.Name = con1 then
bFound1 = true
if EveryConnection.SharingEnabled = False and switch="on" then
szMsg = szMsg & vbCRLF & "Not Shared... Enabling private connection share..."
WScript.Echo(szMsg)

2012年03月05日 01点03分 5
level 7
hgmmym 楼主
EveryConnection.EnableSharing CONNECTION_PRIVATE
szMsg = " Shared!"
elseif(switch = "off") then
szMsg = szMsg & vbCRLF & "Shared... DisEnabling private connection share..."
WScript.Echo(szMsg)
EveryConnection.EnableSharing CONNECTION_ALL
end if
end if if objNCProps.Name = con2 then
bFound2 = true
if EveryConnection.SharingEnabled = False and switch="on" then
szMsg = szMsg & vbCRLF & "Not Shared... Enabling public connection share..."
WScript.Echo(szMsg)
EveryConnection.EnableSharing CONNECTION_PUBLIC
szMsg = " Shared!"
elseif(switch = "off") then
szMsg = szMsg & vbCRLF & "Shared... DisEnabling public connection share..."
WScript.Echo(szMsg)
EveryConnection.EnableSharing CONNECTION_ALL
end if
end if
WScript.Echo(szMsg & vbCRLF & vbCRLF)
next if( con1 <> "list" ) then
if( bFound1 = false ) then
WScript.Echo( "Connection " & chr(34) & con1 & chr(34) & " was not found" )
end if
if( bFound2 = false ) then
WScript.Echo( "Connection " & chr(34) & con2 & chr(34) & " was not found" )
end if
end if
end sub function Initialize()
DIM bReturn
bReturn = FALSE set NetSharingManager = Wscript.CreateObject("HNetCfg.HNetShare.1")
if (IsObject(NetSharingManager)) = FALSE then
Wscript.Echo("Unable to get the HNetCfg.HnetShare.1 object")
else
if (IsNull(NetSharingManager.SharingInstalled) = TRUE) then
Wscript.Echo("Sharing isn't available on this platform.")
else
bReturn = TRUE
end if
end if
Initialize = bReturn
end function function GetConnectionObjects()
DIM bReturn
DIM Item bReturn = TRUE if GetConnection(CONNECTION_PUBLIC) = FALSE then
bReturn = FALSE
end if if GetConnection(CONNECTION_PRIVATE) = FALSE then
bReturn = FALSE
end if if GetConnection(CONNECTION_ALL) = FALSE then
bReturn = FALSE
end if GetConnectionObjects = bReturn end function
function GetConnection(CONNECTION_TYPE)
DIM bReturn
DIM Connection
DIM Item
bReturn = TRUE if (CONNECTION_PUBLIC = CONNECTION_TYPE) then
set Connection = NetSharingManager.EnumPublicConnections(ICSSC_DEFAULT)
if (Connection.Count > 0) and (Connection.Count < 2) then
for each Item in Connection
set PublicConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
next
else
bReturn = FALSE

2012年03月05日 01点03分 6
level 7
hgmmym 楼主
end if
elseif (CONNECTION_PRIVATE = CONNECTION_TYPE) then
set Connection = NetSharingManager.EnumPrivateConnections(ICSSC_DEFAULT)
if (Connection.Count > 0) and (Connection.Count < 2) then
for each Item in Connection
set PrivateConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
next
else
bReturn = FALSE
end if
elseif (CONNECTION_ALL = CONNECTION_TYPE) then
set Connection = NetSharingManager.EnumEveryConnection
if (Connection.Count > 0) then
set EveryConnectionCollection = Connection
else
bReturn = FALSE
end if
else
bReturn = FALSE
end if if (TRUE = bReturn) then
if (Connection.Count = 0) then
Wscript.Echo("No " + CStr(ConvertConnectionTypeToString(CONNECTION_TYPE)) + " connections exist (Connection.Count gave us 0)")
bReturn = FALSE
'valid to have more than 1 connection returned from EnumEveryConnection
elseif (Connection.Count > 1) and (CONNECTION_ALL <> CONNECTION_TYPE) then
Wscript.Echo("ERROR: There was more than one " + ConvertConnectionTypeToString(CONNECTION_TYPE) + " connection (" + CStr(Connection.Count) + ")")
bReturn = FALSE
end if
end if
Wscript.Echo(CStr(Connection.Count) + " objects for connection type " + ConvertConnectionTypeToString(CONNECTION_TYPE)) GetConnection = bReturn
end function function ConvertConnectionTypeToString(ConnectionID)
DIM ConnectionString if (ConnectionID = CONNECTION_PUBLIC) then
ConnectionString = "public"
elseif (ConnectionID = CONNECTION_PRIVATE) then
ConnectionString = "private"
elseif (ConnectionID = CONNECTION_ALL) then
ConnectionString = "all"
else
ConnectionString = "Unknown: " + CStr(ConnectionID)
end if ConvertConnectionTypeToString = ConnectionString
end function
2012年03月05日 01点03分 7
level 7
hgmmym 楼主
我说愚人,长了点哦,闪着看看吧,是设置internet共享的
我不懂,愚人你懂吗?
2012年03月05日 01点03分 8
level 8
我只会手动设置共享连接...
[揉脸]
2012年03月05日 01点03分 9
level 7
hgmmym 楼主
你不觉得用脚本去连接是一种享受么?
你不是学校的网不用dr.com肯定不用这么恼火啦。。。。
我这要是开了共享会把端口占了,dr.com死活不让我登陆。。。。
所以每次都要去更改,很麻烦的你了不了哦?
好吧!现在就是发挥你的威力的时候了!就是现在!来吧。。。!!趁现在还年轻,帮我把这代码给解剖了吧!!愚人,变身成为超人吧!!!

2012年03月05日 02点03分 10
level 7
hgmmym 楼主
不对。。。@愚人陈 你回来。。。你看看上面那个脚本,不用研究功能。。。问题在于:它的对象都是在function里面create的,换了个function为何还能用呢?
就像:
function fun1()
set obj=createobject("对象")
end function
function fun2()
obj.FU*K
end function
你来解释一下吧。。。。
2012年03月09日 03点03分 11
level 8
那它就是全局变量吧
2012年03月09日 04点03分 12
level 7
hgmmym 楼主
回复12楼:全局的么?那它设这个变量干嘛?
2012年03月09日 04点03分 13
level 8
createobject("对象")
那就是获得对象吧
2012年03月09日 05点03分 14
level 7
hgmmym 楼主
2012年03月09日 06点03分 15
level 11
你的变量没有声明啊……
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim obj '这样就是全局变量,哪里都能用。
Function A()
  set obj = CreateObject("对象")
End Function
Function B()
  obj.方法
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function A()
  Dim obj '这样就是局部变量,只能在这用。
  set obj = CreateObject("对象")
  obj.方法
End Function
Function B()
  obj.方法 '若调用会报错
End Function

2012年03月10日 05点03分 16
level 7
hgmmym 楼主
额??声明哪个变量?
2012年03月11日 09点03分 17
1