[精讚] [會員登入]
377

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

你可能感興趣的文章

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

臺中市雲端校務系統與Windows AD帳號整合(9) 3-2 Linux上隨系統開機啟動服務 以Centos 7 發行版為例 請注意, 此時提供服務的主机為Linux, 所以

臺中市雲端校務系統與Windows AD帳號整合(7) 設定校端更改密碼程式及執行

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

openldap資料移到 docker 拉docker 上的 image 回來 docker pull osixia/openldap 在正在運行的openld

shell scirpt 批次建立samba使用者 建立一csv檔, 兩個欄位如下 5101,532 5102,592 5103,321 第一欄為帳號使用班級加座號, 第二

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

java.time 時間 instant java.time

編碼的順序 utf8 big5

讀取特定資料夾下的xls檔 讀取特定資料夾下的xls檔

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

題庫批次匯入google表單 請先建一新試算表, 將題目轉成格式如下 並將網址列記下來, 後續的題目就是從此試算表讀出 題目 答案 選項一 選項二 選