Windows 8 hostednetwork and ICS issue, no internet access

10,238

Solution 1

Ok. Sharing and using hostednetwork can be a stress. This is how i've done it.
Using command line and powershell to achieve needed goals.
Sure it could be achieved with powershell only but hey ... probably later.

Save the following (BATCH FILE) file as a *.bat. Change accordingly where it reads

YOURPATH\YOURFILE.ps1

Save the second file (PS1 FILE) with name you supplied in previous step

"YOURFILE.ps1"

Alter the first section of ps1 file and change adapters accordingly with your system

$wifi = "description='Broadcom 4313 802.11b/g/n'"
$ethernet = "description='Intel(R) 82577LC Gigabit Network Connection'"

You can get yours running the following command in powershell

Get-WmiObject win32_networkadapterconfiguration | select description

Its supposed to have only one connected interface either physical (ethernet) or wireless.

Run batch file as administrator.

Additionaly you can start the process from the windows explorer context menu for simplicity.
For that use the third file and save it as a reg and run it or alter manually from the sample
Needless to say that its necessary to alter where it reads

YOURPATH\BATCHFILE.bat

Enjoy. Cheers

-------------------------------------------- BATCH FILE

@echo off
echo Current Settings (netsh wlan show hostednetwork):
netsh wlan show hostednetwork | findstr -i status
rem echo               Current Settings
rem echo            ######################
rem echo .
echo SSID Name
netsh wlan show hostednetwork | findstr -i " ssid "
netsh wlan show hostednetwork setting=security
echo            ######################
echo            #                    #
echo            # Please select      #
echo            #                    #
echo            #   [E] Edit     #
echo            #   [S] Start    #
echo            #   [Q] Stop     #
echo            #   [V] View     #
echo            #                    #
echo            ######################
choice /C ESQV 
IF errorlevel 4 goto TetherView
IF errorlevel 3 goto TetherStop
IF errorlevel 2 goto TetherStart
IF errorlevel 1 goto TetherEdit
rem GOTO TetherEnd

:TetherEdit
echo "Please enter SSID:" 
set /p SSID=
echo "SSID Password"
set /p PassWord=
echo %SSID% %PassWord%
netsh wlan set hostednetwork mode=allow ssid=%SSID% key=%PassWord%
netsh wlan start hostednetwork
GOTO TetherEnd

:TetherStart
netsh wlan start hostednetwork
powershell -file YOURPATH\ICS-Control.ps1 enable
GOTO TetherEnd

:TetherStop
netsh wlan stop hostednetwork
powershell -file YOURPATH\ICS-Control.ps1 disable
GOTO TetherEnd

:TetherView
cls
netsh wlan show hostednetwork | findstr -i status
echo SSID Name
netsh wlan show hostednetwork | findstr -i " ssid "
netsh wlan show hostednetwork setting=security
echo Connected clients
arp -a | findstr -i 192.168.173 | findstr /V 255 | findstr /V 192.168.173.1
GOTO TetherEnd

:TetherEnd
@PAUSE

--------------------------------------------PS1 FILE

#Change accordingly
$wifi = "description='Broadcom 4313 802.11b/g/n'"
$ethernet = "description='Intel(R) 82577LC Gigabit Network Connection'"

#Doesnt change so no need to alter. Detects what interface is connected (should be only one)
$netAdapter = get-wmiobject win32_networkadapter -filter "netconnectionstatus = 2" | select netconnectionid, name, InterfaceIndex, netconnectionstatus 
if ($netAdapter.netconnectionid -cmatch "Wi-Fi"){$publicAdapter = $wifi} else {$publicAdapter = $ethernet}
$privateAdapter = "description='Microsoft Hosted Network Virtual Adapter'"

Function Var1ICSenable
{
    $virtualAdapter = Get-WMIObject win32_networkadapterconfiguration | where {$_.ServiceName -eq "vwifimp"} | % {$_.GetRelated('win32_networkadapter')} | Select -ExpandProperty Name
    $vars1 = $privateAdapter
    $Adapter0 = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter $vars1 | select description
    $mAdapter3 = $Adapter0 -replace "@{description=",""
    $mAdapter3 = $mAdapter3 -replace "}","" 
    $mAdapter4 = "description='$mAdapter3'"
    $mAdapter5 = gwmi win32_networkadapter -Filter $mAdapter4 |select netconnectionid
    $mAdapter5 = $mAdapter5 -replace "@{netconnectionid=",""
    $global:mAdapter5 = $mAdapter5 -replace "}",""
}

Function Var2ICSenable
{
    $vars2 = $publicAdapter
    $Adapter1 = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter $vars2 | select description
    $mAdapter = $Adapter1 -replace "@{description=",""
    $mAdapter = $mAdapter -replace "}","" 
    $mAdapter1 = "description='$mAdapter'"
    $mAdapter2 = gwmi win32_networkadapter -Filter $mAdapter1 |select netconnectionid
    $mAdapter2 = $mAdapter2 -replace "@{netconnectionid=",""
    $global:mAdapter2 = $mAdapter2 -replace "}",""
}

function EnableDisableICS
{

    $bFound = $FALSE

    $oNetSharingManager = new-object -comobject HNetCfg.HNetShare
     if ($oNetSharingManager -eq $null)
        {
            write-host "Unable to get the HNetCfg.HnetShare object."
            Exit
        }    
    if ($oNetSharingManager.SharingInstalled -eq $null)
        {
            write-host "Sharing is not available on this platform."
            Exit
        }

    $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
    foreach ($oItem In $oConnectionCollection)
    {
        $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
        $objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
        If ($objNCProps.name -eq $sPrivateConnectionName)
        {
            $bFound = $True
            write-host "Setting ICS Private to " $bEnable " on connection: " $objNCProps.name
            If ($bEnable -eq "true")
                {
                    $EveryConnection.EnableSharing(1)
                }
            Else
                {
                    $EveryConnection.DisableSharing()
                }
        }
    }

    $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
    foreach ($oItem In $oConnectionCollection)
    {
        $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
        $objNCProps = $oNetSharingManager.NetConnectionProps($oItem)

        If ($objNCProps.name -eq $sPublicConnectionName)
        {
           $bFound = $True
           write-host "Setting ICS Public to " $bEnable " on connection: " $objNCProps.name
            If ($bEnable -eq "true")
            {
                $EveryConnection.EnableSharing(0)
            }
            Else
            {
                $EveryConnection.DisableSharing()
            }
        }
    }

    If ($bFound -eq $null)
    {
       write-host "Unable to find the connection " + $sPublicConnectionName
    }

}

Function EnableSharing
{
    #regsvr32 /s hnetcfg.dll

        # Variables to enable and disable ICS
        Var1ICSenable
        Var2ICSenable
        $global:firstICSvar = $global:mAdapter2
        $global:secondICSvar = $global:mAdapter5

    $benable = "true"
    $sPublicConnectionName = $global:firstICSvar
    $sPrivateConnectionName = $global:secondICSvar

    $mstr = $sPublicConnectionName + " " + $sPrivateConnectionName + " " + $bEnable
    EnableDisableICS $mstr
}

Function DisableSharing
{
    #regsvr32 /s hnetcfg.dll

        # Variables to enable and disable ICS
        Var1ICSenable
        Var2ICSenable
        $global:firstICSvar = $global:mAdapter2
        $global:secondICSvar = $global:mAdapter5

    $benable = "false"
    $sPublicConnectionName = $global:firstICSvar
    $sPrivateConnectionName = $global:secondICSvar

    $mstr = $sPublicConnectionName + " " + $sPrivateConnectionName + " " + $bEnable
    EnableDisableICS $mstr
    #write-host "TESTE" $mstr
}

    if ($args[0] -eq "enable"){EnableSharing}else{DisableSharing}

--------------------------------------------REG FILE

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas]
@="Tether (Hosted Network)"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas\command]
@="cmd.exe /c YOURPATH\BATCHFILE.bat"

Solution 2

Because this post is so high in the search I'll repeat myself here, maybe it helps.

  1. As mentioned in several posts I've enabled the routing and remoting service.

but that was only part of the solution, the internet still didn't work. So when checking the hosted wireless adapter settings I noticed that the IP Address was static but there wasn't any DNS Server entry. So here comes part 2 of the solution.

  1. Edit hosted network IPv4 Settings. Enter a valid DNS Server (Use any open dns server available, e.g. google's is 8.8.8.8)

That worked for me.

Share:
10,238

Related videos on Youtube

Eric
Author by

Eric

Updated on September 18, 2022

Comments

  • Eric
    Eric over 1 year

    The Issue

    Trying to host a network to extend the range of my home wifi network, instead of going out and spending 50 bucks on a wifi extender.

    Anyways my issue occurs in that my hostednetwork does not have internet access no matter what I've tried.


    What I've done

    Setting up

    First things first, I started by starting up ICS first, as I need the DHCP server to assign IP's in the range of 192.168.137.x on my to be hostednetwork.

    I then set up a hostednetwork via command line like so:

    netsh wlan set hostednetwork ssid="Test" key="password"
    netsh wlan start hostednetwork
    

    It works fine, I was able to test this connection by syncing my phones music collection 'over wifi' (DoubleTwist AirSync). I state this because I had originally started my hostednetwork first, which starts ICS in standalone mode, which then assigns IP's in 192.168.173.x instead, and DoubleTwist could not find my phone. Though I could've just released and renewed IP's once I had the ICS full mode started.

    Anyways next step I took. I went into to network adapter settings, right clicked my wifi adapter that's connected to my home network and enabled shared internet connection with the newly created hostednetwork.

    Nada, nothing happens.


    System Information

    IPconfig /all:

    IPconfig /all

    Network Adapter Settings:

    Network Adapter Settings


    End

    I have no idea why this isn't working, every guide and support forum I've googled have done exactly what I have and it's worked for them. I'm guessing it's because I'm trying to share internet from the same adapter as I am broadcasting from. I would love to be able to broadcast from a seperate dongle (I have a spare) but windows doesn't support that natively.

    • Gabriel Fair
      Gabriel Fair about 9 years
      Did you ever find a solution?
    • Eric
      Eric about 9 years
      @gabriel fair No, I gave up hahah sorry.
    • Gabriel Fair
      Gabriel Fair about 9 years
      Yeah I did as well. lol
  • Eric
    Eric about 10 years
    Which is what I have done.
  • Eric
    Eric about 10 years
    Scratch that apparently it has been working. Windows says there's internet connectivity on it. My phone just doesn't think there is.
  • Fadarrizz
    Fadarrizz about 10 years
    I'm sorry I read it too fast. It's a whole other problem if your phone doens't see the connection. What kind of phone do you have? If have encountered some problems as well. My phone can't connect to my network.
  • David d C e Freitas
    David d C e Freitas over 7 years
    For me to get a DNS entry, I had to do this: see this answer: superuser.com/a/1051122/35525