Afficher un message
Vieux 26/09/2007, 13h58   #5
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: VBS to create local user and add to local amins

Something similar to below should work.
===============
Option Explicit

Dim objNetwork strComputer, objComputer, objUser
Dim strUserName, strPassword, objGroup

' Retrieve NetBIOS name of local computer.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Bind to local computer object.
Set objComputer = GetObject("WinNT://" & strComputer)

' Create user object.
strUserName = "Temp"
Set objUser = objComputer.Create("user", strUserName)
objUser.SetInfo

' Set password.
strPassword "zxy321"
objUser.SetPassword strPassword

' Bind to local Administrators group.
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")

' Add user to local Administrators group.
objGroup.Add(objUser.AdsPath)
=====================
I used "Option Explicit" to make troubleshooting easier. This requires that
all variables be declared (in Dim statements).

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Chris" <nospam@email.com> wrote in message
news:uNir0YBAIHA.1204@TK2MSFTNGP03.phx.gbl...
> Hi Guys,
>
> Still struggling with this. I have no idea about scripts.
>
> I need the script to create a local user named Temp
> Set a password
> and add to the local admins group.
>
> Would be eternally grateful if you can .
>
> Kind Regards
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>>
>> "Fred Beck" <FredBeck@discussions.microsoft.com> wrote in message
>> news:E50D755D-593F-46F2-AA91-FB0E98A6160E@microsoft.com...
>>> The "." signifies the machine that you are running the script on.
>>>
>>> strComputer = "."
>>> Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
>>> Set objUser = GetObject("WinNT://fabrikam/kenmyer")
>>> objGroup.Add(objUser.ADsPath)

>>
>> A script can also retrieve the NetBIOS name of the local computer from
>> the wshNetwork object:
>> ========
>> Set objNetwork = CreateObject("Wscript.Network")
>> strComputer = objNetwork.ComputerName
>>
>> Set objComputer = GetObject("WinNT://" & strComputer)
>> Set objUser = objComputer.Create("user", "NewUser")
>> objUser.SetInfo
>> ========
>> But the "." probably works as well.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>

>
>



  Réponse avec citation
 
Page generated in 0,06871 seconds with 9 queries