Link to home
Start Free TrialLog in
Avatar of alohadin
alohadin

asked on

Convert (short) Powershell script to VBS

Hi,

I am not that bad in Powershell scripting, but I really suck in VBS.
I need a custom detection method in SCCM which checks for a version number in the registry and check if a file DOES NOT exist.

If version number = X AND file does not exist Echo Installed

The file and the registry keys might be in different places depending on OS bit.

Can someone help with converting this Powershell Script to VBS?
Reason why I don't use the Powershell script for the detection method is because it needs to be signed. I would rather work with a VBS.


[boolean]$Is64Bit = [boolean]((Get-WmiObject -Class 'Win32_Processor' -ErrorAction 'SilentlyContinue' | Where-Object { $_.DeviceID -eq 'CPU0' } | Select-Object -ExpandProperty 'AddressWidth') -eq 64)
        
If ($Is64Bit -eq $True)
{
    [string]$appInstalledVersion = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Citrix\PluginPackages\XenAppSuite\ICA_Client' -ErrorAction SilentlyContinue | select -ExpandProperty Version
    [boolean]$ssonsvr = Test-Path ("${env:ProgramFiles(x86)}\Citrix\ICA Client\ssonsvr.exe")
}
Elseif ($Is64Bit -ne $True)
{
    [string]$appInstalledVersion = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Citrix\PluginPackages\XenAppSuite\ICA_Client' -ErrorAction SilentlyContinue | select -ExpandProperty Version
    [boolean]$ssonsvr = Test-Path ("$env:ProgramFiles\Citrix\ICA Client\ssonsvr.exe")
}


if (($ssonsvr -eq $False) -and ($appInstalledVersion -eq "14.7.0.13011"))
{
    Write-Host "installed"
}
else
{
}

Open in new window

Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Should be somewhat close...
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

boolIs64Bit = false
If objShell.Environment("SYSTEM")("PROCESSOR_ARCHITECTURE") = "AMD64" Then
    boolIs64Bit = true
End If

strRegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\PluginPackages\XenAppSuite\ICA_Client\Version"
strPath = objShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%\Citrix\ICA Client\ssonsvr.exe")

If boolIs64Bit = true Then
    strRegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix\PluginPackages\XenAppSuite\ICA_Client\Version"
    strPath = objShell.ExpandEnvironmentStrings("%PROGRAMFILES%\Citrix\ICA Client\ssonsvr.exe")
End If

strVersion = objShell.RegRead(strPath)

If objFSO.FileExists(strPath) = false And strVersion = "14.7.0.13011" Then
    WScript.Echo "Installed"
End If

Open in new window

By the way, in PowerShell you can use the environment variable $env:PROCESSOR_ARCHITECTURE to determine if you're in 32-bit or 64-bit mode. Personally I prefer this method though:
if ([IntPtr]::Size -eq 8) {
    Write-Host '64-bit process'
} elseif ([IntPtr]::Size -eq 4) {
    Write-Host '32-bit process'
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Took me all my time to remember that much VbScript. Nice work Bill, very tidy.
Avatar of Bill Prew
Bill Prew

Sadly(?) I still spend too much time in VBScript, although I still like it as a scripting tool language.  Just don't tell Qlemo :-).


»bp
Avatar of alohadin

ASKER

Thank you both very much.
Bill, that script does exactly what it should. Thank you so much. You have saved me one day!

Chris,
I know about the variable $env:PROCESSOR_ARCHITECTURE but that line I use for a couple of years now.
Found it somewhere a long time ago when I just started with PS and I use it every time I need it.
Welcome, glad that was helpful...


»bp
Hi Bill,

Forgot to mention...
There is a tiny mistake in the TestPath function.
Can you change it to this in your original post so others who stumble on this topic have correct answer:
Function TestPath(strPath)
    TestPath = objFSO.FileExists(strPath)
End Function

Open in new window




You had this:
Function TestPath(strPath)
    TestPath = objFSO.FileExists(strDataFile)
End Function
Done.

»bp