在 C# 中设置管理权限 [英] Set administrative privileges in C#

查看:37
本文介绍了在 C# 中设置管理权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 WMI 编写许多脚本,其中很多脚本只有在我以以管理员身份运行"的情况下启动 Visual Studio 时才有效.

I have been writing many scripts using WMI and a lot of them only work if I start visual studio with "Run as Administrator".

有没有办法用 .Net 或其他方式以编程方式设置?

Is there a way to set that programmatically with .Net or other means?

最终,这些脚本将作为 Unity3D 的 .exe 运行,因此我需要在运行它们之前自动设置这些权限.理想情况下,我希望这一切都可以在 C# 中完成.

Eventually, these scripts will be run as .exes from Unity3D so I need to automate setting these rights before running them. Ideally I'm hoping this can all be done in C#.

推荐答案

此问题已在评论中得到解答.唯一的方法是向您的项目添加一个清单文件,该文件将您的应用程序所需的权限设置为管理权限.非常感谢 Peter Ritchie 和 DJ KRAZE!

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!

这篇关于在 C# 中设置管理权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆