注册 登录
编程论坛 VB6论坛

一个不用重启更改机器名和工作组的批处理程序,在VB中为什么会报错

ts_2000 发布于 2022-03-23 07:55, 1639 次点击
一个不用重启更改机器名和工作组的批处理程序,修改在VB中用shell调用,为什么更改机器名正常,但改工作组的语句就总是报错,实例不可用?。

@echo off
echo
set /p name=请输您的计算机名:
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
echo.
echo 修改计算机名完毕
echo.
echo
set /p work1=请输入您的工作组名:
wmic computersystem where Name="%COMPUTERNAME%" call JoinDomainOrWorkgroup Name="%work1%"
echo 修改工作组完毕
pause>nul
echo.
4 回复
#2
yuma2022-03-23 18:43
你是怎么改的,代码发上来看一下。
#3
ts_20002022-03-24 08:56
shell "cmd /c reg add ""HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName"" /v ComputerName /t reg_sz /d " &text1.text &" /f >nul 2>nul
shell "cmd /c reg add ""HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters"" /v ""NV Hostname"" /t reg_sz /d " &text1.text &" /f >nul 2>nul
shell "cmd /c reg add ""HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters"" /v Hostname /t reg_sz /d " & text1.text &" /f >nul 2>nul


shell "cmd /c wmic computersystem where Name="" &text1.text &"" call JoinDomainOrWorkgroup Name=""& text2.text """

修改机器名好使,但修改工作组不成功!
#4
yuma2022-03-24 10:20
以下4条命令亲测可以完成。

wmic computersystem where caption='%COMPUTERNAME%' call rename 'DESKTOP-MD1PIA7'-----修改计算机名为DESKTOP-MD1PIA7( 需管理员权限运行)
wmic computersystem where Name="%COMPUTERNAME%" call JoinDomainOrWorkgroup Name="aaa"-----添加当前计算机到指定的工作组aaa中( 需管理员权限运行)
powershell Rename-Computer -NewName "ComputerName"-----修改计算机名为ComputerName( 需管理员权限运行)
powershell Add-Computer -WorkGroupName "Workgroup_Name"-----添加当前计算机到指定的工作组Workgroup_Name中( 需管理员权限运行)

我建议你用下面两条命令,调用难度小一些。

[此贴子已经被作者于2022-3-24 10:37编辑过]

#5
ts_20002022-03-24 14:11
谢谢版主!
1