Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- [switch] $Enable,
- [string] $Adapter = "Ethernet",
- [string] $SSID = "YOUR_SSID",
- [string] $Password = "YOUR_PASSWORD"
- )
- $adapter_v = "Microsoft Hosted Network Virtual Adapter"
- regsvr32.exe /s hnetcfg.dll
- $m = New-Object -ComObject HNetCfg.HNetShare
- $config_priv
- $c_pub = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq $Adapter }
- $config_pub = $m.INetSharingConfigurationForINetConnection.Invoke($c_pub)
- if ($Enable) {
- Write-Output "Starting"
- netsh.exe wlan set hostednetwork mode=allow ssid=$SSID key=$Password
- netsh.exe wlan start hostednetwork
- Start-Sleep -Seconds 1
- $c_priv = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).DeviceName -eq $adapter_v }
- $config_priv = $m.INetSharingConfigurationForINetConnection.Invoke($c_priv)
- $config_priv.EnableSharing(1)
- $config_pub.EnableSharing(0)
- } else {
- Write-Output "Stopping"
- $c_priv = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).DeviceName -eq $adapter_v }
- $config_priv = $m.INetSharingConfigurationForINetConnection.Invoke($c_priv)
- $config_pub.DisableSharing()
- $config_priv.DisableSharing()
- Start-Sleep -Seconds 1
- netsh.exe wlan stop hostednetwork
- }
- Write-Output ("Public interface: " + $config_pub.SharingEnabled + ", " + $config_pub.SharingConnectionType)
- Write-Output ("Private interface: " + $config_priv.SharingEnabled + ", " + $config_priv.SharingConnectionType)
- Write-Host -NoNewLine 'Press any key to continue...';
- $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement