Question: I am running a script that queries windows and its registry.
I'm trying to add a code where it can query both 64bit and 32bit versions of the OS.

So if it's a 32bit then it should look at HKLM\_SOFTWARE\_TEAMVIEWER
and if it's 64bit it should query at HKLM\_SOFTWARE\_WOW6432Node\_Teamviewer

So, how should this part look to query both locations depending on OS type?

```
$TVID = (Get-ItemProperty "HKLM:\SOFTWARE\TeamViewer").ClientID

```

This is the script:

```
    Param(
 [string]$ServerShare
)

$dom = $env:userdomain
$usr = $env:username
$Fullname = ([adsi]"WinNT://$dom/$usr,user").fullname

$TVID = (Get-ItemProperty "HKLM:\SOFTWARE\TeamViewer").ClientID
if (!$TVID) { $TVID = (Get-ItemProperty "HKLM:\SOFTWARE\TeamViewer\Version9").ClientID }

```

Answer: 
Apart from first detecting what bitness the computer uses, there is a simpler way I think by testing any of the two possible registry paths like:

```
# get the existing registry path (if any)
$regPath = 'HKLM:\SOFTWARE\TeamViewer', 'HKLM:\SOFTWARE\WOW6432Node\TeamViewer' | Where-Object { Test-Path -Path $_ }
if ($regPath) { 
    # we found the path, get the ClientID value
    $TVID = (Get-ItemProperty -Path $regPath).ClientID
}
else { 
    Write-Warning "TeamViewer registry path not found"
}

```
You can check WMI under Win32\_Processor and look at the process AddressWidth property to check your OS CPU AddressWidth.

```
#determine process version
[boolean]$is64bit = [boolean]((Get-WmiObject -Class "Win32_Processor" | 
   Where-Object {$_.DeviceID -eq 'CPU0'} | Select -ExpandProperty AddressWidth) -eq 64) 

if ($is64bit){
    #look here for 64 bit reg keys
    Write-Output "x64 bit os detected"
}
else{
    #look here for 32 bit reg keys
    Write-Output " 32 bit os detected"
}

```

And run on my system

> 
> x64 bit OS Detected
> 
> 
> 

Now all you need to do is merge your registry fetch code into the proper spots and you're on your way...