/build/static/layout/Breadcrumb_cap_w.png

Rename a computer using wmic

K1000, online kscript, run as local system, Microsoft Windows - I have the following:

Launch "SYS\ runas /user:administrator cmd.exe" with params "/c wmic ComputerSystem where Caption='CCILTIT99' call Rename Name=CCILTIT12"

With or without the runas the script fails with error code 5 'access is denied.

Any thoughts?

 


3 Comments   [ + ] Show comments
  • Any chance the computer is on a domain? If it is then the error 5 might indicate that the local user doesn't have permission to change the domain account. - chucksteel 10 years ago
  • yes on a domain but I thought the runas administrator would take care of that. - nadecats 10 years ago
  • Run as administrator just takes care of rights on the local PC. You have to be logged in as a user that has modify rights to the machine account at the domain level. - BHC-Austin 10 years ago

Answers (2)

Posted by: SMal.tmcc 10 years ago
Red Belt
0

I had to unjoin them, rename, and rejoin them to get wmic to work for machines in the domain.

You may also be able to run the script as a domain user that has local admin rights as well as rights to rename machines in the domain.

to unjoin a machine:

Wmic computersystem where name="%computername%" call unjoindomainorworkgroup


Comments:
  • I use this vbs to join the machines:

    Const JOIN_DOMAIN = 1
    Const ACCT_CREATE = 2
    Const ACCT_DELETE = 4
    Const WIN9X_UPGRADE = 16
    Const DOMAIN_JOIN_IF_JOINED = 32
    Const JOIN_UNSECURE = 64
    Const MACHINE_PASSWORD_PASSED = 128
    Const DEFERRED_SPN_SET = 256
    Const INSTALL_INVOCATION = 262144

    If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
    WScript.Quit
    Else
    strDomain = WScript.Arguments.Item(0)
    strUser = WScript.Arguments.Item(1)
    strPassword = WScript.Arguments.Item(2)

    'set DNS IP address
    If WScript.Arguments.Count = 4 Then
    strDNSIP = WScript.Arguments.Item(3)
    Set objShell = CreateObject("WScript.shell")
    objShell.Run "netsh int ip set dns ""local area connection"" static "& _
    strDNSIP &" primary",0,0
    End If

    End If


    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName

    Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & _
    "\root\cimv2:Win32_ComputerSystem.Name='" _
    & strComputer & "'")
    ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
    strPassword, _
    strDomain & "\" & strUser, _
    NULL, _
    JOIN_DOMAIN+ACCT_CREATE)


    cscript.exe -b join_domain.vbs domain.tmcc.edu domainuser password DCip - SMal.tmcc 10 years ago
Posted by: worzie 10 years ago
Fourth Degree Brown Belt
0

I too use a vbs but much smaller and not via KACE:

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = inputbox ("Please Enter Computer Name","Enter Computer Name","brooklyn-7")

Set objRegistry = GetObject _
("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
strValueName = "srvcomment"
strDescription = inputbox ("Please Enter New Description","Enter Description",".")

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription

strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters\srvcomment"

' Wscript.Echo strDescription

Msgbox("Computer Description Sucessfully Changed to " & strDescription )
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ