Home All Groups Group Topic Archive Search About

VBS to create local user and add to local amins



Author
25 Sep 2007 8:09 PM
Chris
Hiya,

I can find scripts to create local user accounts but these need the PC name
to be entered into the script

Does anyone ahve one that can be ran on any PC?

TIA

Author
25 Sep 2007 8:56 PM
Fred Beck
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)
Author
25 Sep 2007 9:34 PM
Richard Mueller [MVP]
"Fred Beck" <FredB***@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
--
Author
26 Sep 2007 7:57 AM
Chris
Thanks Lads.

Very Much Appreciated.


Show quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>
> "Fred Beck" <FredB***@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
> --
>
>
Author
26 Sep 2007 8:21 AM
Chris
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 help.

Kind Regards

Show quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>
> "Fred Beck" <FredB***@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
> --
>
>
Author
26 Sep 2007 12:58 PM
Richard Mueller [MVP]
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
--

Show quote
"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 help.
>
> Kind Regards
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>>
>> "Fred Beck" <FredB***@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
>> --
>>
>>
>
>
Author
26 Sep 2007 8:23 PM
Chris
Thanks Richard,

I get an error on line 3, character 16.

Is this normal?

Show quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:OQJey0DAIHA.4656@TK2MSFTNGP04.phx.gbl...
> 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 help.
>>
>> Kind Regards
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>> message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>>>
>>> "Fred Beck" <FredB***@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
>>> --
>>>
>>>
>>
>>
>
>
Author
27 Sep 2007 1:16 AM
Richard Mueller [MVP]
My fault. I missed a comma in the Dim statement. The third line should be:

Dim objNetwork, strComputer, objComputer, objUser

Notice the commas separating all variables declared in the Dim statement.

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

Show quote
"Chris" <nospam@email.com> wrote in message
news:O8rtmsHAIHA.5184@TK2MSFTNGP02.phx.gbl...
> Thanks Richard,
>
> I get an error on line 3, character 16.
>
> Is this normal?
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:OQJey0DAIHA.4656@TK2MSFTNGP04.phx.gbl...
>> 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 help.
>>>
>>> Kind Regards
>>>
>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>>> message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>>>>
>>>> "Fred Beck" <FredB***@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
>>>> --
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
27 Sep 2007 10:11 AM
Chris
You lads who understand this absolute amaze me.

Had to put an = in line 19 also.

Really appreciate this Richard

Thanks again

Show quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:eji5XRKAIHA.5184@TK2MSFTNGP02.phx.gbl...
> My fault. I missed a comma in the Dim statement. The third line should be:
>
> Dim objNetwork, strComputer, objComputer, objUser
>
> Notice the commas separating all variables declared in the Dim statement.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Chris" <nospam@email.com> wrote in message
> news:O8rtmsHAIHA.5184@TK2MSFTNGP02.phx.gbl...
>> Thanks Richard,
>>
>> I get an error on line 3, character 16.
>>
>> Is this normal?
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>> message news:OQJey0DAIHA.4656@TK2MSFTNGP04.phx.gbl...
>>> 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 help.
>>>>
>>>> Kind Regards
>>>>
>>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote
>>>> in message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>>>>>
>>>>> "Fred Beck" <FredB***@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
>>>>> --
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
27 Sep 2007 12:29 PM
Richard Mueller [MVP]
Oops. Thanks for catching that. The line should be:

strPassword = "zxy321"

Richard

Show quote
"Chris" <nospam@email.com> wrote in message
news:%23We9O7OAIHA.3900@TK2MSFTNGP02.phx.gbl...
> You lads who understand this absolute amaze me.
>
> Had to put an = in line 19 also.
>
> Really appreciate this Richard
>
> Thanks again
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:eji5XRKAIHA.5184@TK2MSFTNGP02.phx.gbl...
>> My fault. I missed a comma in the Dim statement. The third line should
>> be:
>>
>> Dim objNetwork, strComputer, objComputer, objUser
>>
>> Notice the commas separating all variables declared in the Dim statement.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "Chris" <nospam@email.com> wrote in message
>> news:O8rtmsHAIHA.5184@TK2MSFTNGP02.phx.gbl...
>>> Thanks Richard,
>>>
>>> I get an error on line 3, character 16.
>>>
>>> Is this normal?
>>>
>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>>> message news:OQJey0DAIHA.4656@TK2MSFTNGP04.phx.gbl...
>>>> 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 help.
>>>>>
>>>>> Kind Regards
>>>>>
>>>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote
>>>>> in message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
>>>>>>
>>>>>> "Fred Beck" <FredB***@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
>>>>>> --
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
8 Oct 2007 7:52 AM
Monkey
Great! It is helpfull. But what script to set user  with password never
expire and other attribute?
Show quote
"Richard Mueller [MVP]" wrote:

> Oops. Thanks for catching that. The line should be:
>
> strPassword = "zxy321"
>
> Richard
>
> "Chris" <nospam@email.com> wrote in message
> news:%23We9O7OAIHA.3900@TK2MSFTNGP02.phx.gbl...
> > You lads who understand this absolute amaze me.
> >
> > Had to put an = in line 19 also.
> >
> > Really appreciate this Richard
> >
> > Thanks again
> >
> > "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> > message news:eji5XRKAIHA.5184@TK2MSFTNGP02.phx.gbl...
> >> My fault. I missed a comma in the Dim statement. The third line should
> >> be:
> >>
> >> Dim objNetwork, strComputer, objComputer, objUser
> >>
> >> Notice the commas separating all variables declared in the Dim statement.
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >> "Chris" <nospam@email.com> wrote in message
> >> news:O8rtmsHAIHA.5184@TK2MSFTNGP02.phx.gbl...
> >>> Thanks Richard,
> >>>
> >>> I get an error on line 3, character 16.
> >>>
> >>> Is this normal?
> >>>
> >>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> >>> message news:OQJey0DAIHA.4656@TK2MSFTNGP04.phx.gbl...
> >>>> 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 help.
> >>>>>
> >>>>> Kind Regards
> >>>>>
> >>>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote
> >>>>> in message news:uNS1Xw7$HHA.3548@TK2MSFTNGP06.phx.gbl...
> >>>>>>
> >>>>>> "Fred Beck" <FredB***@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
> >>>>>> --
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>
> >
> >
>
>
>

AddThis Social Bookmark Button