Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 更改Windows计算机名BAT文件_Batch File - Fatal编程技术网

Batch file 更改Windows计算机名BAT文件

Batch file 更改Windows计算机名BAT文件,batch-file,Batch File,我想从使用BAT文件的用户输入更改windows 7计算机的名称。我要更改的名称是“高级系统设置”中的计算机名称。(见下面的屏幕截图) 下面的代码是我尝试过的,但不起作用。我还尝试过以管理员身份运行代码,然后重新启动,但也没有成功 SET /P PCNAME=Please enter your name: REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG

我想从使用BAT文件的用户输入更改windows 7计算机的名称。我要更改的名称是“高级系统设置”中的计算机名称。(见下面的屏幕截图)

下面的代码是我尝试过的,但不起作用。我还尝试过以管理员身份运行代码,然后重新启动,但也没有成功

SET /P PCNAME=Please enter your name: 
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %PCNAME% /f

一个快速的google会带来以下命令:

WMIC ComputerSystem where Name=COMPUTERNAME call Rename Name=NewName
如果计算机名包含破折号或其他特殊字符,则需要引用计算机名

WMIC ComputerSystem where Name="COMPUTER-NAME" call Rename Name=NewName

使用powershell方法:

Powershell 3.0(Windows 8)引入了
重命名计算机
cmdlet。例如:

Rename-Computer -NewName NewComputerName -Restart
这将重命名计算机并立即重新启动

使用Vbscript方法:

选项显式
Title=“重命名PC”
Dim Title,strComputer,objWMIService,strNewName,objComputer
Dim Obj、问题、错误、标准说明、colComputers、x
'以管理员身份运行
如果不存在WScript.Arguments.Named.Exists(“提升”),则
CreateObject(“Shell.Application”).Shell执行DblQuote(WScript.FullName)_
,DblQuote(WScript.ScriptFullName)和“/提升”,“运行方式”,1
WScript.Quit
如果结束
“*********************************************主脚本****************************************
调用Rename_PC()
'如果要更改计算机的说明,应取消对此行的注释:
'呼叫更改_Descrption()
调用Ask4Reboot()
“**********************************更改电脑名称*************************************
分包商(PC)
strComputer=“”
设置objWMIService=GetObject(“winmgmts:”\u
&“{impersonationLevel=impersonate}!\\”&strComputer&“\root\cimv2”)
strNewName=Inputbox(“输入电脑的新名称:”,标题,“Salle Poste”)
如果strNewName=“”,则Wscript.Quit()
设置colComputers=objWMIService.ExecQuery(“从Win32\U ComputerSystem中选择*)
对于colComputers中的每个对象计算机
err=objComputer.Rename(strNewName)
下一个
端接头
“*************************更改描述**********************************
子更改描述()
strDescription=Inputbox(“输入说明:”,标题,“机器blalllaaaaa”)
如果strDescription=“”,则Wscript.Quit()
Set Obj=GetObject(“winmgmts:\\”&strComputer).InstancesOf(“Win32\u操作系统”)
对于Obj中的每个x
x、 Description=strDescription
x、 放_
下一个
端接头
'***************************************************************************************
子Ask4Reboot()
问题=MsgBox(“PC名称将更改”&DblQuote(strNewName)&“重新启动此计算机后”&vbCrLf&_
“是以重新启动”&vbCrLF&_
“否以取消重新启动”&vbtab&“?”,VbYesNo+VbQuestion,Title)
如果问题=是,那么
重新启动()
其他的
wscript.Quit(1)
如果结束
端接头
'**************************************
函数DblQuote(Str)
DblQuote=chr(34)和Str&chr(34)
端函数
'**************************************
子重新启动()
调暗ws、命令、结果
设置ws=CreateObject(“Wscript.Shell”)
Command=“Shutdown.exe/r/t 20/c”&DblQuote(“保存您的文档-电脑将在20秒后重新启动”)
结果=ws.run(命令,0,True)
端接头
'**************************************

一个快速的google会带来以下命令:

WMIC ComputerSystem where Name=COMPUTERNAME call Rename Name=NewName
如果计算机名包含破折号或其他特殊字符,则需要引用计算机名

WMIC ComputerSystem where Name="COMPUTER-NAME" call Rename Name=NewName

使用powershell方法:

Powershell 3.0(Windows 8)引入了
重命名计算机
cmdlet。例如:

Rename-Computer -NewName NewComputerName -Restart
这将重命名计算机并立即重新启动

使用Vbscript方法:

选项显式
Title=“重命名PC”
Dim Title,strComputer,objWMIService,strNewName,objComputer
Dim Obj、问题、错误、标准说明、colComputers、x
'以管理员身份运行
如果不存在WScript.Arguments.Named.Exists(“提升”),则
CreateObject(“Shell.Application”).Shell执行DblQuote(WScript.FullName)_
,DblQuote(WScript.ScriptFullName)和“/提升”,“运行方式”,1
WScript.Quit
如果结束
“*********************************************主脚本****************************************
调用Rename_PC()
'如果要更改计算机的说明,应取消对此行的注释:
'呼叫更改_Descrption()
调用Ask4Reboot()
“**********************************更改电脑名称*************************************
分包商(PC)
strComputer=“”
设置objWMIService=GetObject(“winmgmts:”\u
&“{impersonationLevel=impersonate}!\\”&strComputer&“\root\cimv2”)
strNewName=Inputbox(“输入电脑的新名称:”,标题,“Salle Poste”)
如果strNewName=“”,则Wscript.Quit()
设置colComputers=objWMIService.ExecQuery(“从Win32\U ComputerSystem中选择*)
对于colComputers中的每个对象计算机
err=objComputer.Rename(strNewName)
下一个
端接头
“*************************更改描述**********************************
子更改描述()
strDescription=Inputbox(“输入说明:”,标题,“机器blalllaaaaa”)
如果strDescription=“”,则Wscript.Quit()
Set Obj=GetObject(“winmgmts:\\”&strComputer).InstancesOf(“Win32\u操作系统”)
对于Obj中的每个x
x、 Description=strDescription
x、 放_
下一个
端接头
'***************************************************************************************
子Ask4Reboot()
问题=MsgBox(“PC名称将更改”&DblQuote(strNewName)&“重新启动此计算机后”&vbCrLf&_
“是以重新启动”&vbCrLF&_
“否以取消重新启动”&vbtab&“?”,VbYesNo+VbQuestion,Title)
如果问题=是,那么
重新启动()
其他的
wscript.Quit(1)
如果结束
端接头
'**************************************
函数DblQuote(Str)
DblQuote=chr(34)和Str&chr(34)
端函数
'**************************************
子重新启动()
调暗ws、命令、结果
设置ws=CreateObject(“Wscript.Shell”)
Command=“Shutdown.exe/r/t 20/c”&DblQuote(“保存您的文档-电脑将在20秒后重新启动”)
结果=ws.run(命令,0,True)
端接头
'**************************************
his issu