想要通过wmi接口修改windows盘符,该如何实现呢?wmi提供了Win32_Volume类,通过该类可以修改盘符。
 
  • python脚本
import wmi
_root_conn = wmi.WMI(privileges=["Shutdown"])
query_str = "select * from Win32_Volume where DeviceID like '%%%s%%'" % volume_id
volume = _root_conn.query(query_str)[0]
volume.DriveLetter = "M:"
volume.put()
 
  • powershell脚本
$Drive = Get-WmiObject win32_volume -Filter "Label = 'xxxx'"
$Drive.DriveLetter = "m:"
$Drive.put()