Jeffrey Renfroe
asked on
Check the name of the local administrator account using vb.net
Hello. I have a tool that does some migration task when a user moves a Windows 7 machine from one location to another. One task is to give the local administrator account a new password based on what is used at the site. This works well except for sites that use the French language pack. Administrator is spelled administrateur.
I want to have the tool check how admin account is spelled. Based on what it finds, it will execute the proper code to set the admin password. I was trying to use environment.username but discovered that is for the logged on user only. Is there a way to check the spelling of the admin account using vb.net?
Thank you for any help.
I want to have the tool check how admin account is spelled. Based on what it finds, it will execute the proper code to set the admin password. I was trying to use environment.username but discovered that is for the logged on user only. Is there a way to check the spelling of the admin account using vb.net?
Thank you for any help.
If Environment.UserName = "administrateur" Then
Dim user As System.DirectoryServices.DirectoryEntry
Try
user = New System.DirectoryServices.DirectoryEntry("WinNT://" + Environment.MachineName + "/administrateur,user")
user.Invoke("SetPassword", txtLocalAdminPW.Text)
user.CommitChanges()
Catch ex As Exception
MsgBox("Error " + Err.Number.ToString + ". Failed to set local Administrateur password.", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Windows 7 Migration Tool")
Me.Cursor = Cursors.Default
Exit Sub
End Try
End If
One option is to set the password for both Administrator and administrateur if the languages are limited.
ASKER
Can you explain further? Someone else developed the tool. I have some experience with programming but it is not my main area of expertise.
You can change the code to
If Environment.UserName = "administrateur" or Environment.UserName = "administrator" Then
Dim user As System.DirectoryServices.DirectoryEntry
Try
user = New System.DirectoryServices.DirectoryEntry("WinNT://" + Environment.MachineName + "/" Environment.UserName & ",user")
user.Invoke("SetPassword", txtLocalAdminPW.Text)
user.CommitChanges()
Catch ex As Exception
MsgBox("Error " + Err.Number.ToString + ". Failed to set local Administrateur password.", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Windows 7 Migration Tool")
Me.Cursor = Cursors.Default
Exit Sub
End Try
End If
ASKER
Thank you for the information. I assume this means that the user would have to be logged on as local administrator to run this. Is that correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much. This was very helpful
ASKER
Thank you
Glad to help :-)