How to detect the windows installation path or drive using python code ?
>>> import os
>>> os.environ['SYSTEMDRIVE']
'C:'
You can use GetWindowsDirectory via the ctypes library to get the location of the Windows folder, and then you can use os.path.splitdrive to get the drive letter. For example:
import ctypes
import os
kernel32 = ctypes.windll.kernel32
windows_directory = ctypes.create_unicode_buffer(1024)
if kernel32.GetWindowsDirectoryW(windows_directory, 1024) == 0:
# Handle error
else:
windows_drive = os.path.splitdrive(windows_directory)[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With