wmi接口如何通过Win32_VolumeL类修改盘符

想要通过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()
posted @ 2017-06-18 10:10  妙音  阅读(292)  评论(0编辑  收藏  举报