3

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 }

3 Answers3

1

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"
}
Theo
  • 57,719
  • 8
  • 24
  • 41
0

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...

FoxDeploy
  • 12,569
  • 2
  • 33
  • 48
0

The easiest way to check OS bittness is to use .net.

[Environment]::Is64BitOperatingSystem
Aaron
  • 563
  • 3
  • 13