admin管理员组文章数量:1432352
I am working on a program for doing post-imaging tasks on Windows computers. Several of the things it needs to do require running subprocesses as admin. It seems like there are solutions for Linux and macOS but not Windows.
This is one of the things I am trying to run.
final ProcessResult userResult = Process.runSync("runas", ["net", "user", "/add", "it_admin"], runInShell: true);
When I look at the output, I get the following error:
Encountered an error trying to run "uname -m"
I have tried running the same process without "runas" to no avail.
final ProcessResult userResult = Process.runSync("net", ["user", "/add", "it_admin"], runInShell: true);
I have tried adding the following to the runner.exe.manifest
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
and both of the following to CmakeLists.txt
SET_TARGET_PROPERTIES(PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS")
SET_TARGET_PROPERTIES(${BINARY_NAME} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS")
Any help is greatly appreciated!
I am working on a program for doing post-imaging tasks on Windows computers. Several of the things it needs to do require running subprocesses as admin. It seems like there are solutions for Linux and macOS but not Windows.
This is one of the things I am trying to run.
final ProcessResult userResult = Process.runSync("runas", ["net", "user", "/add", "it_admin"], runInShell: true);
When I look at the output, I get the following error:
Encountered an error trying to run "uname -m"
I have tried running the same process without "runas" to no avail.
final ProcessResult userResult = Process.runSync("net", ["user", "/add", "it_admin"], runInShell: true);
I have tried adding the following to the runner.exe.manifest
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
and both of the following to CmakeLists.txt
SET_TARGET_PROPERTIES(PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS")
SET_TARGET_PROPERTIES(${BINARY_NAME} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS")
Any help is greatly appreciated!
Share Improve this question asked Nov 18, 2024 at 17:44 Aspen RodriguezAspen Rodriguez 133 bronze badges 1- I change my answer run powershell.exe as admin. Maybe can help you now. – Alexandre B. Commented Nov 18, 2024 at 20:16
1 Answer
Reset to default 0There are some reports about bugs in Process.runAsync or Process.run. Can you try using Process.start?
Process.start(
'powershell.exe',
[
'Start-Process',
'-Verb',
'RunAs',
'-FilePath',
'powershell.exe',
],
);
And here you can open notepad as Admin using runSync:
ProcessResult process = Process.runSync(
'powershell.exe',
[
'Start-Process',
'-Verb',
'RunAs',
'-FilePath',
'notepad.exe',
],
);
本文标签: flutterRun Dart process as admin on WindowsStack Overflow
版权声明:本文标题:flutter - Run Dart process as admin on Windows - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745604010a2665734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论