Jump to content

Change Workstationname


Recommended Posts

Is it possible to change the workstation name of the computer by asking for it?

Is it a registry setting? if so i can imagine a batch file with reg add or something like that.

After i install the workstation i get a random name, as last step before i reboot i want to change the workstationname to the names we use in our company.

Link to comment
Share on other sites


I think i found a solution here:

WSNAME CHANGER

Version 2.74i

Date 9 October 2005

Author David Clarke

Function To provide an automated method to change a workstations name

Operating Systems Windows 9x, NT4, 2000, XP, 2003

Distribution Status Freeware, subject to Disclaimer

What's New In This Version?

Modified the string truncation routine so you can specify truncation from left or right hand side

Modified the %SERIALNUM call so it now queries WIN32_BIOS and if there is no serial number there it will now also look in WIN32_SystemEnclosure.

For a full list of changes, see the change log

Command Line Switches

/H /?

Opens this document

/N:<new name>

Silent Operation. Updates computer name without intervention, no dialogue is shown

This command switch supports the following variables:

%MAKE Computer Manufacturer from the BIOS using WMI (WMI functions require Windows 2000 or later)

%MODEL Computer Model from the BIOS using WMI

%SERIALNUM Computer Serial Number from the BIOS using WMI

%MAC MAC Address of the primary Ethernet Adapter as the Computer Name

%MAC2 MAC Address of the primary Ethernet Adapter as the Computer Name, forces use of the IPCONFIG method (refer here)

%IP IP Address of the primary Ethernet Adapter as the Computer Name (swaps the '.' for '-' to avoid DNS confusion)

%DNS

%DNS:<dns server> Determine Workstations new using Reverse DNS lookup, see below for more details for reverse lookup mode

%USERID Name to the name of the currently logged in user

%OSVER TLA for OS Version (W95, W2K etc)

%RANDOM Generates a random 15 Character name

/IGNOREMEMBERSHIP Ignore Domain Membership checking

/WG:<workgroup> Specify the Workgroup membership

/UNREG

Checks the "Unregister Workstation" function (if UNREG32.EXE is in the path)

/PG:<Name to Check>

Post Ghost mode, see below for more details on Post Ghost

/NS

Name Sync mode, sets the host name to the computer name, no dialogue is shown

/REBOOT

Reboot on completion, only effective when using /NS or /N (reboots only if name is changed)

/NOREBOOT Suppresses reboot prompt in GUI mode

/MCN Sets 'My Computer' name on the desktop to the Computer Name

/SCD Sets Computer Description to the Computer Name

/SCD:<description> Sets Computer Description to specified string, enclose in quotes if the string contains spaces. Max length 256 characters.

/SDL Set Drive Label, sets the label of drive C:\ to the Computer Name

(On non-NTFS drives the name is truncated to 11 characters as this is the max length of a drive label with the FAT and FAT32 file system)

/LOT Sets "Log On To" option in the logon GINA to the machine name (WinNT + only)

/CHO Changes Host Name only (Leaves NetBIOS name unchanged)

/ADR Always Do Rename, WSName normally stops processing if the old and new names are the same, this switch ignores this test

/RCID Rename Computer in Domain

/USER: Name of user with rights to perform the /RCID operation

/PASS: Password of user with rights to perform the /RCID operation

/RDF: Read new name from data file

/DFK: Data file key

/TEST Goes through the motions, does not perform the rename

Silent Mode

Silent mode does not display the GUI interface and is initiated using the /N switch.

You can specify a new name or use a combination of variables to build a name that suits you requirements. You can also truncate strings ensure the result will fit in the 15 char size limit by specifying the size in square brackets "[]".

By default all strings are truncated from the left hand side, to truncate from the right append a "+" to the number.

eg: [6] First 6 characters from the left

[+5] First 5 characters from the left

[9+] Last 9 characters from the right

So putting it all together..

eg: wsname /N:WKS%MAC will give you a new name of WKS00508B052AE8

wsname /N:W-%IP "

W-10-0-0-100

wsname /N:MYORG-%RANDOM[9] "

MYORG-456278803

wsname /N:%MAKE[4]-%RANDOM[10] "

TOSH-KECJRTDJQU

Setting Workgroup Membership

The /WG:<workgroup> option gives the ability to change the Workgroup membership, this command can be run either on its own or in conjunction with a rename.

e.g. wsname /WG:wgroup

or wsname /N:Computer1 /WG:wgroup

Notes:

Added in version 2.74

Will not move a computer that is joined to a Domain into a Workgroup

This function uses the NetJoinDomain API so is supported on Windows 2000 or later only

Logging

WSName creates an extensive log of its operations in the %TEMP% directory (WSName.log). Check this out to see what WSName is doing.

Renaming Remote Computers

Click here to view a sample VB script that enables you to rename remote computers (uses WMI so only Windows 2000 and above) or if you are more comfortable with Batch files then check out this version that uses PSEXEC from SysInternals.

Post Ghost Mode [Top]

Post Ghost mode checks the name of the computer against the name passed with the /PG switch, if the names match the standard dialog is shown, otherwise the program terminates.

As workstations build via Ghost (or similar cloning tool) will have the same name the idea was to call WSName via a login script or Novell Application Launcher (NAL) force run to remind the workstation builder to set the workstations name correctly.

Reverse DNS Lookup

This mode of operation performs a reverse DNS lookup against the primary DNS server to determine the workstations name. This may be handy for those installations using static IP address assignments but should work ok with dynamic DNS sites too.

You can either parse the IP address of a DNS server that holds the PTR records for the target workstation, or allow WSName to use your primary DNS server setting.

e.g. wsname /N:%DNS

wsname /N:%DNS:192.168.30.55

The GetNetworkParams API call is used to find the DNS server for supported operating systems, otherwise the program will try to use "winipcfg" or "ipconfig" and capture the output.

Data File Mode

This mode of operation looks in a text file for the new name. This gives the ability to build up a data file that maps devices to their names. The most obvious identifier to search on is the MAC address or Serial Number

If the path to the data file or the search key contain spaces, you will need to wrap them in quotes.

Syntax

wsname /RDF:DataFile /DFK:SearchKey

Example

wsname /RDF:"F:\DATA\MACAddress to PC Name.txt" /DFK:00508B052AE8 or

wsname /RDF:"F:\DATA\MACAddress to PC Name.txt" /DFK:%MAC or

wsname /RDF:"F:\DATA\MACAddress to PC Name.txt" /DFK:%SERIALNUM

Example Data File Format

00508B052AE8 = Computer1

005056C00008 = Computer2

005056C00001 = Computer3

....

How WSName Works

Windows 9x and Windows NT 4.0

The workstation name is read using the "GetComputerName" API can and set using the "SetComputerName" API call, sadly both of these functions only concern themselves with the NetBIOS name, the TCPIP name (hostname) needs to be manipulated separately, I can't find an API that does this (and if you know of one please let me know) so WSName writes directly to the registry, the keys that hold this information differ between Windows NT and Windows 9x.

Windows NT HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\

Windows 9x HKLM\SYSTEM\CurrentControlSet\Services\VxD\MSTCP\

Windows 2000 and above - Rename Stand Alone Workstation

Windows 2000 and later support the new and improved SetComputerNameEx API, this allows us to set the Host and NetBIOS name together.

Windows 2000 and above - Rename Workstation in Domain

If the "Rename in Domain" option (/RCID) is selected the NetRenameMachineInDomain API is used, this renames the Workstation and updates the Domain or Active Directory with the new name. Remember that you will need to pass a username and password with appropriate Domain rights delegated to perform this function.

In all cases the workstation needs to be rebooted for the change to take effect.

Running UNREG32.EXE

WSName looks for UNREG32.EXE in the search path during the program load, if it is found then the "Unregister Workstation" tick box is enabled.

UNREG32.EXE removes the registry information about the workstation registration from HKLM\SOFTWARE\NOVELL\WORKSTATION MANAGER\IDENTIFICATION, it does not remove any objects from within Novell Directory Services (NDS).

UNREG32 is a component of Novell's ZENWorks for Desktops.

The Workstation Name

WSName examines the new workstation name for validity based on the following:

Microsoft Support Document Q188997 details that valid NetBIOS computer names can be up to 15 alphanumeric characters with no blank spaces. The name must be unique on the network and can contain the following special characters:

! @ # $ % ^ & ( ) - _ ' { } . ~

The following characters are not allowed:

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

Microsoft Support Document Q244739 suggests that it's not a good idea to start a computer name with a hyphen (-).

With Windows 2000 and above the computer name cannot be all numeric (like 1234). This is due to the increased reliance on DNS name resolution which does not allow this naming scheme. This is detailed in knowledge base article Q248412.

Additionally with Windows 2000 and above, a computer name cannot contain a period (.) as the text to the right of the period would be treated as part of the DNS domain name. As WSName sets both the NetBIOS and Hosts names this restriction is applied to all OS versions.

Host names have slightly looser naming rules but since we want computer and host name to be the same, WSName uses the most restrictive.

Renaming a Workstation that is a member of a Domain [Top]

Renaming a workstation that is a member of a domain is supported on Windows 2000 and later versions only.

This option requires access to the domain so a User ID and Password is required. For security the password is masked in the logfile.

eg: wsname /n:mynewname /rcid /user:mydomain\administrator /pass:secret

Note: If the new computer name already exists in the Domain the operation will fail with a 2224 error (The user account already exists). The same error occurs if you try to change the computer name through the GUI (my computer | properties | computer name | change). The only work around for this I can think of is to add additional logic to delete this existing account, the obvious risk is that this account could be being used by another computer. If anyone has any thoughts on this I'm open to ideas!

Microsoft Support Document Q175023 shows the renaming of a Windows NT workstation to be very painful, I'm not going to code that!

Using the MAC Address

The MAC Address checks for OS support of the GetAdaptersInfo API and will use it if available. If it's not there (Win95 and NT4) then the old unreliable NetBIOS method is used.

The NetBIOS method is known to fail sometimes if the machine is disconnected from the network (media disconnected) or if the machine has no NetBIOS support.

If the NetBIOS method does fail then the program will try to use "winipcfg" or "ipconfig" to capture the output. (if you want to force using this method you can use %MAC2 rather than %MAC)

Please note that as this method uses screen scraping it will fail on non English versions of Windows.

If you wish to use the MAC address as the machine name you should consider adding a character prefix as some MAC addresses are all numeric and this will cause the new name to be rejected by the name validity test.

Edited by freburg
Link to comment
Share on other sites

I placed WSNAME.EXE and WSNAME.CMD in the $OEM$\$1\Install-folder

I added WSNAME.cmd to RunOnceEx.cmd just before my cleanup process

RunOnceEx.cmd:

REG ADD %KEY%\998 /VE /D "Change Workstation Name" /f
REG ADD %KEY%\998 /V 1 /D "%systemdrive%\install\wsname.cmd" /f

wsname.cmd:

SET /P COMPNAME=What is the computer name?:
wsname.exe /N:%COMPNAME%

I know this results in a not 100% unattended setup, but this is the last action done before the reboot.

In the same way you could add it to a workgroup of your choise (WSNAME.EXE /WS:<Workgroupname>)

Link to comment
Share on other sites

  • 2 weeks later...

Can anyone provide info on the possibility of renaming a workgroup xp machine without a reboot?

I'm interested in booting a static xp image (.iso, vmware, virtualpc) and being able to give it a name when it starts. I don't care about ad or domains in this case.

Thanks!

Link to comment
Share on other sites

  • 3 months later...

Hi,

Is it possible to change the IP-adress with this program ? I'm searching for a tool (or creating one by myself) that prompts the user to give the computername AND IP-adresss.

Thx in advance!

Edited by Jeroeneke
Link to comment
Share on other sites

I placed WSNAME.EXE and WSNAME.CMD in the $OEM$\$1\Install-folder

I added WSNAME.cmd to RunOnceEx.cmd just before my cleanup process

RunOnceEx.cmd:

REG ADD %KEY%\998 /VE /D "Change Workstation Name" /f
REG ADD %KEY%\998 /V 1 /D "%systemdrive%\install\wsname.cmd" /f

wsname.cmd:

SET /P COMPNAME=What is the computer name?:
wsname.exe /N:%COMPNAME%

I know this results in a not 100% unattended setup, but this is the last action done before the reboot.

In the same way you could add it to a workgroup of your choise (WSNAME.EXE /WS:<Workgroupname>)

Man & Welcome

But please why soo many freakin posts, pleaaase use the edit button its your friend.

Cheers

MC.

Link to comment
Share on other sites

Hi everyone !

Great tool ! Just one question ... is there a way to determine which is the primary ethernet adapter if more than one nic is installed ? I would need this since the tool only checks the MAC adress of the primary NIC.

Thanks for your help !

Bye,

Alex

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...