/build/static/layout/Breadcrumb_cap_w.png

Scripting to modify compatibility mode on an EXE

I have a peice of software that I am trying to automate the install with SCCM 2012 R2. Everything install correctly with the MSI + MST, however in order for the program to work correctly, the program needs to be ran in Windows XP SP3 Compatiblity Mode.  To fix this I created a VB script to write to correct location in the registry, that will set the correct setting, however the app does not recognize the key.  It will recognize the key but only after I reboot the PC, and then go into the Compatiblity tab of the EXE in question.  I don't need to modify or add any thing, just go into the tab(when I do, it does show that the compatibily mode is set to WINXPSP3), after that the program opens in the correct mode.  I have attached the function that is creating the regkey.

 

Set objRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\"
strKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
strValue = "WINXPSP3"

If bl64bit = True Then
strValueName = "C:\Program Files (x86)\program.exe"
Else
strValueName = "C:\Program Files\Program.exe"
End If

intkeyReturn = objRegistry.CreateKey(HKLM, strKey)
If intkeyReturn = 0 Then
intkeyReturn = objRegistry.SetStringValue(HKLM,strKeyPath,strValueName,strValue)
End If

0 Comments   [ + ] Show comments

Answers (3)

Posted by: BHC-Austin 10 years ago
4th Degree Black Belt
0

I had similar issues at one point. Especially when running on a 64-bit machine. What I found was that the VBScript was writing to the Wow6432Node instead of in the base HKLM\SOFTWARE. I had to use the code below to force writing to the correct registry location:

Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", nbits
objCtx.Add "__RequiredArchitecture", True
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")rpath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
if nbits = 64 Then
 exepath = "C:\Program Files (x86)\Program.exe"
Else
 exepath = "C:\Program Files\Program.exe"
end if
' Use ExecMethod to call the SetStringValue method
Set Inparams = objStdRegProv.Methods_("SetStringValue").Inparameters
Inparams.Hdefkey = HKEY_LOCAL_MACHINE
Inparams.Ssubkeyname = rpath
Inparams.Svaluename = exepath
Inparams.Svalue = "RUNASADMIN"
Set Outparams = objStdRegProv.ExecMethod_("SetStringValue", Inparams,,objCtx)
Essentially, still using the SetStringValue, but inserting addtional params that tell it to write to either the 64-bit or 32-bit registryl
Posted by: Visalakshi 10 years ago
Orange Senior Belt
0

Try HKCU registry to set the compatibility. It may work without reboot.

Posted by: mattski 10 years ago
Second Degree Green Belt
0

Have you tried using the Application Compatibilty Tool and shim the app making it run as admin?

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ