I have an ASPX web application written in C# in which I call a desktop application running on the cloud web server machine from a button on the web page using a ProcessStartInfo object. The application (SetTags) was failing with a security violation when trying to access a Registry key in HKCU/Software. To get around this, I changed the ProcessStartInfo verb from 'open' to 'runas' and set UseShellExecute to true, which should start the desktop application with Administrator privilege. UAC has been turned off on the cloud server machine. However, the desktop application crashes with a security exception recorded in the event log as follows
Exception Info: System.Security.SecurityException
at System.ThrowHelper.ThrowSecurityException(System.ExceptionResource)
at Microsoft.Win32.RegistryKey.OpenSubKey(System.String, Boolean)
at Global.Common..cctor()
Exception Info: System.TypeInitializationException
at Global.Common.ShowUserError(System.String, System.String)
at SetTagsNS.Program.Main(System.String[])
The crash happens before any data can be written to a log file and the Common.ShowUserError code does not contain any explicit Registry calls. It is as follows:
public static void ShowUserError(string sMsg, string sCaption = "")
{
if (CallingArgs == null) MessageBox.Show(sMsg, sCaption);
else
if (CallingArgs.GetUpperBound(0) != -1)
{
if(sErrFile!="")
{
StreamWriter Err = new StreamWriter(sErrFile,true); // 2nd param = true to append error
// Redirect standard error from the console to the error file.
Console.SetError(Err);
Err.Close();
}
else Console.Error.Write(sMsg);
}
else MessageBox.Show(sMsg, sCaption);
}
The desktop application is built in C# using VS2013 as Windows application rather than a console application, but with the option of not showing any windows if it is launched with command line arguments. A console is attached to the application to record messages when the application is launched with command line arguments. This is done in order to use the same code base for a web application and a desktop application.
The desktop application can be run successfully on the cloud web server (Server2016 OS) from an administrator account from a .bat file using the same parameters as used when it is called from aspx page. runas /trustlevel=0x20000 is used to make the application run with only basic user privilege
What can I do to allow to allow the desktop application access to the Registry when it is called from an aspx page?