Page 1 of 1 1
Topic Options
#157913 - 2006-02-27 08:48 AM Add local user
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
Hi

I must add local user in the local sam account database on workstations. I want to execute the code locally on the workstation. Can someone give me some code that can do this. I have code to do this from remote but not local.
Code:
 
$Group = GetObject("WinNT://" + $Ws + "/" + $AdminLanguage + ",group")
If @ERROR < 0
? "ERROR @Error:@SError"
Else
$Group.Add("WinNT://" + @Domain + "/Domain Users")
EndIf



In the code above I am using WinNT://" + $Ws which point to a remote computer, but if i execute the code locally what to write ?
And how to add one user ?

Top
#157914 - 2006-02-27 09:14 AM Re: Add local user
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
net user john 12345 /add

But that simply creates an account named john with a password of 12345 but does not place it into any group.
Is that what you're wanting?

Top
#157915 - 2006-02-27 09:26 AM Re: Add local user
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
Nice, can I check error code with that, so I am is sure that the account is created ?
Top
#157916 - 2006-02-27 09:29 AM Re: Add local user
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Yes, should be able to no problem.

{untested}
SHELL 'net user john 12345 /add '
If @ERROR
  'Error creating account: ' + @ERROR +' '+@SERROR ?
EndIf
 

Top
#157917 - 2006-02-27 09:58 AM Re: Add local user
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Code:
Break On
SHELL '%comspec% /c net user john 12345 /add >nul 2>nul'
If @ERROR
'Error creating account: ' + @ERROR +' '+@SERROR ?
Else
'Account created successfully: ' + @ERROR +' '+@SERROR ?
EndIf




Weird though as it gives a rather odd error of 2 if the account already exists.

Top
#157918 - 2006-02-27 11:49 AM Re: Add local user
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
The reason of this script is that I want to see if a user is local administrator or not on a pc. We want to mail out this exe file (I have made a exe file of it with iTripoli AdminScriptEditor) to the users and ask them to execute this.
Here is the code:

Code:
 Shell '%Comspec% /c Net User _Qwertyu ?9955MMxyythk /Add'

If @ERROR = 0
$Sel = MessageBox("You HAVE administrators rights in this computer.@CRLF@CRLFUsername = %Username%@CrlfComputername = %Computername%@CrlfDomain=@Domain", "Company AB", 64)
Shell '%Comspec% /c Net User _Qwertyu /Delete'
Else
$Sel = MessageBox("You DO NOT HAVE administrators rights in this computer.@CRLF@CRLFUsername = %Username%@CrlfComputername = %Computername%@CrlfDomain=@Domain", "Company", 16)
EndIf


Top
#157919 - 2006-02-27 02:27 PM Re: Add local user
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
No need to get fancy with ADSI or external applications; use KiXtart's built-in InGroup() function...

Code:

InGroup("\\" + @WKSTA + "\administrators")


Top
#157920 - 2006-02-27 10:42 PM Re: Add local user
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Yes, but depending on the local language it is better to use...

Code:
$Admin = 1
If not InGroup( "\\" + @wksta + "\" + SidToName( "S-1-5-32-544" ) )
$Admin=0
Endif

_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1334 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.042 seconds in which 0.019 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org