Does TK have the ability to detect X before running the install?

I am using the TK to deploy a piece of software.
During this deployment it also makes sure it detects all the users and deletes a specific registry key (just to ensure it is gone)

What I am hoping for is during the Pre-Installation phase it will detect if a certain registry key is present, if it is not, then to go ahead with the installation, but if it is detected then do not install the software.

The software is being deployed in the SYSTEM context, but the key is located in HKCU. I tried to make this work in SCCM using APP, but it will install regardless and then just keeps installing.

Hi Kevin,

Basically, you’re set. PowerShell can access the registry and the Toolkit collects the user info.

Scenario #1: checking for the registry key in HKLM

In the pre-install phase part of the script, put something like this in the script:
$regKeyFound = Test-Path “HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome”

And in the install phase part of the script, put something like this in the script:
If ($regKeyFound) {

# INSTALL

} Else {

# DO SOMETHING ELSE

}

Scenario #2: checking for the registry key in HKU

In the pre-install phase part of the script, put something like this in the script:
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$userSID = (Get-LoggedOnUser).SID
$regKeyFound = Test-Path “HKU:$userSID\Software\Mozilla”

The install phase part of the script is the same:
If ($regKeyFound) {

# INSTALL

} Else {

# DO SOMETHING ELSE

}

Let me know if this is working out for you.

Cheers,
Marin

You want to make changes to a hive you don’t really have the full path to yet (HKCU would be HKU\S-1-5-18 if running under NT-Authority\System). The toolkit has a function called Get-LoggedOnUser which seems to be helpful in this scenario.

Description: Get session details for all local and RDP logged on users using Win32 APIs. Get the following session details: NTAccount, SID, UserName, DomainName, SessionId, SessionName, ConnectState, IsCurrentSession, IsConsoleSession, IsUserSession, IsActiveUserSession, IsRdpSession, IsLocalAdmin, LogonTime, IdleTime, DisconnectTime, ClientName, ClientProtocolType, ClientDirectory, ClientBuildNumber

Without having this tested, I’m thinking you could do the following to access logged on user’s registry hive
$LoggedOnUser = Get-LoggedOnUser
$LoggedonUserSID = $LoggedOnUser.SID
if((Test-RegistryValue -Key “HKU:$LoggedonUserSID\Software<PATH TO KEY>” -Value “YourString”) -ne “Desired value”)
{

do changes here if reg string contains invalid value

}
else
{

do changes if value is valid or do nothing (continue with script)

}

This would of course require the script to be launched when a user actually is logged on (SCCM has support for this).

If it’s on a terminal server you would have the potential risk of having multiple users logged on, which would require you to run the above in a loop for each SID. Something like
foreach($sid in $LoggedOnUser.SID)
{
Test-RegistryValue -Key “HKU:$SID<PATH TO KEY>”
}

Again. I haven’t tested this out, but with a little testing I’m sure you will solve this deployment :slight_smile:

HTH!

Another small note: maybe test-registryvalue should be replaced with Get-RegistryKey… It’s up to what ever kind of check you want to do.

And an extra note: I’m a fool for only reading the first part of Marin’s reply haha… it’s all there basically…

Thanks for the info guys. I will check this out and see what I can do.

Will report back if I have anymore questions.