[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] vbs设置internet连接共享提示“没有权限”如何解决

关于网络共享给网卡的一个ics.vbs,这代码怎么弄求助
此代码是用来开启双网卡共享的,如果不行还求指导

代码如下,在XP下运行时可以的,但是在win10上就会报错如下,请问该如何解决
  1. '用法 cscript  /nologo ics.vbs "内网适配器名称" "外网网络连接名称" "off/on"
  2. OPTION EXPLICIT
  3. DIM ICSSC_DEFAULT, CONNECTION_PUBLIC, CONNECTION_PRIVATE, CONNECTION_ALL
  4. DIM NetSharingManager
  5. DIM PublicConnection, PrivateConnection
  6. DIM EveryConnectionCollection
  7. DIM objArgs
  8. DIM priv_con, publ_con
  9. DIM switch
  10. ICSSC_DEFAULT       = 0
  11. CONNECTION_PUBLIC   = 0
  12. CONNECTION_PRIVATE  = 1
  13. CONNECTION_ALL      = 2
  14. Main()
  15. sub Main( )
  16.     Set objArgs = WScript.Arguments
  17.     if  objArgs.Count = 3 then
  18. priv_con      = objArgs(0)   '内网适配器名称
  19. publ_con      = objArgs(1)   '外网网络连接名称
  20. switch        = objArgs(2)   '状态切换开关 on 为打开 off 相反
  21.         if Initialize() = TRUE then
  22.             GetConnectionObjects()
  23.             FirewallTestByDeviceName priv_con,publ_con
  24.         end if
  25.     else
  26.         if Initialize() = TRUE then
  27.             GetConnectionObjects()
  28.             FirewallTestByDeviceName "list","list"
  29.         end if
  30.     end if
  31. end sub
  32. sub FirewallTestByDeviceName(con1,con2)
  33. on error resume next
  34.     DIM Item
  35.     DIM EveryConnection
  36.     DIM objNCProps
  37.     DIM szMsg
  38.     DIM bFound1,bFound2
  39.     WScript.echo(vbCRLF)
  40.     bFound1 = false
  41.     bFound2 = false
  42.     for each Item in EveryConnectionCollection
  43.         set EveryConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
  44.         set objNCProps = NetSharingManager.NetConnectionProps(Item)
  45.         szMsg = "Name: "       & objNCProps.Name       & vbCRLF & _
  46.                 "Guid: "       & objNCProps.Guid       & vbCRLF & _
  47.                 "DeviceName: " & objNCProps.DeviceName & vbCRLF & _
  48.                 "Status: "     & objNCProps.Status     & vbCRLF & _
  49.                 "MediaType: "  & objNCProps.MediaType
  50.         if EveryConnection.SharingEnabled then
  51.             szMsg = szMsg            & vbCRLF & _
  52.                     "SharingEnabled" & vbCRLF & _
  53.                     "SharingType:  " & ConvertConnectionTypeToString(EveryConnection.SharingConnectionType)
  54.         end if
  55.         if objNCProps.DeviceName = con1 then
  56.             bFound1 = true
  57.             if EveryConnection.SharingEnabled = False and switch="on" then
  58.                 szMsg = szMsg & vbCRLF & "Not Shared... Enabling private connection share..."
  59.                 EveryConnection.EnableSharing CONNECTION_PRIVATE
  60.             end if
  61. if switch="off" then
  62. szMsg = szMsg & vbCRLF & "Shared... DisEnabling private connection share..."
  63. EveryConnection.EnableSharing CONNECTION_ALL
  64. end if
  65.         end if
  66.         if objNCProps.Name = con2 then
  67.             bFound2 = true
  68.             if EveryConnection.SharingEnabled = False and switch="on" then
  69.                 szMsg = szMsg & vbCRLF & "Not Shared... Enabling public connection share..."
  70.                 EveryConnection.EnableSharing CONNECTION_PUBLIC
  71.             end if
  72. if switch="off" then
  73. szMsg = szMsg & vbCRLF & "Shared... DisEnabling public connection share..."
  74. EveryConnection.EnableSharing CONNECTION_ALL
  75. end if
  76.         end if
  77.         WScript.Echo(szMsg & vbCRLF)
  78.     next
  79. if( con1 <> "list" ) then
  80. if( bFound1 = false ) then
  81. WScript.Echo( "Connection " & chr(34) & con1 & chr(34) & " was not found" )
  82. end if
  83. if( bFound2 = false ) then
  84. WScript.Echo( "Connection " & chr(34) & con2 & chr(34) & " was not found" )
  85. end if
  86. end if
  87. end sub
  88. function Initialize()
  89.     DIM bReturn
  90.     bReturn = FALSE
  91.     set NetSharingManager = Wscript.CreateObject("HNetCfg.HNetShare.1")
  92.     if (IsObject(NetSharingManager)) = FALSE then
  93.         Wscript.Echo("Unable to get the HNetCfg.HnetShare.1 object")
  94.     else
  95.         if (IsNull(NetSharingManager.SharingInstalled) = TRUE) then
  96.             Wscript.Echo("Sharing isn't available on this platform.")
  97.         else
  98.             bReturn = TRUE
  99.         end if
  100.     end if
  101.     Initialize = bReturn
  102. end function
  103. function GetConnectionObjects()
  104.     DIM bReturn
  105.     DIM Item
  106.     bReturn = TRUE
  107.     if GetConnection(CONNECTION_PUBLIC) = FALSE then
  108.         bReturn = FALSE
  109.     end if
  110.     if GetConnection(CONNECTION_PRIVATE) = FALSE then
  111.         bReturn = FALSE
  112.     end if
  113.     if GetConnection(CONNECTION_ALL) = FALSE then
  114.         bReturn = FALSE
  115.     end if
  116.     GetConnectionObjects = bReturn
  117. end function
  118. function GetConnection(CONNECTION_TYPE)
  119.     DIM bReturn
  120.     DIM Connection
  121.     DIM Item
  122.     bReturn = TRUE
  123.     if (CONNECTION_PUBLIC = CONNECTION_TYPE) then
  124.         set Connection = NetSharingManager.EnumPublicConnections(ICSSC_DEFAULT)
  125.         if (Connection.Count > 0) and (Connection.Count < 2) then
  126.             for each Item in Connection
  127.                 set PublicConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
  128.             next
  129.         else
  130.             bReturn = FALSE
  131.         end if
  132.     elseif (CONNECTION_PRIVATE = CONNECTION_TYPE) then
  133.         set Connection = NetSharingManager.EnumPrivateConnections(ICSSC_DEFAULT)
  134.         if (Connection.Count > 0) and (Connection.Count < 2) then
  135.             for each Item in Connection
  136.                 set PrivateConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
  137.             next
  138.         else
  139.             bReturn = FALSE
  140.         end if
  141.     elseif (CONNECTION_ALL = CONNECTION_TYPE) then
  142.         set Connection = NetSharingManager.EnumEveryConnection
  143.         if (Connection.Count > 0) then
  144.             set EveryConnectionCollection = Connection
  145.         else
  146.             bReturn = FALSE
  147.         end if
  148.     else
  149.         bReturn = FALSE
  150.     end if
  151.     if (TRUE = bReturn)  then
  152.         if (Connection.Count = 0) then
  153.             Wscript.Echo("No " + CStr(ConvertConnectionTypeToString(CONNECTION_TYPE)) + " connections exist (Connection.Count gave us 0)")
  154.             bReturn = FALSE
  155.         'valid to have more than 1 connection returned from EnumEveryConnection
  156.         elseif (Connection.Count > 1) and (CONNECTION_ALL <> CONNECTION_TYPE) then
  157.             Wscript.Echo("ERROR: There was more than one " + ConvertConnectionTypeToString(CONNECTION_TYPE) + " connection (" + CStr(Connection.Count) + ")")
  158.             bReturn = FALSE
  159.         end if
  160.     end if
  161.     Wscript.Echo(CStr(Connection.Count) + " objects for connection type " + ConvertConnectionTypeToString(CONNECTION_TYPE))
  162.     GetConnection = bReturn
  163. end function
  164. function ConvertConnectionTypeToString(ConnectionID)
  165.     DIM ConnectionString
  166.     if (ConnectionID = CONNECTION_PUBLIC) then
  167.         ConnectionString = "public"
  168.     elseif (ConnectionID = CONNECTION_PRIVATE) then
  169.         ConnectionString = "private"
  170.     elseif (ConnectionID = CONNECTION_ALL) then
  171.         ConnectionString = "all"
  172.     else
  173.         ConnectionString = "Unknown: " + CStr(ConnectionID)
  174.     end if
  175.     ConvertConnectionTypeToString = ConnectionString
  176. end function
复制代码
1

评分人数

    • pcl_test: 勿发笼统无意义的标题PB -2

回复 10# 523066680


    谢谢啊,好像可以了,非常感谢

TOP

回复 9# iK-


    建立批处理.bat  内容为 start xxx.vbs (就是你要运行的vbs

批处理的右键菜单应该有 用管理员身份运行

Win7是这样的

TOP

回复 8# 523066680


    拷贝到XP测试可以使用,但小弟的win10里用不了会报错

TOP

xp?

TOP

回复 5# lxzzr


    右键没有管理员运行的选项啊

TOP

回复 3# iK-


    淡定,别去搭理那些整天叽叽歪歪的人。

TOP

管理员权限试试看

TOP

我相信我的问题会解决的,哪怕只有我自己自学自通,祝福贵坛!

TOP

初到贵坛并不熟悉,看到DiamondbacK 反馈的帖子才觉得,发这篇帖子挺是对不起论坛的,我承认我是新手和伸手党也有点无耻,和老鸟的境界没得比,甚至最简单的代码都搞不定,小弟以前逛得论坛都没有bathome这么有技术性,此次也是接触了这个ICS共享脚本问题才来的,作为一个新手不敢要求太多,只求贵坛和气不想伤了大神们的心,其实我的问题已经不重要了,一天解决不了两天,总有解决的时候,论坛的长久才是关键,DiamondbacK大神的话在理,在下叨扰了
  PS:我也在百度搜罗了N多相关信息,弄得焦头烂额不得已才请教求助,有时候发帖求助只是想尽快解决问题吧,生活中接触代码的机会太少了,养成了伸手的习惯,惭愧惭愧
                                                                           ——不想删帖是想留句话,起码还有新手有自知之明

TOP

还请指出问题或者方向,谢谢了

TOP

返回列表