win7 cmd方式设置无线虚拟wifi
1、确认你的win7系统是双网卡,最好有线网卡和无线网卡都有,并且无线网卡是支持承载网络的。
#查看是否支持承载网络, 否,非老版网卡,就是网卡驱动有问题,自己想法子去更新
netsh wlan show hostednetwork
如果无线网卡不支持承载网络,下面的就不用看了!!!
#设置wifi热点(这里只设置下,没必要启动)
netsh wlan set hostednetwork mode=allow ssid=wifi key=1234567890 注意:上面的1234567890 就是连接用的密码
执行后 你的网络属性里会多出一个“无线网络连接 2”的虚拟连接,这个“无线网络连接 2”在后面cmd命令行启动网络连接共享时会用到
2、确认win7的系统服务已经开启
查看Internet Connection Sharing (ICS)和Windows Firewall两个服务是否开启,
如果没开启请开启,并设置自动启动或通过命令行方式启动。(连接网络共享需要)
#开启Internet Connection Sharing (ICS)服务 net start sharedaccess
#开启Windows Firewall服务 net start MpsSvc
#设置ics服务自启动
sc config sharedaccess start= auto
#设置Windows Firewall服务自启动 sc config MpsSvc start= auto
停止服务就把start改为stop,不多说了,不会就百度吧
3、确认你的网络连接的名称 下面是我的网络
有线网络名称:本地连接
无线网络连接名称:无线网络连接
虚拟的无线网络连接名称:无线网络连接 2
ics.vbs脚本4、用下面的代码建立vbs脚本文件ics.vbs 或者点击用记事本打开并保存为ics.vbs。(此vbs从网络获取,对付出劳动的前辈说声谢谢),有的从网上下载下来报错,原因是elseif写成了 else if多了个空格,注意就是了。 '↓运行命令↓
'cscript /nologo ics.vbs \无线网络连接\本地连接\
'将以上代码保存为*.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 \ end if
szMsg = \name of the private and public connections as the argument.\vbCRLF & _
\ \& WScript.scriptname & \\& chr(34) & \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 = \ \
\ \ \ if EveryConnection.SharingEnabled then
szMsg = szMsg & vbCRLF & _
\ \
ConvertConnectionTypeToString(EveryConnection.SharingConnectionType) end if
if objNCProps.Name = con1 then bFound1 = true
if EveryConnection.SharingEnabled = False and switch=\then
szMsg = szMsg & vbCRLF & \Shared... Enabling private connection share...\
WScript.Echo(szMsg)
EveryConnection.EnableSharing CONNECTION_PRIVATE szMsg = \
elseif(switch = \
szMsg = szMsg & vbCRLF & \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=\then
szMsg = szMsg & vbCRLF & \connection share...\
WScript.Echo(szMsg)
EveryConnection.EnableSharing CONNECTION_PUBLIC szMsg = \
elseif(switch = \
szMsg = szMsg & vbCRLF & \DisEnabling public connection share...\ WScript.Echo(szMsg)
EveryConnection.EnableSharing CONNECTION_ALL
end if end if
WScript.Echo(szMsg & vbCRLF & vbCRLF) next
if( con1 <> \
if( bFound1 = false ) then
WScript.Echo( \was not found\ end if
if( bFound2 = false ) then
WScript.Echo( \was not found\ end if end if end sub
function Initialize() DIM bReturn bReturn = FALSE
set NetSharingManager =
Wscript.CreateObject(\
if (IsObject(NetSharingManager)) = FALSE then
Wscript.Echo(\ else
if (IsNull(NetSharingManager.SharingInstalled) = TRUE) then Wscript.Echo(\ 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