2009年3月29日

Fix the Network problem for VMWare (Workstation) in Windows 7 (Semi-functional)

Problem: VMWare’s NAT/Bridged Network is not working in Windows 7
Possible Solution:
  • Set Client VM to use Bridge instead of NAT
  • In Virtual Network Editor:
    • disable NAT
    • Remove network adaptor for NAT uses.  e.g. vmnet8
    • Change the Subnet setting of VMnet1 (e.g. 192.168.0.0/255.255.255.0)
  • Run the patch script below:

Be default, W7 does not allow to run unsigned script due to security issue.
Please un the following command first:
  • Run “PowerShell V2” as administrator
  • Type “set-executionpolicy unrestricted”
  • Leave this PS windows as-is and create the script file “fix-vmnet-adapters.ps1”in your computer:
[Source Code]:
# see http://msdn2.microsoft.com/en-us/library/bb201634.aspx

# *NdisDeviceType  

# The type of the device. The default value is zero, which indicates a standard 
# networking device that connects to a network. 

# Set *NdisDeviceType to NDIS_DEVICE_TYPE_ENDPOINT (1) if this device is an 
# endpoint device and is not a true network interface that connects to a network. 
# For example, you must specify NDIS_DEVICE_TYPE_ENDPOINT for devices such as 
# smart phones that use a networking infrastructure to communicate to the local 
# computer system but do not provide connectivity to an external network.  

# Usage: run in an elevated shell (vista/longhorn) or as adminstrator (xp/2003). 

# PS> .\fix-vmnet-adapters.ps1 
# boilerplate elevation check 
$identity = [Security.Principal.WindowsIdentity]::GetCurrent() 
$principal = new-object Security.Principal.WindowsPrincipal $identity
$elevated = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) 
if (-not $elevated) { 
    $error = "Sorry, you need to run this script"
    if ([System.Environment]::OSVersion.Version.Major -gt 5) { 
        $error += " in an elevated shell."
    } else { 
        $error += " as Administrator."
    } 
    throw $error

function confirm { 
    $host.ui.PromptForChoice("Continue", "Process adapter?", 
        [Management.Automation.Host.ChoiceDescription[]]@("&No", "&Yes"), 0) -eq $true

# adapters key 
pushd 'hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}'
# ignore and continue on error 
dir -ea 0  | % { 
    $node = $_.pspath 
    $desc = gp $node -name driverdesc 
    if ($desc -like "*vmware*") { 
        write-host ("Found adapter: {0} " -f $desc.driverdesc) 
        if (confirm) { 
            new-itemproperty $node -name '*NdisDeviceType' -propertytype dword -value 1 
        } 
    } 

popd 
# disable/enable network adapters 
gwmi win32_networkadapter | ? {$_.name -like "*vmware*" } | % { 
    # disable 
    write-host -nonew "Disabling $($_.name) ... "
    $result = $_.Disable() 
    if ($result.ReturnValue -eq -0) { write-host " success." } else { write-host " failed." } 
    # enable 
    write-host -nonew "Enabling $($_.name) ... "
    $result = $_.Enable() 
    if ($result.ReturnValue -eq -0) { write-host " success." } else { write-host " failed." } 
  • Back to your PS, change the directory to your script location.
  • Type “.\fix-vmnet-adapters.ps1” to run the script
  • Anwser [Y] in the prompt for any vmware network adaptors (VMNet08)
  • Finally, reset the policy for secuirty reason:
  • Type: “ set-executionpolicy allsigned”
  • Exit the PowerShell
Reference:
VMWare VMNET Adapters Triggering Public Profile for Windows Firewall
易學易用的 Windows PowerShell (MSDN)
Semi-functional workaround for networking issues with VMWare Workstation 6.5 and Windows 7

沒有留言:

發佈留言