Created
July 1, 2024 11:17
-
-
Save Zensey/76b326d157c6ccca40e30385aeda3dc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:ffi/src/utf8.dart'; | |
import 'package:ffi/ffi.dart'; | |
import 'package:win32/win32.dart'; | |
import 'dart:convert'; | |
import 'dart:ffi'; | |
import 'dart:io'; | |
import 'dart:isolate'; | |
Future<bool> startElevatedProcess({required String executable, required String args, bool window = false}) async { | |
var shellInput = calloc<SHELLEXECUTEINFO>(); | |
shellInput.ref.lpFile = executable.toNativeUtf16(); | |
shellInput.ref.lpParameters = args.toNativeUtf16(); | |
shellInput.ref.nShow = window ? SW_SHOWNORMAL : SW_HIDE; | |
shellInput.ref.fMask = ES_AWAYMODE_REQUIRED; | |
shellInput.ref.lpVerb = "runas".toNativeUtf16(); | |
shellInput.ref.cbSize = sizeOf<SHELLEXECUTEINFO>(); | |
var shellResult = ShellExecuteEx(shellInput); | |
return shellResult == 1; | |
} | |
void main() async { | |
await startElevatedProcess(executable:"ping", args:"8.8.8.8", window:true); | |
print("Hello, World!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment