|
Answer» Hey Everyone,
I am having a problem RENAMING the Computer Name using a bat file I have worked up. What this does is goes out and finds the ServiceTag number from the BIOS and puts it into a variable which is suppose to turn around and rename the Computer Name. It's not working correctly, doesn't rename it.
Here is what I have so far.
Code: [Select]echo off setlocal enabledelayedexpansion set line=1 for /f "delims=" %%A in ('wmic csproduct Get identifyingnumber') do ( if !line! equ 2 set idnumber=%%A set /a line+=1 ) set idnumber=%idnumber: =%
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %idnumber% /f
Any help would be greatly appreciatedAre you running the batch file as an administrator? Simple, but I can't see anything wrong with the code that would cause that.I am. I thought maybe it needs to be rebooted after the program runs, so I have added a reboot command, but still nothing. This is being tested on a WINDOWS 7 Pro x64 machine.Alright Everyone,
I have come up with a solution to my .bat file. I won't use it. I will use a .vbs file instead. This only works with computers not joined to a domain. Works great though. Here is the code:
Code: [Select]WScript.Echo "Before selecting the OK button, please save any" & _ " documents that need to be saved."
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & _ "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objSMBIOS in objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") ' The below variable will be used in the next For Each statement. Dim Name Name = objSMBIOS.SerialNumber
Next
Set objWMIService = GetObject("Winmgmts:root\cimv2")
' This section renames the computer. For Each objComputer in _ objWMIService.InstancesOf("Win32_ComputerSystem")
Result = objComputer.rename(Name) If Result <> 0 Then WScript.Echo "Rename failed. Error = " & Err.Number Else WScript.Echo "Rename successful." & _ " Your machine will reboot after clicking the OK button. Once again, make sure you have saved any documents before clicking OK. NOTE: IF YOU CLICK THE 'X' AT THE TOP RIGHT CORNER OF THE WINDOW, IT WILL REBOOT THE COMPUTER AS WELL." End If
Next 'Reboots the computer. Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _ & "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_ & "Primary=true") for each OpSys in OpSysSet retVal = OpSys.Reboot() next Thanks for all your help guys.
|