在VB.NET中以管理员身份自动运行程序 [英] Automatically running a program as administrator in VB.NET

查看:87
本文介绍了在VB.NET中以管理员身份自动运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于 VB.NET 的应用程序,它需要管理权限才能正常运行.然而,我在网上浏览了几个教程,它们都提到了如何使用 mainifest 文件来做到这一点.这种技术的问题在于,无论何时打开程序,我都需要输入管理员密码,但我希望这会自动发生.(用户不要输入Admin密码,密码必须从代码层面输入)

I am developing a VB.NET based application which requires administrative privileges in order to run properly. However I went through several tutorials online and it all mentioned how to do this using a mainifest file. The problem with this technique is that whenever the program is opened I need to type in the Administrator password, however I want this to happen automatically. (The user should not type the Admin password, the password must be entered from the code level)

以下代码是我能找到的最接近的代码,但它也不能满足我的问题,

The following code is the closest I could find, but it too does not satisfy my problem,

Dim securePass As New Security.SecureString()
Dim pass As String = "password"

For Each c As Char In pass
    securePass.AppendChar(c)
Next

' If there isn't a domain, set the argument to 'Nothing', as demonstrated below.
Process.Start("testsoftware\WinKBSel\WinKBSel1003.exe", "username", pass, Nothing)

谁能告诉我如何在不要求用户输入管理员密码的情况下执行此操作?

Could anyone please let me know how I could do this without requiring the user to enter the administrator password?

推荐答案

除非用户名/密码已知,否则您无法创建自动以用户身份登录的程序.

You cannot create a program that will automatically log on as a user unless the username/password is already known.

这意味着您要么被限制在您的应用程序已经知道凭据的系统上运行,您的用户必须将凭据输入您的应用程序,或者您的用户必须使用 Windows 中的运行方式"功能才能使用正确的用户.

That means that you're either restricted to running on systems where your app already knows the credentials, your user has to enter the credentials into your app, or your user has to use the "Run As" functionality in Windows to use the correct user.

如果您提出的建议确实可行,这将代表一个巨大安全漏洞:您可以以任何用户身份运行任何代码,而无需先进行身份验证.这可不是什么好事!

If what you're proposing were actually possible, it would represent a huge security hole: you'd be able to run any code as any user without requiring authentication first. That is not a good thing!

这样想:如果你被卖了一个程序,它会自动以管理员身份登录即使没有你的许可,你会有什么感觉?

Think about it like this: if you were sold a program that would automatically log on as administrator even without your permission, how would you feel?

这篇关于在VB.NET中以管理员身份自动运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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