China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 08:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask: How to read and modify the local computer name and workgroup in batch processing? View 4,428 Replies 8
Original Poster Posted 2006-10-23 01:52 ·  中国 广东 广州 电信
初级用户
Credits 90
Posts 35
Joined 2006-10-23 01:13
19-year member
UID 67781
Gender Male
Status Offline
Searched a lot of materials and couldn't find it. Could anyone please give some guidance?

How to read and modify the computer name and workgroup of the local machine? Thanks
Floor 2 Posted 2006-10-23 02:43 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
It is related to the registry, not much related to batch processing. Just search for the registry key value of the computer name, and use the reg command.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2006-10-23 03:44 ·  中国 甘肃 兰州 城关区 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Query the computer name of the local machine: hostname

To modify, I guess I need to modify the registry~
Floor 4 Posted 2006-10-23 04:56 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
@echo off
echo The local computer name is: %COMPUTERNAME%

echo Workgroup/domain:
wmic computersystem get domain
pause

echo More detailed information:
systeminfo
rem wmic computersystem


Change:

@echo off
echo Change username:
wmic useraccount where "name='3742668" call Rename cool3742668

echo Change computer name:
wmic computersystem where "name='microsoft'" call rename google

echo Change workgroup:
wmic computersystem where "name='google'" call joindomainorworkgroup "","","MyGroup",1


After changing the computer name, the name seen in the right - click of "My Computer" has not changed, but the computer name can be seen to have changed from set, systeminfo, and wmic.
```
Floor 5 Posted 2006-10-23 04:57 ·  中国 甘肃 兰州 城关区 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Floor 6 Posted 2006-10-23 05:46 ·  中国 广东 广州 电信
初级用户
Credits 90
Posts 35
Joined 2006-10-23 01:13
19-year member
UID 67781
Gender Male
Status Offline
Thanks to the moderator's reply. How can I make the workgroup in the properties of "My Computer" change together? There is no workgroup in the registry. It seems that modifying the workgroup through the registry doesn't work.
Floor 7 Posted 2006-10-23 06:08 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Sweat one, you replied without even trying?
I said it can't be displayed only when the permission is insufficient. If it's a member of the administrators group without restrictions, you can directly see the change.
If there are still problems, refer to <Help and Support> and /?.
Floor 8 Posted 2006-10-24 13:05 ·  中国 广西 梧州 电信
初级用户
Credits 22
Posts 11
Joined 2006-05-11 11:29
20-year member
UID 55321
Status Offline
Why is my run not successful?
It shows: No available example.
Mine is the 2003 system
Also:
After entering computersystem /?, the following appears
Usage:
COMPUTERSYSTEM ASSOC [<format specifier>]
COMPUTERSYSTEM CALL <method name> [<actual param list>]
COMPUTERSYSTEM CREATE <assign list>
COMPUTERSYSTEM DELETE
COMPUTERSYSTEM GET [<property list>] [<get switches>]
COMPUTERSYSTEM LIST [<list format>] [<list switches>]
COMPUTERSYSTEM SET [<assign list>]
Hope to give a rough explanation, thank you moderator
Floor 9 Posted 2006-10-24 17:55 ·  中国 河北 石家庄 桥西区 联通
初级用户
Credits 54
Posts 28
Joined 2006-10-16 14:23
19-year member
UID 65980
Gender Male
Status Offline
VBS script that automatically modifies IP and computer name after Ghost! (Seems quite good)

Now launched, the. VBS version of the Ghost machine name and IP address new version.

AutoConfig.vbs

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

On Error Resume Next
'Get the physical address of the local machine's network card: MacAddress
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each objNicConfig In colNicConfigs
Set objNic = objWMIService.Get _
("Win32_NetworkAdapter.DeviceID=" & objNicConfig.Index)

'Write the physical address of the local machine's network card to variable: strMacAddress
strMacAddress = objNic.MACAddress

Next


'Read the configuration file
dim files,file,strReadLine ,RowNumber
Const ForReading = 1
set files=CreateObject("Scripting.FileSystemObject")
if files.fileexists("E:\AutoConfig\config.cfg", ForReading) then
set file=files.opentextfile("E:\AutoConfig\config.cfg")
else
msgbox("Please place the MAC list file (file name: config.cfg) in the program directory")
end if

RowNumber = 0
Do While file.AtEndOfStream <> True
strReadLine = file.ReadLine
RowNumber = RowNumber + 1
If InStr(strReadLine,strMacAddress) <> 0 Then
ComputerConfig = Split(strReadLine , ";")

Exit Do
End If
Loop

'Modify IP address
strComputer = "."

SubnetIPAddress = "192.168.0."
LocalIPAddress = SubnetIPAddress & RowNumber

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(LocalIPAddress)
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.1")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

Next

'Modify machine name
Set WshShell = CreateObject("Wscript.Shell")
Set Fso = CreateObject("SCripting.FileSystemObject")

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", ComputerConfig(0) ,"REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", ComputerConfig(0) ,"REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname", ComputerConfig(0) ,"REG_SZ"


'Modify CS-CDKEY
WshShell.RegWrite "HKCU\Software\Valve\CounterStrike\Settings\Key", ComputerConfig(3),"REG_SZ"
WshShell.RegWrite "HKU\S-1-5-21-839522115-507921405-2146800195-500\Software\Valve\CounterStrike\Settings\Key", ComputerConfig(3),"REG_SZ"
WshShell.RegWrite "HKU\S-1-5-21-1085031214-220523388-839522115-500\Software\Valve\CounterStrike\Settings\Key", ComputerConfig(3),"REG_SZ"
WshShell.RegWrite "HKU\S-1-5-21-1614895754-1417001333-839522115-500\Software\Valve\CounterStrike\Settings\key", ComputerConfig(3),"REG_SZ"

'Delete startup item
WshShell.RegDelete"HKLM\Software\Microsoft\Windows\CurrentVersion\Run\AutoConfig"
Set Wshell=Nothing

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
On Error GoTo 0
----------------------------------------------------------------------------------------

Save as " AutoConfig.vbs" file.

config.cfg

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


Nh002
Nh003
Nh004
Nh005; 00:11:5B:CF:C8:12; 192.168.0.5; 3245164654063
Nh006; 00:11:5B:BD:2F:E4; 192.168.0.6; 3385636230783
Nh007; 00:11:5B:B3:F0:86; 192.168.0.7; 2030698167302
Nh008; 00:11:5B:C8:C8:E1; 192.168.0.8; 7149496192146
Nh009; 00:11:5B:CF:C6:D9; 192.168.0.9; 6823878707810

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

Add your own machine configuration according to the format. Save as "config.cfg"

Add Startup Item.reg


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

Windows Registry Editor Version 5.00


"AutoConfig"="E:\\AutoConfig\\AutoConfig.vbs"

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

Save as " Add Startup Item.reg"

Read the instructions.txt


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

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

###If you have any questions, please contact me,

Contact
QQ: 233002600
E-mail: digsea2000@163.com
-------------------------------------------------------


**************************************************************************************
###The basic idea of this program is:

First, place all machine names, network card addresses, IP addresses, and CS-CDKEY in the "Config.cfg" file.

After the program runs, it reads the local network card address, then finds the corresponding address in the "Config.cfg" file to determine which line it is on,
to determine the local machine name. Then, according to the obtained line number, it configures the IP, CS-CDKEY, etc. that should be set.


###Usage steps

1. Fill in the machine configuration in the "Config.cfg" file in sequence

2. Before making the master disk and preparing to clone, import "Add Startup Item.reg" into the registry

3. After cloning, restart, and the automatic setup starts


###Introduction to the contents of each file:

This program mainly contains 4 files:

Assuming your system is Win2k Pro,

Autoconfig.vbs is the main program for the 2000 system.
Config.cfg is the machine configuration list
Add Startup Item.reg is run after the master disk is made, and the main program can be automatically started after cloning.
Read the instructions.txt is the help instructions


'Autoconfig.vbs is the main program for the 2000 system.
If you can modify it to make the program more efficient. You can do as you like,

If you don't understand, just ignore it.

'Add Startup Item.reg
The function of this file is to make the cloned disk automatically run the main program after startup,
and the main program will automatically delete this startup item after running,
so the main program will only run once and will not run automatically in the future.


Note: The drive letter, path, and folder name in the file are all set.
If you change the path. Please make corresponding modifications to the configuration in this file.


'Config.cfg
Write the MAC address of each machine in the file in sequence, ensure that the No. 1 is written in the first line, and No. 8 is written in the 8th line......

If your machine is numbered directly from No. 10, leave 9 empty lines above, and the MAC of No. 10 machine is written in the 10th line

The writing format of each line must be complete,
such as:
Nh005; 00:11:5B:CF:C8:12; 192.168.0.5; 3245164654063

Because the IP address is determined by the line number where the MAC is located.

If a certain machine number is not continuous, please only write the machine number and keep the MAC empty.

**************************************************************************************

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

Save as "Read the instructions.txt" file.

Put the above four files in the "E:\Autoconfig\ " folder.

If placed elsewhere, you need to modify "AutoConfig.vbs" and " Add Startup Item.reg".

With the above path, you can only modify your machine configuration!~
Forum Jump: