[精讚] [會員登入]
423

對照mac address 批次更改電腦名稱

讀取mac address 對照表, 還原電腦後,自動更改密碼 'show logged on user Dim

分享此文連結 //n.sfs.tw/14686

分享連結 對照mac address 批次更改電腦名稱@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
最後編修
2020-07-17 19:40:24 By igogo
 

 

讀取mac address 對照表, 還原電腦後,自動更改密碼

'show logged on user
Dim CurrentUser
Set objNetwork = CreateObject("Wscript.Network")
CurrentUser=objNetwork.UserName

If CurrentUser <> "Administrator" then
  Wscript.Echo "Administrator is needed. Try command in cmd " &  vbCRLF & "net user administrator /active:yes" 
End IF

'read mac_table 
Dim row,csv_file

row=0
csv_file="c:\mac.csv"
'Wscript.Echo csv_file
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (csv_file, ForReading)
'讀取筆數
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    row=row+1   
Loop

objTextFile.Close

ReDim mac_tables(row-1,1)
Dim j
j=0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (csv_file, ForReading)

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")
    'Wscript.Echo "Server name: " & arrServiceList(0)
    mac_tables(j,0) = arrServiceList(0)
    For i = 1 to Ubound(arrServiceList)
        'Wscript.Echo "Service: " & arrServiceList(i)
	mac_tables(j,i) = arrServiceList(i)
    Next
    j=j+1   
Loop

 objTextFile.Close
 
'For j = 0 To UBound(mac_tables) 
'  Wscript.Echo mac_tables(j,0)
'Next  

'Wscript.Echo row

Dim CurrentName
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings 
    'Wscript.Echo "System Name: " & objComputer.Name
    CurrentName=objComputer.Name  
Next

Set colAdapters = objWMIService.ExecQuery _ 
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True") 
For Each objAdapter in colAdapters 
  
  
  For j = 0 To UBound(mac_tables)
         
    If UCase(objAdapter.MACAddress) = UCase(mac_tables(j,0)) then
	'Wscript.Echo objAdapter.MACAddress
	  If UCase(CurrentName) <> UCase(mac_tables(j,1)) then
          'Wscript.Echo CurrentName & "vs" & mac_tables(j,1)
          
          Set objWMIService = GetObject("Winmgmts:root\cimv2")

          ' Call always gets only one Win32_ComputerSystem object.
          For Each objComputer in _
            objWMIService.InstancesOf("Win32_ComputerSystem")
       
       
            Return = objComputer.rename(mac_tables(j,1))
            If Return <> 0 Then
              WScript.Echo "Rename failed. Error = " & Err.Number
            Else
              'WScript.Echo "Rename succeeded." & _
              '" Reboot for new name to go into effect"
			 
			  Const TIMEOUT = 5
			  Set objShell = WScript.CreateObject("WScript.Shell") 
			  objShell.Popup "Rename succeeded. Reboot for new name to go into effect", TIMEOUT
	
             '重啟電腦
             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

            End If

          Next 
 
	  Else
        'WScript.Echo "delete this script."
        Set oFso = CreateObject("Scripting.FileSystemObject") : oFso.DeleteFile Wscript.ScriptFullName, True
        Set oFso = CreateObject("Scripting.FileSystemObject") : oFso.DeleteFile csv_file, True	    
	  End If	 
    End If  
                           
  Next   
 
Next 

 

END

你可能感興趣的文章

臺中市雲端校務系統與Windows AD帳號整合(6) 修改Windows AD 密碼原則

[shell script] 批次判斷domain name 正解設定 判斷dns 正解設定

centos 7 移机出現 dracut-initqueue timeout centos 7 移机出現 dracut-initqueue timeout 處理

mongo備份指令 mongodump --host localhost --port 27017 --username root --db

臺中市雲端校務系統與Windows AD帳號整合(2) 安裝Active Directory網域服務

在docker裡跑spring boot+mongo(二) 使用docker-compose 管理多個container 前篇使用docker run 一次建一個container

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

00-F2 的 IPV6 反解設定 近日, 強者我的大神同事, line 傳來一句: igogo 上次你那個ipv6的設定檔 再幫我跑一次 如連結 程式都寫

[scratch2] 巢狀迴圈 有兩清單 一數字 一英文 想排出所以可能, 例如1a,1b,1c,2a,2b,2c...3c 利用巢狀迴圈 內圈累加的變

刪除資料夾內的檔案 lambda 一行文 Arrays.stream(new File("/folder/path").

[web] 自訂模組-打字機與跑馬燈效果 自訂模組-打字機效果