473,508 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Local Administrator

What is the best way to create a local user on the machine with administrator
rights?

I have problems with my code on machines that have password policy. The
problem is that when the user is created there is no password, and password
policy is set to min 7 chars or something. So the code only works if I turn
of group policy. Can I create a user with pass (and even add him to
administrators group) in one line/action? My code:

Private Sub CreateUser(ByVal User As String)
'Create Account
Try
Dim strUser As String = User
Dim oDomain As Object = GetObject("WinNT://" + ComputerName)
Dim oUser As Object = oDomain.Create("user", strUser)
If (Err.Number = 0) Then
oUser.SetInfo()
oUser.SetPassword(Password)
oUser.SetInfo()
SaveLog("Created user " & User)
Else
SaveLog("Unable to create user " & User)
Diagnostics.EventLog.WriteEntry("Rename Tool", "Unable to
create user " & User & " with password " & Password,
EventLogEntryType.Warning)
End If
Catch ex As Exception
SaveLog("Unable to create user " & User & ". More info: " &
ex.Message)
Diagnostics.EventLog.WriteEntry("Rename Tool", "Unable to create
user " & User & " with password " & Password & ".More info: " & ex.Message,
EventLogEntryType.Warning)
End Try

End Sub
Feb 10 '06 #1
6 6108
Hi Philip,

Thanks for posting!

At the current stage, your code is appropriate for create a local user.
"I have problems with my code on machines that have password policy."


As far as I know, if you have joined the domain, you are restricted with
the domain policy. This is why the current issue is encountered. So, I
think you need to follow the policy if you don't quit from the current
domain.

Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 13 '06 #2
But I want to create a user with a password that matches the password policy.
But I cannot create the user and set its password in one action. That is why
I need to disable the passwordpolicy and thus my question how to create a
user and set it's password in action.
""Yuan Ren[MSFT]"" wrote:
Hi Philip,

Thanks for posting!

At the current stage, your code is appropriate for create a local user.
"I have problems with my code on machines that have password policy."


As far as I know, if you have joined the domain, you are restricted with
the domain policy. This is why the current issue is encountered. So, I
think you need to follow the policy if you don't quit from the current
domain.

Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 13 '06 #3
Hi Philip,

Thanks for your reply!

I'm sorry for misunderstanding. But I wonder your meaning is the
SetPassword doesn't work in the current application. If this is true, could
you please supply more details? This means some error message or event log.
Thanks for your understanding.

I'm looking forward your reply!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 13 '06 #4
I do not know the 'exact' error message. But when I execute the code:

Dim oUser As Object = oDomain.Create("user", strUser)

I catch an exception that users password does not match the policy.

This makes sense because the user is first created and then password is set.
But because the policy enforces 7 char password (for example) the creation of
the user fails and I never even get a chance to set the password for the
user. Thus my question if I can create a user AND set the password in one
'call' to the system.

I will try to get the exact error message if need.


""Yuan Ren[MSFT]"" wrote:
Hi Philip,

Thanks for your reply!

I'm sorry for misunderstanding. But I wonder your meaning is the
SetPassword doesn't work in the current application. If this is true, could
you please supply more details? This means some error message or event log.
Thanks for your understanding.

I'm looking forward your reply!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 13 '06 #5
I set my local security policy min. password length to seven and ran the code
again and I receive this exact error (i tried to create the user "dus"):

Unable to create user dus with password The password does not meet the
password policy requirements. Check the minimum password length, password
complexity and password history requirements. (Exception from HRESULT:
0x800708C5)

When I set the min. password length to 0 the code works fine. Once more the
code to create the user:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CreateUser("dus")
End Sub

Private Sub CreateUser(ByVal User As String)
'Create Account
Try
Dim strUser As String = User
Dim oDomain As Object = GetObject("WinNT://" +
Environment.MachineName)
Dim oUser As Object = oDomain.Create("user", strUser)
If (Err.Number = 0) Then
oUser.SetInfo()
oUser.SetPassword("Nrg2005")
oUser.SetInfo()
'SaveLog("Created user " & User)
Else
'SaveLog("Unable to create user " & User)
Diagnostics.EventLog.WriteEntry("Rename Tool", "Unable to
create user " & User & " with password ", EventLogEntryType.Warning)
End If
Catch ex As Exception
'SaveLog("Unable to create user " & User & ". More info: " &
ex.Message)
Diagnostics.EventLog.WriteEntry("Rename Tool", "Unable to create
user " & User & " with password " & ex.Message, EventLogEntryType.Warning)
End Try

End Su

""Yuan Ren[MSFT]"" wrote:
Hi Philip,

Thanks for your reply!

I'm sorry for misunderstanding. But I wonder your meaning is the
SetPassword doesn't work in the current application. If this is true, could
you please supply more details? This means some error message or event log.
Thanks for your understanding.

I'm looking forward your reply!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 13 '06 #6
Hi Philip,

Thanks for your reply!

I'm sorry for careless about the current issue. In the code as below,
please remove the first setinfo method and try to run again:
If (Err.Number = 0) Then
'oUser.SetInfo() Please remove this one
oUser.SetPassword("Nrg2005")
oUser.SetInfo()

After my performing, the user has been created on my machine.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4141
by: ezra epstein | last post by:
I found a post about something similar in an older release: http://archives.postgresql.org/pgsql-bugs/2002-08/msg00151.php Here's the issue. Inside a function I'm calling CREATE LOCAL TEMPORARY...
1
3814
by: Daniel | last post by:
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific...
3
7922
by: W C Hull | last post by:
We have a request from Auditing to modify the password an a local workstation administrative account every 90 days. We are developing two programs - a VB6 GUI program that will allow the...
1
972
by: Matt Adamson | last post by:
If we use forms authentication in our web application we need an initial administrator account from which the first user can log on to create new users and assign roles. How do others do this, use...
4
1758
by: cj | last post by:
Here's what I'm trying to do direct from MS (Create a Database) http://msdn2.microsoft.com/en-us/library/ms247254(VS.80).aspx Only I have VS 2005 Pro instead of Visual Web Developer. I do have...
15
11037
by: eltonchew | last post by:
Hi, We have an inhouse developed VB.NET Windows application which runs successfully only when the user is given a local administrator rights. Without which, it fails to start. There isn't...
4
10670
by: sethington | last post by:
Here is my situation. I have ODBC Rights to a SQL database but I have 4 users who need to get to this information but because they are contractors they are not allowed to get there own ODBC access. ...
3
7013
by: romcab | last post by:
Hi guys, I'm currently using NTP for time synchronization and I'm using public NTP server. I would like to ask how to create a local NTP server and what are the configurations needed. Is it...
1
1453
by: sabira | last post by:
how to create an administrator
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.