When deploying applications to users there always comes a time when you need to detect an application is installed whilst in the user context. It becomes abit of an issue when checking files and folders exist in the users profile as by default SCCM runs with administrative privileged and not as the user. I’m sure there are a few way around this but the script i created below i found the most useful as it still work in Powershell version 2 which we had on our Windows 7 machines.
- Configure your application as to how you would like it to install
- Run the application whilst already logged in as a standard user (this is will ensure the application can run and isn’t stopped by any policy)
- Locate where the application is copying files too or creating files too
- Amend the below script with the location of the newly created files so SCCM can discover if the application is installed
[String] ${stUserDomain},[String] ${stUserAccount} = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name.split("\") $Path = "C:\PrintingInfo\${stUserAccount}.txt" If(Test-Path $Path) { "Installed" } Else { "" }
- The first line will get the logged in username and remove the <domain>\
For example: Contoso\Joe.Bloggs will be shortened to Joe.Bloggs
- Set the path
For example: C:\Users\${stUserAccount}\Desktop\File.txt
- Set the detection method as a Powershell Script and copy and paste the code
- Deploy and test!