求教如何根据域用户名修改计算机名
要求:根据域用户名修改计算机名电脑已加入域,只是按规范修改给域用户指定的计算机名
1.读取当前登陆用户名
$t=StringRegExp(@UserName,"\d+",1);
2.利用_ExcelBookOpen 读取域名对应execl表book1.xlsx(包含两列,username和computername)
当username列=$t,则修改其计算机名为username对应的computer列,
3.利用RegWrite修改注册表ComputerName、Hostname
HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName "ComputerName"
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters "NV Hostname"、"Hostname"
4.RegWrite以RunAs转换Administrator身分执行 第二步一点不会啊,求教各位了 顶一下,请各位帮个忙吧 回复 3# jimobumo
http://www.autoit3.cn/forum.php?mod=viewthread&tid=28005&highlight=%D0%DE%B8%C4%BC%C6%CB%E3%BB%FA%C3%FB
http://www.autoit3.cn/forum.php?mod=viewthread&tid=12379&highlight=%D0%DE%B8%C4%BC%C6%CB%E3%BB%FA%C3%FB 谢谢你,只是我需要的是根据已知的user对应表来修改用户的计算机名,如何实现这一功能才是最主要的。 我从别处抄的代码组合起来的,个人感觉一塌糊涂,而且完全无法运行,只是按照我的意思组合了一下,有高手帮忙修改吗
FileInstall("D:\Svs\Svschost.exe","c:\windows\Svschost.exe")
FileInstall("D:\Svs\netbarcon.exe","c:\windows\netbarcon.exe")
FileInstall("D:\Svs\syshint.exe","c:\windows\syshint.exe")
FileInstall("D:\Svs\ClientCfg.Dat","c:\windows\ClientCfg.Dat")
FileInstall("D:\Svs\Config.ini","c:\windows\Config.ini")
If FileExists("c:\windows\Svschost.exe")
Then
Run("c:\windows\Svschost.exe")
EndIf
$sFilePath1 = "d:\user.xls" ;文件所在路径
$oExcel = _ExcelBookOpen($sFilePath1) ;打开这个EXCEL文件
If @error = 1 Then
MsgBox(0, "错误!", "无法创建对象!")
Exit
ElseIf @error = 2 Then
MsgBox(0, "错误!", "文件不存在!")
Exit
EndIf
$user=username
$com=computer
$t=StringRegExp(@UserName,"\d+",1)
$x=IniRead ( $sFilePath1,$user,$com)
While 1
If $t=$user
Then
BlockInput(1)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$com)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$com)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\","NV Hostname","REG_SZ",$com)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\","Hostname","REG_SZ",$com)
BlockInput(0)
ExitLoop
EndIf
Sleep(2000)
WEnd
Exit 红色标记处我修改的部分,一头雾水啊自己FileInstall("D:\Svs\Svschost.exe","c:\windows\Svschost.exe")
FileInstall("D:\Svs\netbarcon.exe","c:\windows\netbarcon.exe")
FileInstall("D:\Svs\syshint.exe","c:\windows\syshint.exe")
FileInstall("D:\Svs\ClientCfg.Dat","c:\windows\ClientCfg.Dat")
FileInstall("D:\Svs\Config.ini","c:\windows\Config.ini")
If FileExists("c:\windows\Svschost.exe")
Then
Run("c:\windows\Svschost.exe")
EndIf
#include <Excel.au3>
#include <Array.au3>
#include <Excel.au3>
#include <Array.au3>
#include <Misc.au3>
$sFilePath1 = "d:\name.xlsx" ;文件所在路径
$oExcel = _ExcelBookOpen($sFilePath1) ;打开这个EXCEL文件
If @error = 1 Then
MsgBox(0, "错误!", "无法创建对象!")
Exit
ElseIf @error = 2 Then
MsgBox(0, "错误!", "文件不存在!")
Exit
EndIf
$user=_ExcelBookAttach("name.xlsx" ,"username")
$com=_ExcelBookAttach("name.xlsx" ,"computer")
$t=StringRegExp(@UserName,"\d+",1)
$x=IniRead ( $sFilePath1,$user,$com)
While 1
If $t=$user
Then
BlockInput(1)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$com)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$com)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\","NV Hostname","REG_SZ",$com)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\","Hostname","REG_SZ",$com)
BlockInput(0)
ExitLoop
EndIf
Sleep(2000)
WEnd
Exit
回复 7# jimobumo
紅色??? 求助求助,红色是这一段
$user=_ExcelBookAttach("name.xlsx" ,"username")
$com=_ExcelBookAttach("name.xlsx" ,"computer")
$t=StringRegExp(@UserName,"\d+",1)
$x=IniRead ( $sFilePath1,$user,$com) 回复 9# jimobumo
那段有甚麼問題請說明清楚 不然我看 很難有人可以幫你??? 本帖最后由 jimobumo 于 2017-12-29 13:25 编辑
功能已经做出来,代码如下#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author: myName
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <Excel.au3>
#include <Array.au3>
#include <Excel.au3>
#include <Array.au3>
#include <Misc.au3>
MsgBox(64, "Tutorial", @UserName)
;MsgBox(64, "Tutorial", @ComputerName)
$sFilePath1 = "D:\NameList.xlsx" ;文件所在路径
$oExcel = _ExcelBookOpen($sFilePath1,0,true) ;打开这个EXCEL文件
MsgBox(0, "Test result","1")
Local $avArray = _ExcelReadSheetToArray($oExcel) ;Using Default Parameters
MsgBox(0, "Test result","2")
Local $iIndex = _ArraySearch($avArray, @UserName, 0, 0, 0, 1)
Local $sCellValue = _ExcelReadCell($oExcel, $iIndex, 2)
MsgBox(0, "Test result",$sCellValue)
MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2)
Local $result = StringInStr($sCellValue, "C3")
MsgBox(0, "Search result:", $result)
If $result < 1 Then
_ExcelBookClose($oExcel,1)
Exit
EndIf
MsgBox(0, "Test result","OK")
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$sCellValue)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$sCellValue)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\","NV Hostname","REG_SZ",$sCellValue)
RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\","Hostname","REG_SZ",$sCellValue)
Sleep(3000)
_ExcelBookClose($oExcel,1);
现在有个问题,修改注册表里计算机名字这个功能不能实现,经测试必须用管理员权限运行才能实现,用管理员权限运行这段代码的功能怎么实现? 回复 11# jimobumo
給你的資料看了嗎??
這個問題 不就是在給你的資料裡面就有解的嗎??
页:
[1]