导航:首页 > 编程语言 > 代码改计算机名字

代码改计算机名字

发布时间:2023-06-01 00:54:38

『壹』 求高手写一个的vbs或bat命令更改计算机名字

sNewName = ComputerName
sNewName="新计算机名"

Set oShell = CreateObject ("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\告派Parameters\"
sCompNameRegPath = sCCS & "吵侍Control\ComputerName\"

With oShell
.RegDelete sTcpipParamsRegPath & "Hostname"
.RegDelete sTcpipParamsRegPath & "NV Hostname"

.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With
Msgbox "计算机名称已袜碰贺经修改成功!"& vbcr &"请重新启动计算机确认改动生效!"

这个是VBE的

『贰』 求win7系统不重启计算机批处理修改计算机名

在修改我们计算机名的时候,修改后总是需要重新启动,丛前余这个很麻烦,下面icech来介绍一种方法,可以解决这个麻烦,让你无需重新启动计算机就可以成功修改计算机名!下面这段批处理代码,拷贝到记事本当中,保存成modify.bat文件,然后运行,提示你输入计算机名的时候就输入你的新计算机名称,然后这个批处理文件就可以帮你自动渗滚修改注册表啦,而且不用重启计算机哟~~~@echo offset /p name=请输您的计算机名悔粗:
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_sz /d %name% /f nul 2nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f nul 2nul
echo 修改计算机名完毕

『叁』 vb自动关机并且可以改变计算机用户名的代码,只要代码就ok了,谢谢了亲们,么么哒亲亲⊙ε⊙

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "空神岁advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long '设置计算机用户名
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const HELP_CONTENTS = &H3&
Const EWX_LOGOFF = 0 '注销
Const EWX_SHUTDOWN = 1 '待机
Const EWX_REBOOT = 2 '重新启动
Const EWX_WAIT = 16
Const EWX_FORCE = 4 '终止没有响应的进程
Const EWX_POWEROFF = 8 '关闭电源

Private Sub Form_Load() '下面的斗睁代码是确保有足够权瞎迟限进行关机操作。
Dim hProcessHandle As Long
Dim hTokenHandle As Long
Dim tmpLuid As LUID
Dim tkpNew As TOKEN_PRIVILEGES
Dim tkpPrevious As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
'获取当前进程的一个伪句柄
hProcessHandle = GetCurrentProcess()
OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkpNew.PrivilegeCount = 1
tkpNew.TheLuid = tmpLuid
tkpNew.Attributes = SE_PRIVILEGE_ENABLED
lBufferNeeded = 0
'允许当前应用程序有关闭操作系统的权限
AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded
End Sub

Private Sub Command1_Click() '执行更改用户名和关机的按钮。

Call ReSetPcName() '先调用更改计算机用户名的模块

ExitWindowsEx EWX_FORCE Or EWX_POWEROFF, 0 '执行关机模块

End Sub

Public Function SetCName(CName) As Boolean
Dim lResult As Long
Dim RV As Boolean
lResult = SetComputerName(CName)
If lResult <> 0 Then
RV = True '修改成功
Else
RV = False
End If
SetCName = RV
End Function

Private Sub ReSetPcName()
If SetCName("我是中国人") = True Then '这儿是你需要修改成的计算机名,也可以使用inputbox自己输入。
MsgBox ("修改成功")
Else
MsgBox ("对不起,没有足够的权限!")
End If
End Sub

附送获取计算机用户名的代码:

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long '获取当前用户名

Private Sub Form_Load()
Dim st As String * 100
Dim pln As Long
pln = 99
GetUserName st, pln '调用获取用户名的API函数
MsgBox Left$(st, pln)
End Sub

『肆』 命令行修改计算机名称

wmic computersystem where "name='%computername%'" call rename "Someyouwana"

也可以 批处理

@echo off

set /p name=请输您的计算机并哪名:

reg add "HKEY_LOCAL_MACHINE\岁粗System\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_sz /d %name% /f

reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /绝雀码d %name% /f

reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f

『伍』 求一段在VB6.0中修改计算机名的代码。如下图:默认修改的计算机名格式为年、月、日。例如:20140907

Private Declare Function SetComputerName Lib "kernel32" Alias "碧芦耐SetComputerNameA" (ByVal lpComputerName As String) As Long
Private Function SetCName(CName As String) As Boolean
Dim lResult As Long
Dim RV As Boolean
lResult = SetComputerName(CName)
If lResult <> 0 Then
RV = True
Else
RV = False
End If
SetCName = RV
End Function

Private Sub Command1_Click()
If SetCName("20140907") Then
MsgBox "修哗腔改悔春成功"
Else
MsgBox "修改失败"
End If
End Sub

『陆』 VB编程,如何修改计算机名称。

是改的NetBIOS的计算机名称。
在看到我的电脑名称的界面,点[其他]按钮,能看到!

『柒』 如何用DOS命令改计算机名字

举例说明:
更改计算机名abc为123
wmic computersystem where “name=’abc’” call rename 123
更改工巧好冲作组WORKGROUP为MyGroup
wmic computersystem where “袜配name=’WORKGROUP’” call joindomainorworkgroup “”,”孝歼",”MyGroup”,1

阅读全文

与代码改计算机名字相关的资料

热点内容
食人族到底有多少部 浏览:498
计算机网络的分类ppt 浏览:119
大连市大数据中心网站 浏览:765
营销型网站全网优化怎么收费 浏览:853
生化危机1在线观看完整版免费收看 浏览:499
在线看的韩国爱情片 浏览:927
看电影不花钱的软件 浏览:771
手机如何rar压缩文件 浏览:632
品牌网站开发需要多少钱 浏览:443
win10z自带壁纸 浏览:246
免费电影电视剧大全 浏览:815
鸿蒙系统如何关闭app登录广告 浏览:358
php5教程pdf 浏览:266
韩国电视剧爱人完整结局 浏览:745
cad文件功能详解 浏览:422
资料员主要收藏哪些种类的文件 浏览:606
文件传送快的软件 浏览:693
下载小电影 浏览:503
这个电影我穿过 浏览:485
沐风之女无删除 浏览:796

友情链接