static void Main() { bool createdNew; mutex = new Mutex(true, Application.ProductName, out createdNew); if (!createdNew) { //App is already running! Exiting the application MessageBox.Show("FormFiller is already running\nPress Alt + ~ to activate it", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //Added as a solution for blurry fonts problem //Makes fonts sharp and clear if (Environment.OSVersion.Version.Major >= 6) { SetProcessDPIAware(); } if (ProcessChecker.IsOnlyProcess(Application.ProductName)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new CVForm()); } }
static void Main() { if (ProcessChecker.IsOnlyProcess("Program Window Text")) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }
static void Main() { if (!ProcessChecker.IsOnlyProcess("ProActive Agent Control")) { return; } // Guest accounts Check if the current user have admin rights WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); if (principal.IsInRole(WindowsBuiltInRole.Guest)) { // report error and exit MessageBox.Show("Guest users cannot run the ProActive Agent Control.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check if this application is already running Process[] alreadyRunningProcesses = Process.GetProcessesByName("AgentForAgent"); if (alreadyRunningProcesses != null && alreadyRunningProcesses.Length > 1) { return; } // Check agent and config locations in the registry (setted during agent installation) // ie check if the agent was correctly installed try { RegistryKey agentKey = Registry.LocalMachine.OpenSubKey(Constants.REG_SUBKEY); if (agentKey == null) { // Cannot continue, report error message box and exit MessageBox.Show("Can not open the following registry subkey (LocalMachine) " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string agentLocation = (string)agentKey.GetValue(Constants.INSTALL_LOCATION_REG_VALUE_NAME); if (agentLocation == null) { // report error and exit MessageBox.Show("Cannot get the agent location in " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the registry key agentKey.Close(); return; } string configLocation = (string)agentKey.GetValue(Constants.CONFIG_LOCATION_REG_VALUE_NAME); if (configLocation == null) { // report error and exit MessageBox.Show("Cannot get the config location in " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the registry key agentKey.Close(); return; } string logsDirectory = (string)agentKey.GetValue(Constants.LOGS_DIR_REG_VALUE_NAME); if (logsDirectory == null) { // report error and exit MessageBox.Show("Cannot get the logs directory in " + Constants.REG_SUBKEY + ". It appears that the agent might not have been installed properly.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the registry key agentKey.Close(); return; } // Close the registry key agentKey.Close(); // Connect to the agent service ServiceController sc = null; try { sc = new ServiceController(Constants.SERVICE_NAME); } catch (Exception e) { MessageBox.Show("Could not connect to the service " + Constants.SERVICE_NAME + ". It appears that the agent might not have been installed properly. " + e.ToString(), "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Launch the GUI Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AgentWindow dialog = new AgentWindow(agentLocation, configLocation, logsDirectory, sc); Application.Run(dialog); } catch (Exception e) { MessageBox.Show("Unable to run the ProActive Agent Control " + e.ToString(), "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }