Below is a copy of my script that I'm using to set a random password to the
local administrator.

I would like to improve but would like some help doing it.

I would like to put some error handling in so that I can control an error
and take approrate action if it fails, because at the moment if it fails say
user not found the program just stops.

Also I didn't know if there was a way to query the name of the default local
administrator.

Be honest if needs completly rewriting then say so.

TIA

Gary

Option Explicit
Dim Title, NumChar, Count, strRdm, intRdm, wshShell, oWshNet, sUserName,
sComputerName, oUser

NumChar = 127

Randomize Timer

Do Until Count = NumChar
Count = Count + 1
GetRdm
strRdm = strRdm & Chr(intRdm)
Loop

Sub GetRdm
intRdm = Int((122 - 49) * Rnd + 48)
If intRdm > 57 And intRdm < 65 Or intRdm > 90 And intRdm < 97 Then GetRdm
End Sub


wscript.echo strRdm

Set oWshNet = CreateObject("WScript.Network")

sUserName = "localadmin"

sComputerName = oWshNet.ComputerName

Set oUser = GetObject("WinNT://" & sComputerName & "/"& sUserName & ",user")

oUser.SetPassword(strRdm)
oUser.Setinfo

RE: Configuring Error Handling with in this Script by PeterLundin

PeterLundin
Wed Apr 06 05:59:03 CDT 2005

You can use 'on error resume next' to tell the script to continue when error
and use the 'Err' object to trap the error and decide what to do next.

Like:

--------------
On error resume next

<your code>

if Err.Number <> 0 Then
Wscript.echo "Error:"&Err.Number&vbTab&Err.Description

Else
oUser.SetPassword(strRdm)
oUser.Setinfo
Wscript.echo "Password set"
End If
Err.Clear
--------------

"Gary" wrote:

> Below is a copy of my script that I'm using to set a random password to the
> local administrator.
>
> I would like to improve but would like some help doing it.
>
> I would like to put some error handling in so that I can control an error
> and take approrate action if it fails, because at the moment if it fails say
> user not found the program just stops.
>
> Also I didn't know if there was a way to query the name of the default local
> administrator.
>
> Be honest if needs completly rewriting then say so.
>
> TIA
>
> Gary
>
> Option Explicit
> Dim Title, NumChar, Count, strRdm, intRdm, wshShell, oWshNet, sUserName,
> sComputerName, oUser
>
> NumChar = 127
>
> Randomize Timer
>
> Do Until Count = NumChar
> Count = Count + 1
> GetRdm
> strRdm = strRdm & Chr(intRdm)
> Loop
>
> Sub GetRdm
> intRdm = Int((122 - 49) * Rnd + 48)
> If intRdm > 57 And intRdm < 65 Or intRdm > 90 And intRdm < 97 Then GetRdm
> End Sub
>
>
> wscript.echo strRdm
>
> Set oWshNet = CreateObject("WScript.Network")
>
> sUserName = "localadmin"
>
> sComputerName = oWshNet.ComputerName
>
> Set oUser = GetObject("WinNT://" & sComputerName & "/"& sUserName & ",user")
>
> oUser.SetPassword(strRdm)
> oUser.Setinfo
>