简体   繁体   English

在C#中设置管理权限

[英]Set administrative privileges in C#

I have been writing many scripts using WMI and a lot of them only work if I start visual studio with "Run as Administrator". 我一直在使用WMI编写许多脚本,并且只有当我使用“以管理员身份运行”启动Visual Studio时,其中许多脚本才有效。

Is there a way to set that programmatically with .Net or other means? 有没有一种方法可以通过.Net或其他方式以编程方式进行设置?

Eventually, these scripts will be run as .exes from Unity3D so I need to automate setting these rights before running them. 最终,这些脚本将从Unity3D作为.exes运行,因此我需要在运行它们之前自动设置这些权限。 Ideally I'm hoping this can all be done in C#. 理想情况下,我希望所有这些都可以在C#中完成。

This question was answered in the comments. 评论中回答了这个问题。 The only way is to add a manifest file to your project that sets the required priviledges of your app to be administrative. 唯一的方法是将清单文件添加到您的项目,该清单文件将您的应用程序所需的特权设置为可管理。 Big thanks to Peter Ritchie and DJ KRAZE! 非常感谢Peter Ritchie和DJ KRAZE!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM