jagreygoose

Hotspot Windows 10

Dec 4th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #region Start WLANAutoConfig Service
  2. $WLANAutoConfig = Get-Service -Name "WlanSvc"
  3. if ($WLANAutoConfig.Status -ne 'Running')
  4. {
  5.     Write-Verbose "Starting WlanSvc"
  6.     Start-Service -Name "WlanSvc"
  7.     $WLANAutoConfig.WaitForStatus('Running','00:00:05')
  8. }
  9. #endregion Start WLANAutoConfig Service
  10.  
  11.  
  12. #region Remove existing hostednetwork configuration
  13. $HostedNetworkSettings = "HKLM:\SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\HostedNetworkSettings"
  14. If ((Test-Path $HostedNetworkSettings) -eq $true)
  15. {
  16.     Write-Verbose "Removing Hosted Network"
  17.     netsh wlan stop hostednetwork | out-null
  18.     netsh wlan set hostednetwork mode=disallow | out-null
  19.     Remove-Item "HKLM:\SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\HostedNetworkSettings" -Force
  20. }
  21. #endregion Remove Existing Hosted Network Configuration
  22.  
  23. #region Set & Start Hotspot
  24. netsh wlan set hostednetwork mode=allow ssid=Hotspot key=H0tspot1 | out-null
  25. netsh wlan start hostednetwork | out-null
  26. #endregion Set & Start Hotspot
  27.  
  28. #region Internet Connection Sharing
  29. # The Adapter you use to connect to the internet
  30. $PublicAdapterName = (Get-NetAdapter | Where-Object {$_.MediaConnectionState -eq 'Connected' -and $_.PhysicalMediaType -ne 'Unspecified'} | Sort-Object LinkSpeed | select -First 1).name
  31. # Your Hotspot
  32. $PrivateAdapterName = (Get-NetAdapter | Where-Object {$_.Virtual -eq $true -and $_.MediaConnectionState -eq 'Connected' -and $_.InterfaceDescription -eq "Microsoft Hosted Network Virtual Adapter"} | select -First 1).name
  33.  
  34. function InternetConnectionSharing
  35. {
  36.     [CmdletBinding()]
  37.     param (
  38.         [Parameter(Mandatory = $true)]
  39.         $sPublicConnectionName,
  40.         [Parameter(Mandatory = $true)]
  41.         $ssPrivateConnectionName,
  42.         [Parameter(Mandatory=$false)]
  43.         [Switch]$bEnable
  44.     )
  45.    
  46.     process
  47.     {
  48.         try
  49.         {
  50.             $oNetSharingManager = New-Object -ComObject HNetCfg.HNetShare
  51.         }
  52.         catch
  53.         {
  54.             regsvr32 /s hnetcfg.dll
  55.             $oNetSharingManager = New-Object -ComObject HNetCfg.HNetShare
  56.         }
  57.         $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
  58.         ForEach ($oItem in $oConnectionCollection)
  59.         {
  60.             $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
  61.             $objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
  62.             if ($objNCProps.name -eq $ssPrivateConnectionName)
  63.             {
  64.                
  65.                 if ($bEnable)
  66.                 {
  67.                     $EveryConnection.EnableSharing(1)
  68.                 }
  69.                 else
  70.                 {
  71.                     $EveryConnection.DisableSharing()
  72.                 }
  73.             }
  74.         }
  75.         $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
  76.         ForEach ($oItem in $oConnectionCollection)
  77.         {
  78.             $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
  79.             $objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
  80.             if ($objNCProps.name -eq $sPublicConnectionName)
  81.             {
  82.                
  83.                 if ($bEnable)
  84.                 {
  85.                    
  86.                     $EveryConnection.EnableSharing(0)
  87.                 }
  88.                 else
  89.                 {
  90.                     $EveryConnection.DisableSharing()
  91.                 }
  92.             }
  93.         }
  94.     }
  95.    
  96. }
  97. InternetConnectionSharing -sPublicConnectionName $PublicAdapterName -ssPrivateConnectionName $PrivateAdapterName -bEnable
  98. #endregion Internet Connection Sharing
Advertisement
Add Comment
Please, Sign In to add comment