Fixed Issue 71.

This commit is contained in:
Michael Möller
2010-06-27 13:02:02 +00:00
parent 4a6cdb1e60
commit 589ba48753
2 changed files with 42 additions and 26 deletions

View File

@@ -141,11 +141,7 @@ namespace OpenHardwareMonitor.GUI {
UnitManager.TemperatureUnit == TemperatureUnit.Celcius; UnitManager.TemperatureUnit == TemperatureUnit.Celcius;
fahrenheitToolStripMenuItem.Checked = !celciusToolStripMenuItem.Checked; fahrenheitToolStripMenuItem.Checked = !celciusToolStripMenuItem.Checked;
// Hide the auto startup menu item on Unix startupMenuItem.Visible = startupManager.IsAvailable;
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
startupMenuItem.Visible = false;
}
if (startMinMenuItem.Checked) { if (startMinMenuItem.Checked) {
if (!minTrayMenuItem.Checked) { if (!minTrayMenuItem.Checked) {

View File

@@ -39,6 +39,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal; using System.Security.Principal;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Win32; using Microsoft.Win32;
@@ -49,6 +50,7 @@ namespace OpenHardwareMonitor.GUI {
private TaskSchedulerClass scheduler; private TaskSchedulerClass scheduler;
private bool startup; private bool startup;
private bool isAvailable;
private const string REGISTRY_RUN = private const string REGISTRY_RUN =
@"Software\Microsoft\Windows\CurrentVersion\Run"; @"Software\Microsoft\Windows\CurrentVersion\Run";
@@ -64,6 +66,13 @@ namespace OpenHardwareMonitor.GUI {
} }
public StartupManager() { public StartupManager() {
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
scheduler = null;
isAvailable = false;
return;
}
if (IsAdministrator()) { if (IsAdministrator()) {
try { try {
scheduler = new TaskSchedulerClass(); scheduler = new TaskSchedulerClass();
@@ -101,15 +110,24 @@ namespace OpenHardwareMonitor.GUI {
} else { } else {
scheduler = null; scheduler = null;
} }
if (scheduler == null) { if (scheduler == null) {
RegistryKey key = Registry.CurrentUser.OpenSubKey(REGISTRY_RUN); try {
startup = false; using (RegistryKey key =
if (key != null) { Registry.CurrentUser.OpenSubKey(REGISTRY_RUN)) {
string value = (string)key.GetValue("OpenHardwareMonitor"); startup = false;
if (value != null) if (key != null) {
startup = value == Application.ExecutablePath; string value = (string)key.GetValue("OpenHardwareMonitor");
if (value != null)
startup = value == Application.ExecutablePath;
}
}
isAvailable = true;
} catch (SecurityException) {
isAvailable = false;
} }
} else {
isAvailable = true;
} }
} }
@@ -165,6 +183,10 @@ namespace OpenHardwareMonitor.GUI {
key.DeleteValue("OpenHardwareMonitor"); key.DeleteValue("OpenHardwareMonitor");
} }
public bool IsAvailable {
get { return isAvailable; }
}
public bool Startup { public bool Startup {
get { get {
return startup; return startup;
@@ -172,24 +194,22 @@ namespace OpenHardwareMonitor.GUI {
set { set {
if (startup != value) { if (startup != value) {
startup = value; startup = value;
if (scheduler != null) { if (isAvailable) {
if (startup) if (scheduler != null) {
CreateSchedulerTask(); if (startup)
else CreateSchedulerTask();
DeleteSchedulerTask(); else
} else { DeleteSchedulerTask();
if (startup) } else {
CreateRegistryRun(); if (startup)
else CreateRegistryRun();
DeleteRegistryRun(); else
DeleteRegistryRun();
}
} }
} }
} }
} }
} }
} }