vb.net使用本地管理员用户帐户身份验证登录 [英] vb.net login with local admin user account authentication

查看:264
本文介绍了vb.net使用本地管理员用户帐户身份验证登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我写了一个程序,需要用户使用本地管理员帐户登录。

但是本地管理员帐户名不同每台PC,所以我不能硬编码用户名。



下面的代码只检索了Administrators组中的用户,但没有检测到身份验证。可以帮忙吗?

1.如何认证用户名&密码?

2.如何强制用户仅使用本地用户帐户登录。



  Dim  localMachine 作为  DirectoryEntry(  WinNT://&   localhost
Dim admGroup As DirectoryEntry = localMachine .Children.Find( 管理员 group
Dim members As 对象 = admGroup.Invoke( 成员没什么
对于 每个 groupMember As 对象 CType (成员,IEnumerable)
Dim 成员作为 DirectoryEntry(groupMember)
MsgBox(member.Name)
下一步

解决方案

对于Vista及更高版本,您可以添加一个清单,告诉Windows您的应用程序需要管理权限。然后会弹出同意框,用户可以输入管理员的用户名和密码。


你好,



< pre lang =xml>如果您的意思是您的用户需要本地管理员权限当他们启动您的应用程序时,那么请看一下。

首先,打开你的项目。
然后单击Project Explorer选项卡并双击My Project
现在,单击Application选项卡并单击View Windows Settings
现在应该显示一些代码。

最好在制作任何更换器之前阅读此代码。在进行任何此类更改之前,请创建项目的备份。

如果您阅读了代码,您会看到类似的内容:< requestedExecutionLevel level = asInvoker uiAccess = false / >
这未被注释掉。这是默认值。当代码尝试执行需要它们的操作时,这将询问用户权限。


将asInvoker更改为requireAdministrator并保存。

编译应用程序并在受限帐户和本地管理员帐户上对其进行测试,以查看结果是否符合您的要求。

Hi,

I write a program which need user login using local admin account.
But local admin account name is different for every PC, so I cannot hard code the user name.

Below code only retrieved the user in Administrators group, but not authentication. Can help?
1. How to authentication username & password?
2. How to force user to login using local user account only.

Dim localMachine As New DirectoryEntry("WinNT://" & "localhost")
        Dim admGroup As DirectoryEntry = localMachine.Children.Find("Administrators", "group")
        Dim members As Object = admGroup.Invoke("members", Nothing)
        For Each groupMember As Object In CType(members, IEnumerable)
            Dim member As New DirectoryEntry(groupMember)
            MsgBox(member.Name)
        Next

解决方案

For Vista and above, you can add a manifest which tells Windows that your application requires administrative privileges. Then the consent box will pop up and the user can enter user name and password of an administrator.


Hello,

If you mean then your user require local admin rights "When they start the your application" then take a look at this.

First, Open your Project.
Then click on the Project Explorer tab and double click on "My Project"
Now, Click on the Application Tab and click "View Windows Settings"
Some code should show now.

It is best to read this code before you make any changers. Please create a backup of your project before making any change like this.

If you read the code, you will see something like: <requestedExecutionLevel level="asInvoker" uiAccess="false" />
This is not commented out. This is the default. This will ask the user for permissions when your code tries to do something that needs them.


Change the "asInvoker" to "requireAdministrator" and save.

Compile the application and test it out on a restricted account and a local administrator account to see if the results are what you are looking for.


这篇关于vb.net使用本地管理员用户帐户身份验证登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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