Click here to Skip to main content
15,944,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB
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
Posted

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.
 
Share this answer
 
Hello,

XML
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900