mirror of
https://github.com/corpnewt/gibMacOS.git
synced 2025-02-11 00:11:21 +01:00
More WMIC and PowerShell fun
If we have a valid WMIC path, first try using it to gather information - if we don't get any disks that way, or we don't have a valid WMIC path, fall back on PowerShell. This should hopefully fix the Windows 11 issues.
This commit is contained in:
parent
054fa19306
commit
1ef6a579e4
@ -42,43 +42,61 @@ class Disk:
|
|||||||
def _get_diskdrive(self):
|
def _get_diskdrive(self):
|
||||||
disks = []
|
disks = []
|
||||||
if self.wmic: # Use WMIC where possible
|
if self.wmic: # Use WMIC where possible
|
||||||
|
try:
|
||||||
wmic = self.r.run({"args":[self.wmic, "DiskDrive", "get", "DeviceID,Index,Model,Partitions,Size", "/format:csv"]})[0]
|
wmic = self.r.run({"args":[self.wmic, "DiskDrive", "get", "DeviceID,Index,Model,Partitions,Size", "/format:csv"]})[0]
|
||||||
# Get the rows - but skip the first 2 (empty, headers) and the last 1 (empty again)
|
# Get the rows - but skip the first 2 (empty, headers) and the last 1 (empty again)
|
||||||
disks = list(csv.reader(wmic.replace("\r","").split("\n"), delimiter=","))[2:-1]
|
disks = list(csv.reader(wmic.replace("\r","").split("\n"), delimiter=","))[2:-1]
|
||||||
# We need to skip the Node value for each row as well
|
# We need to skip the Node value for each row as well
|
||||||
disks = [x[1:] for x in disks]
|
disks = [x[1:] for x in disks]
|
||||||
else: # Use PowerShell and parse the info manually
|
except:
|
||||||
|
pass
|
||||||
|
if not disks: # Use PowerShell and parse the info manually
|
||||||
|
try:
|
||||||
ps = self.r.run({"args":["powershell", "-c", "Get-WmiObject -Class Win32_DiskDrive | Format-List -Property DeviceID,Index,Model,Partitions,Size"]})[0]
|
ps = self.r.run({"args":["powershell", "-c", "Get-WmiObject -Class Win32_DiskDrive | Format-List -Property DeviceID,Index,Model,Partitions,Size"]})[0]
|
||||||
# We need to iterate the rows and add each column manually
|
# We need to iterate the rows and add each column manually
|
||||||
disks = self._get_rows(ps.replace("\r","").split("\n"))
|
disks = self._get_rows(ps.replace("\r","").split("\n"))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return disks
|
return disks
|
||||||
|
|
||||||
def _get_ldtop(self):
|
def _get_ldtop(self):
|
||||||
disks = []
|
disks = []
|
||||||
if self.wmic: # Use WMIC where possible
|
if self.wmic: # Use WMIC where possible
|
||||||
|
try:
|
||||||
wmic = self.r.run({"args":[self.wmic, "path", "Win32_LogicalDiskToPartition", "get", "Antecedent,Dependent"]})[0]
|
wmic = self.r.run({"args":[self.wmic, "path", "Win32_LogicalDiskToPartition", "get", "Antecedent,Dependent"]})[0]
|
||||||
# Get the rows - but skip the first and last as they're empty
|
# Get the rows - but skip the first and last as they're empty
|
||||||
disks = wmic.replace("\r","").split("\n")[1:-1]
|
disks = wmic.replace("\r","").split("\n")[1:-1]
|
||||||
else: # Use PowerShell and parse the info manually
|
except:
|
||||||
|
pass
|
||||||
|
if not disks: # Use PowerShell and parse the info manually
|
||||||
|
try:
|
||||||
ps = self.r.run({"args":["powershell", "-c", "Get-WmiObject -Class Win32_LogicalDiskToPartition | Format-List -Property Antecedent,Dependent"]})[0]
|
ps = self.r.run({"args":["powershell", "-c", "Get-WmiObject -Class Win32_LogicalDiskToPartition | Format-List -Property Antecedent,Dependent"]})[0]
|
||||||
# We need to iterate the rows and add each column manually
|
# We need to iterate the rows and add each column manually
|
||||||
disks = self._get_rows(ps.replace("\r","").split("\n"))
|
disks = self._get_rows(ps.replace("\r","").split("\n"))
|
||||||
# We need to join the values with 2 spaces to match the WMIC output
|
# We need to join the values with 2 spaces to match the WMIC output
|
||||||
disks = [" ".join(x) for x in disks]
|
disks = [" ".join(x) for x in disks]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return disks
|
return disks
|
||||||
|
|
||||||
def _get_logicaldisk(self):
|
def _get_logicaldisk(self):
|
||||||
disks = []
|
disks = []
|
||||||
if self.wmic: # Use WMIC where possible
|
if self.wmic: # Use WMIC where possible
|
||||||
|
try:
|
||||||
wmic = self.r.run({"args":[self.wmic, "LogicalDisk", "get", "DeviceID,DriveType,FileSystem,Size,VolumeName", "/format:csv"]})[0]
|
wmic = self.r.run({"args":[self.wmic, "LogicalDisk", "get", "DeviceID,DriveType,FileSystem,Size,VolumeName", "/format:csv"]})[0]
|
||||||
# Get the rows - but skip the first 2 (empty, headers) and the last 1 (empty again)
|
# Get the rows - but skip the first 2 (empty, headers) and the last 1 (empty again)
|
||||||
disks = list(csv.reader(wmic.replace("\r","").split("\n"), delimiter=","))[2:-1]
|
disks = list(csv.reader(wmic.replace("\r","").split("\n"), delimiter=","))[2:-1]
|
||||||
# We need to skip the Node value for each row as well
|
# We need to skip the Node value for each row as well
|
||||||
disks = [x[1:] for x in disks]
|
disks = [x[1:] for x in disks]
|
||||||
else: # Use PowerShell and parse the info manually
|
except:
|
||||||
|
pass
|
||||||
|
if not disks: # Use PowerShell and parse the info manually
|
||||||
|
try:
|
||||||
ps = self.r.run({"args":["powershell", "-c", "Get-WmiObject -Class Win32_LogicalDisk | Format-List -Property DeviceID,DriveType,FileSystem,Size,VolumeName"]})[0]
|
ps = self.r.run({"args":["powershell", "-c", "Get-WmiObject -Class Win32_LogicalDisk | Format-List -Property DeviceID,DriveType,FileSystem,Size,VolumeName"]})[0]
|
||||||
# We need to iterate the rows and add each column manually
|
# We need to iterate the rows and add each column manually
|
||||||
disks = self._get_rows(ps.replace("\r","").split("\n"))
|
disks = self._get_rows(ps.replace("\r","").split("\n"))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return disks
|
return disks
|
||||||
|
|
||||||
def get_disks(self):
|
def get_disks(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user