Page 1 of 1

How to get windows disk device instance path by python?

Posted: Thu Jan 02, 2020 2:50 am
by zfm076
Hi,How to get windows disk device instance path by python?

Re: How to get windows disk device instance path by python?

Posted: Thu Jan 02, 2020 8:28 am
by stijn
You mean Python or MicroPython?

First case you can parse output of e.g.

Code: Select all

import os
os.popen('wmic diskdrive get PNPDeviceID').read() 
(your question doesn't specify which device, this will list all of them..)

Second case: you'll have to write something custom for that since popen isn't implemented. E.g. a custom C module which uses win32 API to get the needed information.

Re: How to get windows disk device instance path by python?

Posted: Thu Jan 02, 2020 9:30 am
by zfm076
stijn wrote:
Thu Jan 02, 2020 8:28 am
You mean Python or MicroPython?

First case you can parse output of e.g.

Code: Select all

import os
os.popen('wmic diskdrive get PNPDeviceID').read() 
(your question doesn't specify which device, this will list all of them..)

Second case: you'll have to write something custom for that since popen isn't implemented. E.g. a custom C module which uses win32 API to get the needed information.
Thank you very much. Python use code:os.popen('wmic diskdrive').read() . I can get the disk DeviceID and PNPDeviceID. Then I have a new question: How do I know the partition(like:C,D,E,F,G...) of this disk device if I know the DeviceID and PNPDeviceID?

Re: How to get windows disk device instance path by python?

Posted: Thu Jan 02, 2020 1:03 pm
by stijn
Something like this: https://superuser.com/questions/634842/ ... using-wmic or maybe using the Python psutil module

Re: How to get windows disk device instance path by python?

Posted: Tue Jan 07, 2020 10:30 am
by zfm076
stijn wrote:
Thu Jan 02, 2020 1:03 pm
Something like this: https://superuser.com/questions/634842/ ... using-wmic or maybe using the Python psutil module
Thank you very much.Helped me a lot. :D