Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Feature request: allow collecting mount point data without Administrator access in disk_partitions() #1986

Open
KSerrania opened this issue Sep 9, 2021 · 0 comments

Comments

@KSerrania
Copy link

Summary

  • OS: Windows
  • Type: core

Description

#1192 added the ability for psutil.disk_partitions() to list mount points on Windows, using the FindFirstVolumeMountPoint, FindNextVolumeMountPoint and FindVolumeMountPointClose functions.

These functions' required permissions aren't well-documented (see FindFirstVolumeMountPoint and FindNextVolumeMountPoint), but experimentally it seems like these two functions only work if the caller has Administrator access on the host. Otherwise, these functions return an OSError 5 (Access is denied), which means they won't appear in the output of psutil.disk_partitions().

For instance, on a Windows Server 2012R2 instance where I added two mount points in the D: drive, I get the following as Administrator:

> python.exe -c "import psutil; print('psutil version', psutil.__version__); print(*psutil.disk_partitions(all=True), sep='\n')"
psutil version 5.7.2
sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed')
sdiskpart(device='D:\\', mountpoint='D:\\Data\\', fstype='NTFS', opts='rw')
sdiskpart(device='D:\\', mountpoint='D:\\tempdb\\', fstype='NTFS', opts='rw')
sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed')
sdiskpart(device='E:\\', mountpoint='E:\\', fstype='', opts='cdrom')

and the following as a non-Administrator user:

> python.exe -c "import psutil; print('psutil version', psutil.__version__); print(*psutil.disk_partitions(all=True), sep='\n')"
psutil version 5.7.2
sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed')
sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed')
sdiskpart(device='E:\\', mountpoint='E:\\', fstype='', opts='cdrom')

Could there be a way for psutil.disk_partitions() to be able to list mount points even when the user does not have Administrator rights?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant