Jump to content
Sign in to follow this  
chucks0

WMI and Rename Method

Recommended Posts

I am trying to use WMI to rename a Windows XP computer, but I can't seem to get the syntax quite right. The vbscript equivalent from http://msdn.microsoft.com/library/default....putersystem.asp looks like:

Name = "name"
Password = "password"
Username = "username"

Set objWMIService = GetObject("Winmgmts:root\cimv2")

' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in _
    objWMIService.InstancesOf("Win32_ComputerSystem")

        Return = objComputer.rename(Name,Password,User)
        If Return <> 0 Then
           WScript.Echo "Rename failed. Error = " & Err.Number
        Else
           WScript.Echo "Rename succeeded." & _
               " Reboot for new name to go into effect"
        End If

Next

Any suggestions?

Share this post


Link to post
Share on other sites

I am trying to use WMI to rename a Windows XP computer, but I can't seem to get the syntax quite right. 

$name = "name"
$password = "password"
$user = "user"

$objWMIService = ObjGet("Winmgmts:root\cimv2")

for $objComputer in $objWMIService.InstancesOf("Win32_ComputerSystem")

        $return = $objComputer.rename($name,$password,$user)

        if $return <> 0 then
           msgbox(4096, "Error", "Rename failed. Error = " & $return) 
        else
           msgbox(4096, "OK", "Rename succeeded. Reboot for new name to go into effect")
        endIf
next

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

$name = "name"
$password = "password"
$user = "user"

$objWMIService = ObjGet("Winmgmts:root\cimv2")

for $objComputer in $objWMIService.InstancesOf("Win32_ComputerSystem")

        $return = $objComputer.rename($name,$password,$user)

        if $return <> 0 then
           msgbox(4096, "Error", "Rename failed. Error = " & $return) 
        else
           msgbox(4096, "OK", "Rename succeeded. Reboot for new name to go into effect")
        endIf
next

Cheers

Kurt

Woaw, thnx guys!

just what i needed :P u guys are :) 's

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...