Welcome, guest | Sign In | My Account | Store | Cart

Script reads data stored in HKLM\SYSTEM\MountedDevices key and shows it in user friendly format. It's still under development.

Batch, 45 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@echo off
  setlocal enabledelayedexpansion
    ::script info
    set "slf=%~n0 v1.0"
    echo %slf% - mounted devices
    echo Copyright (C) 2013 greg zakharov gregzakh@gmail.com
    echo Activestate - code.activestate.com
    echo.
    ::
    set "i=0"
    set "key=HKLM\SYSTEM\MountedDevices"
    ::searching \DosDevices\
    for /f "tokens=1,3" %%i in ('reg query %key%^
      ^| findstr /r /c:DosDevices ^| sort') do (
        set "arr.!i!=%%i=%%j" & set /a "i+=1"
      )
    )
    ::real length of array
    set /a "len=%i% - 1"
    ::reset increment and create new pair Drive=>Volume
    set "i=0"
    for /l %%i in (0, 1, !len!) do (
      for /f "tokens=1,2 delims==" %%j in ("!arr.%%i!") do (
        ::%%j - device and %%k - data
        for /f "tokens=1,3" %%l in ('reg query %key%^
          ^| findstr /r /c:Volume') do (
          ::%%l - value and %%m - data
          if "%%k" equ "%%m" set "a.!i!=%%j=%%l" & set /a "i+=1"
        )
      )
    )
    ::user friendly output
    for /l %%i in (0, 1, !len!) do (
      for /f "tokens=2* delims=\=" %%j in ("!a.%%i!") do (
        for /f "tokens=2 delims=:" %%l in ('2^>nul dir %%j^
          ^| findstr /i /r [a-z0-9]-[a-z0-9]') do (
          echo Volume: \%%k\
          echo    Mounted at: %%j\
          echo     Volume ID:%%l
        )
        echo.
      )
    )
  endlocal
exit /b
Created by greg zakharov on Tue, 13 Aug 2013 (MIT)
Batch recipes (42)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks