Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. param(
  2. [switch] $Enable,
  3. [string] $Adapter = "Ethernet",
  4. [string] $SSID = "YOUR_SSID",
  5. [string] $Password = "YOUR_PASSWORD"
  6. )
  7.  
  8. $adapter_v = "Microsoft Hosted Network Virtual Adapter"
  9. regsvr32.exe /s hnetcfg.dll
  10. $m = New-Object -ComObject HNetCfg.HNetShare
  11. $config_priv
  12. $c_pub = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq $Adapter }
  13. $config_pub = $m.INetSharingConfigurationForINetConnection.Invoke($c_pub)
  14.  
  15. if ($Enable) {
  16. Write-Output "Starting"
  17. netsh.exe wlan set hostednetwork mode=allow ssid=$SSID key=$Password
  18. netsh.exe wlan start hostednetwork
  19. Start-Sleep -Seconds 1
  20. $c_priv = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).DeviceName -eq $adapter_v }
  21. $config_priv = $m.INetSharingConfigurationForINetConnection.Invoke($c_priv)
  22. $config_priv.EnableSharing(1)
  23. $config_pub.EnableSharing(0)
  24. } else {
  25. Write-Output "Stopping"
  26. $c_priv = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).DeviceName -eq $adapter_v }
  27. $config_priv = $m.INetSharingConfigurationForINetConnection.Invoke($c_priv)
  28. $config_pub.DisableSharing()
  29. $config_priv.DisableSharing()
  30. Start-Sleep -Seconds 1
  31. netsh.exe wlan stop hostednetwork
  32. }
  33.  
  34. Write-Output ("Public interface: " + $config_pub.SharingEnabled + ", " + $config_pub.SharingConnectionType)
  35. Write-Output ("Private interface: " + $config_priv.SharingEnabled + ", " + $config_priv.SharingConnectionType)
  36.  
  37. Write-Host -NoNewLine 'Press any key to continue...';
  38. $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement