Jump to content
Sign in to follow this  
marcsusy

Error changing computer name using WMI. please help

Recommended Posts

marcsusy
I'm trying to rename a computer in a domain and I get the following error:
 
: ==> The requested action with this object has failed.:
 
$rc = $objWMIComputerSystem.Rename($NewComputer,$sPassword,$sUserName)^ ERROR
 
 
The script is used:
 
 
$sHost = "HOST"
$sDomain = "Domain"
$sUserName = "User"
$sPassword = "pass"
$NewComputer = "NEW_HOST"
 
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIComputer = $objSWbemLocator.ConnectServer($sHost, "rootcimv2", $sDomain&""&$sUserName, $sPassword)
$objSWbemLocator.Security_.ImpersonationLevel = 3
$objWMIComputerSystem = $objWMIComputer.Get("Win32_ComputerSystem.Name='" &$sHost & "'")
 
$rc = $objWMIComputerSystem.Rename($NewComputer,$sPassword,$sUserName)
 
IF $rc <> 0 then
MsgBox(0,"","failed")
Else
    MsgBox(0,"","Successfully renamed")
Endif
 

Share this post


Link to post
Share on other sites
water

Add a COM error handler to get better error description. See how to do so in the help file for ObjEvent.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
marcsusy

Thanks I' ll Tray, Water

Share this post


Link to post
Share on other sites
marcsusy
I tried this new script at home and it works correctly, but at work it does not work, do not get any errors but does not change the hostname, I get the message failed, not why
 
$strComputer     = "HOST"       
$strNewComputer  = "NEWHOST"   
$strDomainUser   = "User"     
$strDomainPasswd = "pass"
$strLocalUser    = "HOSTAdminuser" 
$strLocalPasswd  = "passadmin"
 
$oErrorHandler = ObjEvent("AutoIt.Error","ObjErrorHandler")
 
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMILocator.Security_.AuthenticationLevel = 6
$objWMIComp = $objWMILocator.ConnectServer($strComputer, _
                                             "rootcimv2", _
                                             $strLocalUser, _
                                             $strLocalPasswd)
 
$objWMICompSys = $objWMIComp.Get("Win32_ComputerSystem.Name='" & $strComputer & "'")
 
$intRC = $objWMICompSys.Rename($strNewComputer, _
                             $strDomainPasswd, _
                             $strDomainUser)
IF $intRC <> 0 then
MsgBox(0,"","Fail")
Else
    MsgBox(0,"","Successfully renamed")
Endif
 
 
Func ObjErrorHandler()
     Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oErrorHandler.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oErrorHandler.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oErrorHandler.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oErrorHandler.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oErrorHandler.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oErrorHandler.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oErrorHandler.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oErrorHandler.helpcontext _
            )

Share this post


Link to post
Share on other sites
water

What is the value of $intRC, @error and @extended after the rename?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
marcsusy

Water

I get the error  is $intRC 1323

Share this post


Link to post
Share on other sites
water

According to this documentation it means:

ERROR_WRONG_PASSWORD

Unable to update the password. The value provided as the current password is incorrect.

1323 (0x52B)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

I think your problem is described here: "However, you cannot use the method remotely for domain computers."wever, you cannot use the method remotely for domain computers."


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Google offers a lot of solutions for this problem.

One of them can be found here.

The AD part can be solved using my AD UDF (for download please check my signature).


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×