问题
Environment: Windows Server 2008 R2 64 bit
I have a program that works with Windows Server 2003 SP1 compatibility mode. However, when I try to execute this program using C#, the program errors out.
I think it is because it is not running in compatibility mode when invoked from another program. I use Process.Start(pathToExe)
from my code to start this program.
I tried to run the calling program in compatibility mode to check if this would make the program run correctly.
Please note that I have set the program set to compatibility from Properties | Compatibility.
回答1:
I am not sure if I understand your problem exactly, but if you want to run the Program always in the Compatibility mode you can set the registry to make it work so.
Registry Key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
Add a new String entry with,
Name : Your Application Path in Full.
Type: REG_SZ
Data : Required Compat Value. I think it is WIN2003
OR WIN2003SP1
in your case.
Example:
C:\Program Files\System32\Notepad.exe REG_SZ WIN2003
You can check for the current OS version you are running under and you can set and unset this registry value before calling the program.
来源:https://stackoverflow.com/questions/12249263/how-to-execute-a-program-in-compatibility-mode-from-code