Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change comp name, & strCompN

Status
Not open for further replies.

slint

Technical User
Jul 2, 2006
48
SE
Have some trouble with this one..

The code below is taken from microsofts site -
As it is now the script works, but...

Code:
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("WebServer")
Next

If i moify it to this then it doesnt work. The comp name is not renamed.
Code:
strCompN = "COMP1"

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(&strCompN)
Next

A: This can not be done!
B: Typo
C: Just wrong!


If A Then OK
Else
If B Then Pls Help me!
Else If
If C Whats wrong?
End If
Next
 
B or C:
err = objComputer.Rename(strCompN)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Strange...

I tryed your example yesterday and it worked one time.. then nothing.. but today it's working again.

I guess i had a typo somewhere else yesterday..

Thnx PHV!
 
I found the prob wy it didnt work yesterday.

The prob was that i named the strCompN like this
strCompN = "00001"
And as i can se now if i use a zero in the begining it dosent work but if i place a letter infront like this
strCompN = "A0001" then it works.

Is it because i cant have a comp name begining with zero or is it the script that cant handle it?
 
Default limitations are:
[1] It cannot be solely of numbers, periods, or spaces.
[2] Leading periods or spaces are disregarded.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top