Sign in to follow this  
Followers 0
ken82m

Help Converting WMI Script

3 posts in this topic

#1 ·  Posted (edited)

I'm trying to convert this WMI script to AU3. It's supposed to rename a computer.

I think I got everything right, but I'm not sure what to do with "objComputer" on lines 8 and 9.

Thanks,

Kenny

$Name = "testname-xp"
$Password = "password"
$Username = "kmorrissey"

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

;Call always gets only one Win32_ComputerSystem object.
For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem")
    $Return = $objComputer.rename($Name,$Password,$Username)
    If $Return <> 0 Then
        MsgBox(0,"", "Rename failed. Error = " & $Return)
    Else
        MsgBox(0,"", "Rename succeeded." & @CR & "Reboot for new name to go into effect")
    EndIf
Next


#cs   ORIGINAL FROM MSDN
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,Username)
        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
#ce
Edited by ken82m

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites



mild change...

$Name = "testname-xp"
$Password = "password"
$Username = "kmorrissey"

;$objWMIService = ObjCreate("Winmgmts:\root\cimv2")
$objWMIService = ObjGet("winmgmts:\root\cimv2");<<<<<<<<<<<<<<<<<<<<

;Call always gets only one Win32_ComputerSystem object.
For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem")
    $Return = $objComputer.rename($Name,$Password,$Username)
    If $Return <> 0 Then
        MsgBox(0,"", "Rename failed. Error = " & $Return)
    Else
        MsgBox(0,"", "Rename succeeded." & @CR & "Reboot for new name to go into effect")
    EndIf
Next


#cs   ORIGINAL FROM MSDN
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,Username)
        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
#ce

Share this post


Link to post
Share on other sites

Thanks I appreciate it :) -Kenny


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

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  
Followers 0