# Copyright © 2008, Microsoft Corporation. All rights reserved. PARAM($printerName) # # Check whether the local printer is shared on the Homegroup # Import-LocalizedData -BindingVariable localizationString -FileName CL_LocalizationData Write-DiagProgress -activity $localizationString.progress_ts_homeGroup . .\CL_Utility.ps1 function Get-HomeGroupId() { [string]$hgid = $null; $regKey= Get-Item -path "HKLM:\SYSTEM\CurrentControlSet\Services\HomeGroupProvider\ServiceData" if ($regKey) { if ($regKey.SubKeyCount -eq 1) { $hgid = $regKey.GetSubKeyNames()[0]; } } return $hgid; } function Get-HomeGroupName() { $name = $null; [string]$hgid = Get-HomeGroupId; if ($hgid) { [string]$path = "HKLM:\SYSTEM\CurrentControlSet\Services\HomeGroupProvider\ServiceData\" + $hgid; [string]$item = "PeerGroupName"; $name = (Get-ItemProperty -Path $path -Name $item).$item } return $name; } function Test-HomeGroupName() { return [bool](Get-HomeGroupName) } function Check-IfDiscoveryEnable() { $Global:NET_FW_PROFILE2_PRIVATE = 0x0002 $Global:FirewallRulesHomeNetwork = @{"File and Printer Sharing" = "@FirewallAPI.dll,-28502"; # IDS_FW_FPS_GROUP #"Core Networking" = "@FirewallAPI.dll,-25000"; # IDS_FW_CORENET_GROUP "Network Discovery" = "@FirewallAPI.dll,-32752"} # IDS_FW_NETDIS_GROUP [bool]$issueDetected = $false $firewall = New-Object -COM HNetCfg.FwPolicy2 foreach ($RuleGroup in $Global:FirewallRulesHomeNetwork.Values) { if (-not($firewall.IsRuleGroupEnabled($Global:NET_FW_PROFILE2_PRIVATE, $RuleGroup))) { $issueDetected = $true break } } return $issueDetected } [bool]$result = $false if(-not (IsVirtualPrinter $printerName)) { #If HomeGroup is build up, then execute checking if(Test-HomeGroupName) { $printerSelected = GetPrinterFromPrinterName $printerName if(-not $printerSelected.NetWork -and -not (PrinterIsShared $printerName)) { $result = $true } else { #If NetWork and PrinterIsShared, then check the firewall configration (If Network and Printer Discovery has been Enable) if(Check-IfDiscoveryEnable) { $result = $true } else { if((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\HomeGroup\PrintingPreferences").Printers -ne 1) { $result = $true } } } } } if($result) { Update-DiagRootCause -id "RC_HomeGroup" -Detected $true -parameter @{ "PRINTERNAME" = $printerName} } else { Update-DiagRootCause -id "RC_HomeGroup" -Detected $false -parameter @{ "PRINTERNAME" = $printerName} }