Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash when detecting UAC on Windows 10. #56

Merged
merged 1 commit into from
Oct 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions flmm/Util/UacUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ private static extern bool GetTokenInformation(
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);

/// <summary>
/// Loads the specified library.
/// </summary>
/// <param name="lpFileName">The library to load.</param>
/// <returns>A handle to the loaded library.</returns>
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = false)]
public static extern IntPtr LoadLibrary(string lpFileName);

[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
public static extern IntPtr GetProcAddress(IntPtr hmodule, string procName);

/// <summary>
/// Gets whether the OS has UAC.
/// </summary>
Expand All @@ -135,13 +124,9 @@ public static bool IsUACOperatingSystem
{
get
{
//TODO: check for native C# way to check this out
var hmodule = LoadLibrary("kernel32");

//a function that only exists on Vista and above
// this is a hack, as the function we use may not exist on some future OS
var strFunction = "CreateThreadpoolWait";
return ((hmodule.ToInt64() != 0) && (GetProcAddress(hmodule, strFunction).ToInt64() != 0));
// UAC exists in Vista and later.
var versionVista = new Version(6, 0);
return Environment.OSVersion.Version >= versionVista;
}
}

Expand Down