[精讚] [會員登入]
433

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

你可能感興趣的文章

管理Google共用雲端硬碟 管理Google共用雲端硬碟

臺中市雲端校務系統與Windows AD帳號整合(3) LDAP的基本概念

tc web 問與答 Q. 填報網址 A. https://tiny.cc/tc-web Q. 出現了以下畫面, 怎麼辦 A. 建議瀏覽器開無

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

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

vim 特定範圍行數開頭加上# 註解 vim 特定範圍行數開頭加上# 註解

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

[vue.js] 設定 content type 今天在wickt 端怎麼就是收不到vue.js 以post 傳過來的資料 找了好久才發現 application/jso

proxmox lxc 救援 今天突然接到一名強者我朋友的臨時求援 他說他把pve 從5.1升到5.2後, kvm的虛擬机器都沒問題 , 但是lxc的

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

2018 hoc 頒獎 校慶到了,啦啦隊比賽如火如荼展開,學務主任將頒發獎狀給表現優異的班級。請完成以下程式碼,讓程式將啦啦隊表演成績由高至低依序輸出。

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