[精讚] [會員登入]
370

對照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

你可能感興趣的文章

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

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

windows ad 如何得知 dn 值 如何得知 windows ad 上的使用者dn 值 https://support.symantec.com/en_US

資料表更改為多個primary key, MariaDB [database]> describe TABLENAME; 想由本來是兩個PRIMARY KE

proxmox zfs 建立異地備份與還原 zfs最吸引人的地方就是可以建立快照並傳輸到遠端机器, 達到增量備份, 並且隨時從任一備份檔還原 完全不怕勒索病毒 將v

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

資料表更改為多個primary key, MariaDB [database]> describe TABLENAME; 想由本來是兩個PRIMARY KE

java.time 時間 instant java.time

雲端校務系統與OPENLDAP帳號整合(1) 本文件目標是為做單一帳號整合, 使用校端更改密碼服務, 將雲端校務系統的帳密同步至校內LDAP server, 並讓SA

雲端校務系統與OPENLDAP帳號整合(2) openldap,雲端校務

Spring Boot Maven wrappers maven, mvnw, build command