简体   繁体   English

使用管理权限启动我的 C# 应用程序

[英]Start my C# application with administrative rights

I have an app of mine that I need to distribute to 5000 computers on my business domain via SCCM and i'm having problems with the windows security.我有一个应用程序,我需要通过 SCCM 将其分发到我业务域上的 5000 台计算机,但我在 Windows 安全方面遇到了问题。 The point is that my app requires administrative rights to access to registry keys and launch some "specific" featues on the local system and all the users on the domain (except for the IT support team of course) doesn't have such privileges.关键是我的应用程序需要管理权限才能访问注册表项并在本地系统上启动一些“特定”功能,并且域中的所有用户(当然 IT 支持团队除外)没有这样的权限。

I was wondering that I could make windows call a launcher on startup next, this launcher would get admin username and password on the app's server and then run the app with those credentials.我想知道接下来我可以让 Windows 在启动时调用启动器,这个启动器会在应用程序的服务器上获取管理员用户名和密码,然后使用这些凭据运行应用程序。 But i'm having difficulties performing this task once i'm new on C# (i'm a java programer) and i haven't found any way of using the runas command with both username and password information.但是,一旦我是 C# 新手(我是 Java 程序员),我在执行此任务时遇到了困难,而且我还没有找到任何使用带有用户名和密码信息的 runas 命令的方法。

Other point, it would be perfect if i could make use the admin privileges without the anoying windows UAC prompts.其他一点,如果我可以在没有烦人的 Windows UAC 提示的情况下使用管理员权限,那将是完美的。

Can anybody help me?有谁能够帮助我?

I'm not sure about what I'm going to say, but just did a bit of research that may help you.我不确定我要说什么,但只是做了一些可能对你有帮助的研究。

You can try to schedule a task to run your program, and config this schedule to run it with admin rights, at startup.您可以尝试安排一个任务来运行您的程序,并在启动时配置此计划以使用管理员权限运行它。

Scheduling a task 安排任务

Then the only thing left you need to look for is how to program easily this task for all your computers.然后,您唯一需要寻找的是如何轻松地为所有计算机编写此任务。

Hope this helps you希望这对你有帮助

If your application must be run as an administrator in order to operate correctly: then tell Windows that:如果您的应用程序必须以管理员身份运行才能正确运行:那么告诉 Windows:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

So that if i'm a standard user (ie not an Administrator), and i try to use your program: i will be prompted to get an administrator to come to my desk and enter their credentials so i can run your program.因此,如果我是标准用户(即不是管理员),并且我尝试使用您的程序:系统将提示我让管理员到我的办公桌前输入他们的凭据,以便我可以运行您的程序。

The downside of your program only functioning with admin privileges is that a standard user cannot run your program.您的程序只能以管理员权限运行的缺点是标准用户无法运行您的程序。

And you could try turning off UAC;你可以尝试关闭 UAC; but that doesn't fix anything.但这并不能解决任何问题。 UAC is a quality-of-life feature. UAC 是一种生活质量功能。

  • if i turn off UAC如果我关闭 UAC
  • i'm still a standard user我还是标准用户
  • except now i have to logout and login as an administrator除了现在我必须注销并以管理员身份登录

The correct solution is to let your program work as a standard user.正确的解决方案是让您的程序以标准用户身份运行。

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

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