Jump to content

Change the computername


Recommended Posts

:hello:

If anyone is interested, it is easy to change the computer name using wmic.exe:

wmic.exe ComputerSystem Where Name="%ComputerName%" Rename Name="NewComputerName"

It requires a reboot but seems to work ... If you don't want to use the environmental variable %ComputerName%, just replace it with the currently active name of the local machine.

:yes:

CF

Link to comment
Share on other sites


Actually, i'm using a third-party tool to rename my HP branded computers using a Prepend string HP-followed by SerialNumber.

zcnclite.exe /wmi:"Win32_BIOS,SerialNumber" /sn:"HP-" /q /forcerun

With your code, i will use this command:

<path>NirCmd.exe script <path>fbreseal.ncl

fbreseal.ncl

execmd for /f %i in ('wmic SystemEnclosure get SerialNumber') do wmic.exe ComputerSystem Where Name="%ComputerName%" Rename Name="HP-%i"
regsetval sz "HKLM\SOFTWARE\HP\Image" "" "HP Preinstalled Image"

:)

Edited by Bilou_Gateux
Link to comment
Share on other sites

Nice one Bilou_Gateux B)

Beware however that this will not work if run at T13 ... Although WMI responds to calls, anything that I tried to set using it, resulted in an error ... The other thing you can do is call the SetComputerNameEx function from kernel32.dll and change ComputerNamePhysicalNetBIOS and ComputerNamePhysicalDnsHostname. A nice VB example for achieving this can be found here. Or you could use this function in XP.

All the above will work on a standalone workstation. You would have to call some AD function to change the computer name if it belongs to a domain. A nice tool to do this is netdom.exe.

For a standalone PC (2k/XP/2k3) I have been using compname.exe up until now. It has some nice features:

Displays SMBIOS information and changes/displays the computer name.

COMPNAME [/c name | /d [template]| /s]

/c[hange] Changes the computer name to the one specified.

/d[isplay] Displays the computer name.

/s[mbios] Displays the serial number information from SMBIOS.

name New computer name. Only valid with the /c option.

This may contain macros; see below.

template When used in conjuction with /d, displays the evaluated name.

Templates will normally contain macros; see below.

The following macros are valid in the name or template.

?s = System serial number. ?c = Chassis serial number.

?b = Mainboard serial number.

?a = The first populated number from system, chassis and mainboard numbers.

?u = System UUID ?U = Fake UUID (24 zeros plus MAC).

?G = If System UUID is FFFF... or 0000... or null it uses ?U, otherwise ?u.

?i, ?j, ?k, ?l = 1st, 2nd, 3rd, 4th octets of IP (decimal).

?I, ?J, ?K, ?L = 1st, 2nd, 3rd, 4th octets of IP (hex).

?d = Hostname found by reverse DNS lookup of IP address.

?m = First MAC address. ?e = Existing NetBIOS computer name.

?D = day ?M = month ?Y = year

?1, ?2, ?3, ..., ?0 = 1, 2, 3, ..., 10 random alphanumeric characters.

Examples:

COMPNAME /d Displays the NetBIOS computer name.

COMPNAME /d ?s Displays the system serial number.

COMPNAME /s Displays system summary information.

COMPNAME /c jupiter Changes computer name to "jupiter".

COMPNAME /c acme-?s Changes computer name to "acme-ABCDEF" where

ABCDEF is the system serial number.

Notes:

* You can simply replace a /c switch with a /d switch to check the name.

* If the name (after macro expansion) is longer than 15 characters,

then the NetBIOS name will be truncated, but the DNS name (on Windows

2000 and above) will be the full length. This may break some applications.

* The following characters (and spaces) are invalid and removed automatically:

\ * + = | : ; " ? < > ,

* The _ character gets translated to - to avoid DNS name problems.

* This program does not rename the computer's domain account.

----------------------------------------------------------------------------

All of the above you can get with WMI. If however you want to rename the computer say at T13 it might be a good idea to use thsi tool :o)

CF

Link to comment
Share on other sites

From Windows XP Embedded documentation:

The WMI Command Line Utility component provides a command-line interface for the Windows Management Instrumentation (WMI infrastructure. This component includes a set of commands and control functions to manage a Windows environment. This component interacts with existing shells and utility commands and can be easily extended by scripts or other administration-based applications.

You can access the WMI infrastructure using a command-line interface and intermediate facilitators, called aliases. Aliases capture the WMI class features that are relevant to a specific task, such as network administration. You can use aliases to rename classes, properties, and methods, or to arrange properties that include property values.

This component enables you to perform the following actions:

  • Define aliases, add output formats, and create and execute scripts
  • Browse the WMI schema and query its classes and instances
  • Get information from a local computer, a remote computer, and multiple computers in a single command

The following table shows the files and applications included in this component.

FileDescriptionCli.mofSchemaCliegaliases.mflLocalization schemaCliegaliases.mofAliasesCsv.xslStyle sheet for comma-separated value formatHform.xslStyle sheet for HTML value list formathtable-sortby.xslStyle sheet for HTML table including sortbyHtable.xslStyle sheet for HTML table format Mof.xslStyle sheet for MOF formatRawxml.xslStyle sheet for raw XML formatTexttable.xslStyle sheet for table formatTexttablewsys.xslOptional style sheet for table formatTextvaluelist.xslStyle sheet for value list formatWmic.chm Windows HelpWmic.exeEngine-parserWmiclimofformat.xslDefault MOF formatWmiclitableformat.xslDefault table formatWmiclitableformatnosys.xslOptional table formatWmiclivalueformat.xslDefault value list formatWml.xslDefault XML formatWsl-mappings.xmlDefault style sheet table

The compilation of Cli.mof, Cliegaliases.mod, and Clialiases.mfl files creates the \\root\cli name space and populates it with aliases. The Wmic.exe file executes queries and calls a method as specified by an alias. The Extensible Markup Language (XML) output is formatted using default style sheets as specified in Xsl-mappings.xml, while other formats can be explicitly specified using /FORMAT:< stylesheet name>.

Services

There are no services for this component.

Associated Components

The WMI Command component is designed to work with the WMI Core and WMI Provider components. The WMI Command component also requires the Tools component to compile Managed Object Formats (MOFs), which occurs during the first boot.

The following components have related functionality:

  • WMI SNMP Provider, which is needed if a user wants to query the SNMP name space.
  • WMI DS Provider, which is needed if a user wants to query the DS name space.

Settings

There are no configurable settings for this component.

Notes

The WMI Command component can only be used by local system administrators, regardless of WMI name space permissions on the local computer.

At T13, we're using the System account

Link to comment
Share on other sites

Interesting ...

And if you try to run wmic with the /User:Administrator /Password:... options it complains thet user credentials cannot be used for local connections ...

RunAs doesn't work either ...

:(

CF

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...