Jump to content

Yens

Member
  • Posts

    2
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    Belgium

Posts posted by Yens

  1. here's the script I cobbed together

    asks for computer name

    - checks for the length to make sure no longer than 13 (netbios names freak out around 15)

    - checks the length for 0 characters

    - checks the name for bogus characters

    strcn = InputBox("Change Name to the following","Please Enter Computername", compname)

    Name = strcn

    name= UCase(Name)

    If Len(name) > 13 Then

    Wscript.echo "The name is too long for use with wins"

    wscript.quit

    End If

    If Len(name) < 1 Then

    Wscript.echo "The name is too short to be used"

    wscript.quit

    End If

    Set objRegEx = CreateObject("VBScript.RegExp")

    objRegEx.Global = True

    objRegEx.Pattern = "[^A-Z0-9]"

    strSearchString = name

    Set colMatches = objRegEx.Execute(strSearchString)

    If colMatches.Count > 0 Then

    Wscript.Echo "The following characters are not allowed:"

    For Each strMatch in colMatches

    Wscript.Echo strMatch.Value

    wscript.Quit

    Next

    End If

    strComputer="."

    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

    For Each objComputer in colComputers

    err = objComputer.Rename(name)

    if err <> 0 then

    wscript.echo "There was an error renaming the machine. Please restart, and try again."

    else

    wscript.echo "Machine successfully renamed: " & Name

    end if

    Next

    This doesn't work

×
×
  • Create New...