|
@@ -13,6 +13,33 @@
|
|
|
#include <memory>
|
|
|
#include <sstream>
|
|
|
|
|
|
+typedef LONG NTSTATUS, * PNTSTATUS;
|
|
|
+#define STATUS_SUCCESS (0x00000000)
|
|
|
+
|
|
|
+typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
|
|
|
+
|
|
|
+RTL_OSVERSIONINFOW GetRealOSVersion() {
|
|
|
+ HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
|
|
|
+ if (hMod) {
|
|
|
+ RtlGetVersionPtr fnRtlGetVersion = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
|
|
|
+ if (fnRtlGetVersion != nullptr) {
|
|
|
+ RTL_OSVERSIONINFOW rovi = { 0 };
|
|
|
+ rovi.dwOSVersionInfoSize = sizeof(rovi);
|
|
|
+ if (STATUS_SUCCESS == fnRtlGetVersion(&rovi)) {
|
|
|
+ return rovi;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RTL_OSVERSIONINFOW rovi = { 0 };
|
|
|
+ return rovi;
|
|
|
+}
|
|
|
+
|
|
|
+bool IsWindows11OrGreater() {
|
|
|
+ RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
|
|
|
+ return (rovi.dwMajorVersion > 10) ||
|
|
|
+ (rovi.dwMajorVersion == 10 && rovi.dwBuildNumber >= 22000);
|
|
|
+}
|
|
|
+
|
|
|
namespace wl_base_help {
|
|
|
|
|
|
// static
|
|
@@ -38,18 +65,25 @@ WlBaseHelpPlugin::WlBaseHelpPlugin(flutter::PluginRegistrarWindows* registrar) :
|
|
|
WlBaseHelpPlugin::~WlBaseHelpPlugin() {}
|
|
|
|
|
|
void WlBaseHelpPlugin::HandleMethodCall(
|
|
|
- const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
|
|
+ const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
|
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
|
|
- if (method_call.method_name().compare("runAsAdministrator") == 0) {
|
|
|
- HWND hwnd = GetMainWindow();
|
|
|
- // 调用您的提权逻辑,传递 hwnd
|
|
|
- TryRunAsAdmin(hwnd, result);
|
|
|
+ if (method_call.method_name().compare("runAsAdministrator") == 0) {
|
|
|
+ HWND hwnd = GetMainWindow();
|
|
|
+ // 调用您的提权逻辑,传递 hwnd
|
|
|
+ TryRunAsAdmin(hwnd, result);
|
|
|
|
|
|
- //result->Success(flutter::EncodableValue(true));
|
|
|
- } else if (method_call.method_name().compare("getPlatformVersion") == 0) {
|
|
|
+ //result->Success(flutter::EncodableValue(true));
|
|
|
+ }
|
|
|
+ else if (method_call.method_name().compare("isRunningAsAdmin") == 0) {
|
|
|
+ bool isAdmin = IsRunningAsAdmin();
|
|
|
+ result->Success(flutter::EncodableValue(isAdmin));
|
|
|
+ }
|
|
|
+ else if (method_call.method_name().compare("getPlatformVersion") == 0) {
|
|
|
std::ostringstream version_stream;
|
|
|
version_stream << "Windows ";
|
|
|
- if (IsWindows10OrGreater()) {
|
|
|
+ if (IsWindows11OrGreater()) {
|
|
|
+ version_stream << "11+";
|
|
|
+ }else if (IsWindows10OrGreater()) {
|
|
|
version_stream << "10+";
|
|
|
} else if (IsWindows8OrGreater()) {
|
|
|
version_stream << "8";
|
|
@@ -69,7 +103,20 @@ void WlBaseHelpPlugin::HandleMethodCall(
|
|
|
return ::GetAncestor(windowHwnd, GA_ROOT);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ bool WlBaseHelpPlugin::IsRunningAsAdmin() {
|
|
|
+ BOOL isAdmin = FALSE;
|
|
|
+ PSID adminGroup = NULL;
|
|
|
+ SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
|
|
|
+ if (AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
|
|
|
+ DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
|
|
|
+ &adminGroup)) {
|
|
|
+ if (!CheckTokenMembership(NULL, adminGroup, &isAdmin)) {
|
|
|
+ isAdmin = FALSE;
|
|
|
+ }
|
|
|
+ FreeSid(adminGroup);
|
|
|
+ }
|
|
|
+ return isAdmin != FALSE;
|
|
|
+ }
|
|
|
void WlBaseHelpPlugin::TryRunAsAdmin(HWND hwnd,
|
|
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>>& result){
|
|
|
wchar_t szPath[MAX_PATH];
|