When you deploy a script with environment manager it is not easy to check if it has run successfully or not. In my situation I had to set a REG_NONE value in HKCU so that SAP files would open instead of the save as option. I exported the registry key, imported it into Environment Manager and ran the action but the subkey SAPGUI.Shortcut.File was not created.

A Reg_None value is not recognized because you can’t set or create it with Windows Group Policy. So I created a script that would create the key and set the value; as shown in the figure below:

custom_action_apply_environment_variables_to_configuration

If you are deploying the script with the condition desktop created and the user has to input data you need to uncheck “Prevent script from running interactively” option. If you check this option the script will run hidden in the background.

When I first ran the script the key was not created. I checked the Appsense logs and the Windows Event Viewer but no errors or warnings were logged. I added the Powershell code below to my script:

Write-Host
Write-Host “Press any key to continue …”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)
Write-Host

This code adds the function that a key has to be pressed to end the script.

So my new script was:

cd hkcu:
$Params = @{
Path =’\Software\Microsoft\Windows\Shell\AttachmentExecute\{0002DF01-0000-0000-C000000000000046}’
Name =’SAPGui.Shortcut.File’
PropertyType =’None’  # Microsoft.Win32.RegistryValueKind
Value =[System.BitConverter]::GetBytes(0)
}
New-ItemProperty @Params
Write-Host
Write-Host “Press any key to continue …”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)
Write-Host

 When I ran the script again and the script waited to finish for the key press I saw the problem. The starting directory was H:\ instead of C:\. I added the command cd C:\ to the first line of the script, ran it again and the key created successfully.

Sources: Colleague Kid Kooijmans, http://appsensebigot.blogspot.be/