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

getVolumes - WMIC.exe deprecated #163

Closed
Mailinnia opened this issue Jan 21, 2022 · 8 comments
Closed

getVolumes - WMIC.exe deprecated #163

Mailinnia opened this issue Jan 21, 2022 · 8 comments

Comments

@Mailinnia
Copy link

It seems that getVolumes on windows uses wmic.exe which is deprecated, so I can't use it to get all my drives.

"The WMIC tool is deprecated in Windows 10, version 21H1 and the 21H1 semi-annual channel release of Windows Server. This tool is superseded by Windows PowerShell for WMI. Note: This deprecation only applies to the command-line management tool. WMI itself is not affected." Windows 10 features we're no longer developing 12/01/2021

@vnijs
Copy link
Collaborator

vnijs commented Jan 22, 2022

I'm using the same version and it still seems to be working fine. Can you show what you are trying to do?

image

@Mailinnia
Copy link
Author

I'm using windows11 insider and wmic.exe does not exist there

@vnijs
Copy link
Collaborator

vnijs commented Jan 23, 2022

We can't make any changes until a clear replacement is available. Unfortunately it is not clear to me (yet) what that would be. It would have to be something that works on both Windows 10 and Windows 11

https://github.com/thomasp85/shinyFiles/blob/master/R/aaa.R#L82-L86

If you have suggestions, or want to create a pull request, please let us know

@Mailinnia
Copy link
Author

It can be replaced by running a powershell command:

volLetter <- system2('powershell', '(get-volume).driveletter', stdout=TRUE)
volumes <- paste0(volLetter, ':/')
names(volumes) <- paste0(volLetter, ':')

As I don't have wmic I don't know how the volume names usually look when using getVolumes()

All Windows come installed with powershell .

@vnijs
Copy link
Collaborator

vnijs commented Feb 5, 2022

Thanks for this starting point. However, on my system that only get the C drive. Not the 3-4 other mounted drives. I think Get-PSDrive may be the tool we will need. If you have ideas, please us know.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-psdrive?view=powershell-7.2

@davboehm
Copy link

davboehm commented Feb 7, 2022

I had the problem that getVolumes()() didn't show the correct names (NANA and empty), didn't include USB-Drives and printed a warning on every call:

Warning in system(paste(wmic, "/FAILFAST:1000 logicaldisk get VolumeName"), :
running command 'C:\WINDOWS\System32\Wbem\WMIC.exe /FAILFAST:1000 logicaldisk get VolumeName' had status 44003

I came up with a solution that worked for me using PowerShell:

      volumes.name <- system2("powershell", "([System.IO.DriveInfo]::GetDrives()).Name", stdout = TRUE)
      volumes.label <- system2("powershell", "([System.IO.DriveInfo]::GetDrives()).VolumeLabel", stdout = TRUE)
      volumes <- system2("powershell", "([System.IO.DriveInfo]::GetDrives()).RootDirectory.Name", stdout = TRUE)
      
      volumes.name <- gsub(":\\\\$", ":/", volumes.name)
      sel <- volumes.label == ""
      volumes.label[sel] <- volumes.name[sel]
      volumes <- gsub(":\\\\$", ":/", volumes)
      names(volumes) <- volumes.label

Can also be reduced to one powershell call (reduces time from ~1s to ~0.3s)

      volumes.info <- system2("powershell", "$dvr=[System.IO.DriveInfo]::GetDrives();Write-Output $dvr.length $dvr.name $dvr.VolumeLabel $dvr.RootDirectory.Name;", stdout = TRUE)
      num = as.integer(volumes.info[[1]])
      if(num == 0) return(NULL)
      volumes.name = volumes.label = volumes  = character(num)
      for(i in 1:(num)){
        volumes.name[i]  = volumes.info[i+1]
        volumes.label[i] = volumes.info[i+1+num]
        volumes[i]   = volumes.info[i+1+2*num]
      }
      volumes.name <- gsub(":\\\\$", ":/", volumes.name)
      sel <- volumes.label == ""
      volumes.label[sel] <- volumes.name[sel]
      volumes <- gsub(":\\\\$", ":/", volumes)
      names(volumes) <- volumes.label

I hope this can help

vnijs added a commit that referenced this issue Apr 27, 2022
@vnijs
Copy link
Collaborator

vnijs commented Apr 27, 2022

Sorry for the delay. I adapted your code and included it in the GitHub version of shinyFiles. Please take a look and let us know if you encounter any issues. Thanks

BTW I recently upgrade to Win 11 and WMIC is still present. It is good to have this change, regardless

@vnijs
Copy link
Collaborator

vnijs commented May 9, 2022

@Mailinnia After a fair amount of testing the approach adapted from your code seems to work well. Thanks again for reporting!

@vnijs vnijs closed this as completed May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants