private void Application_Startup(object sender, StartupEventArgs e) { Log.Info($@"WinHue {Assembly.GetExecutingAssembly().GetName().Version} started"); Log.Info($"User is running as administrator : {UacHelper.IsProcessElevated()}"); MainForm.MainWindow wnd = new MainForm.MainWindow(); double height = SystemParameters.WorkArea.Height * 0.75 >= MainWindow.MinHeight ? SystemParameters.WorkArea.Height * 0.75 : MainWindow.MinHeight; double width = SystemParameters.WorkArea.Width * 0.75 >= MainWindow.MinWidth ? SystemParameters.WorkArea.Width * 0.75 : MainWindow.MinWidth; MainWindow.Height = height; MainWindow.Width = width; switch (WinHueSettings.settings.StartMode) { case 0: wnd.Show(); wnd.WindowState = WindowState.Normal; break; case 1: wnd.Show(); wnd.WindowState = WindowState.Minimized; break; case 2: wnd.Show(); wnd.Hide(); break; default: wnd.Show(); wnd.WindowState = WindowState.Normal; break; } }
private void GetInfo() { string message = string.Empty; // Get and display whether the primary access token of the process belongs // to user account that is a member of the local Administrators group even // if it currently is not elevated (IsUserInAdminGroup). try { message += "Is user in admin group:" + UacHelper.IsUserInAdminGroup().ToString(); } catch { message += "Is user in admin group:N/A"; } // Get and display whether the process is run as administrator or not // (IsRunAsAdmin). try { message += " |Run as admin:" + UacHelper.IsRunAsAdmin().ToString(); } catch { message += " |Run as admin:N/A"; } // Get and display the process elevation information (IsProcessElevated) // and integrity level (GetProcessIntegrityLevel). The information is not // available on operating systems prior to Windows Vista. if (Environment.OSVersion.Version.Major >= 6) { // Running Windows Vista or later (major version >= 6). try { message += " |Is process elevated:" + UacHelper.IsProcessElevated().ToString(); } catch { message += " |Is process elevated:N/A"; } try { // Get and display the process integrity level. int IL = UacHelper.GetProcessIntegrityLevel(); message += " |Integrity level:"; switch (IL) { case NativeMethods.SECURITY_MANDATORY_UNTRUSTED_RID: message += "Untrusted"; break; case NativeMethods.SECURITY_MANDATORY_LOW_RID: message += "Low"; break; case NativeMethods.SECURITY_MANDATORY_MEDIUM_RID: message += "Medium"; break; case NativeMethods.SECURITY_MANDATORY_HIGH_RID: message += "High"; break; case NativeMethods.SECURITY_MANDATORY_SYSTEM_RID: message += "System"; break; default: message += "Unknown"; break; } } catch { message += "|Integrity level:N/A"; } } else { message += " |Is process elevated:N/A |Integrity level:N/A"; } Logger.Instance.AdddLog(LogType.Warn, message, this); }