Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6235869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:44:47+00:00 2026-05-24T10:44:47+00:00

I have a VBScript which detects local hard drive letters and it will store

  • 0

I have a VBScript which detects local hard drive letters and it will store them some where. Now I want to remove the Windows Drive from it. I mean first it finds all local hard drives, then detects windows drive and remove it from local hard drives list and then store them in the target variable. How to do it?

Here is the VBScript:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")

drives = ""
For Each objDisk in colDisks
  if objDisk.DriveType = 3 then
    if drives > "" then
      drives = drives & ";"
    end if
    drives = drives & objDisk.DeviceID & "\"
  end if
Next

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:44:48+00:00Added an answer on May 24, 2026 at 10:44 am

    I would prefer to

    1. use the FSO instead of WMI
    2. have the drives in a useable collection instead of a string
    3. not putting the system drive in the collection instead of removing
      it later

    So:

      Dim goFS      : Set goFS      = CreateObject( "Scripting.FileSystemObject" )
      Dim dicDTypes : Set dicDTypes = buildDicMKV( _
        vbTextCompare, Split( "0 1 2 3 4 5" ), Split( "Unknown Removable Fixed Network CD-ROM RAM-Disk" ) _
      )
      Dim dicDrives : Set dicDrives = CreateObject( "Scripting.Dictionary" )
      Dim oWSH      : Set oWSH      = CreateObject( "WScript.Shell" )
      Dim sSysDir   : sSysDir       = oWSH.Environment( "PROCESS" )( "SYSTEMROOT" )
      WScript.Echo "sSysDir", sSysDir
      Dim sSysDrive : sSysDrive     = goFS.GetDriveName( sSysDir )
      WScript.Echo "sSysDrive", sSysDrive
      Dim sSDLetter : sSDLetter     = Left( sSysDrive, 1 )
      WScript.Echo "sSDLetter", sSDLetter
      Dim oDrive
      For Each oDrive In goFS.Drives
          WScript.Echo oDrive.DriveLetter, oDrive.DriveType, dicDTypes( CStr( oDrive.DriveType ) )
          If     "Fixed" = dicDTypes( CStr( oDrive.DriveType ) ) _
             And sSDLetter <> oDrive.DriveLetter Then
             Set dicDrives( oDrive.DriveLetter ) = oDrive
          End If   
      Next    
      WScript.Echo "------------------"
      Dim sDrive
      For Each sDrive In dicDrives.Keys
          Set oDrive = dicDrives( sDrive )
          WScript.Echo oDrive.DriveLetter, oDrive.DriveType, dicDTypes( CStr( oDrive.DriveType ) )
      Next    
    
    Function buildDicMKV( vbCompMode, aKeys, aValues )
      Set buildDicMKV = CreateObject( "Scripting.Dictionary" )
    '    compare
    '      Optional. If provided, compare is a value representing the comparison mode. 
    '      Acceptable values are 0 (Binary), 1 (Text), 2 (Database). Values greater than 
    '      2 can be used to refer to comparisons using specific Locale IDs (LCID). 
      buildDicMKV.CompareMode = vbCompMode
      Dim nIdx
      For nIdx = 0 To UBound( aKeys )
          buildDicMKV.Add aKeys( nIdx ), aValues( nIdx )
      Next    
    End Function  
    

    output:

    sSysDir C:\WINDOWS
    sSysDrive C:
    sSDLetter C
    A 1 Removable
    C 2 Fixed
    E 3 Network
    M 3 Network
    X 2 Fixed
    ------------------
    X 2 Fixed
    

    ADDED:

    I doubt that you can’t do it yourself, but anyway:

      Dim sSysDrive : sSysDrive = CreateObject( "Scripting.FileSystemObject" ) _
          .GetDriveName(  _
              CreateObject( "WScript.Shell" ).Environment( "PROCESS" )( "SYSTEMROOT" ) )
      Dim strComputer : strComputer = "."
      Dim objWMIService : Set objWMIService = GetObject( "winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" )
    
      Dim colDisks
      Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
    
      Dim drives : drives = ""
      Dim objDisk
      For Each objDisk in colDisks
          If     objDisk.DriveType = 3 _
             And objDisk.DeviceID <> sSysDrive Then
             If drives > "" Then
                drives = drives & ";"
             End If
             drives = drives & objDisk.DeviceID & "\"
          End if
      Next
      WScript.Echo drives
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VBScript which list drives' letters. I want to get the drives'
In my asp.net page I have a VBScript method which is doing some tasks
Context: Windows7, VBScript, ADODB and ADOX. I have written some VBScript code which creates
I have an old vbscript the runs the command, foo = CreateObject(x.y). I want
I have a vbscript file that will open a document with the correct program
I need to create vbscript which will create new folder 'test' and subfolder 'Output'.There
I have VBScript code which launches QuickTest Professional, executes a series of QTP tests,
I have a vbscript which does the following: Open an access 2003 database Run
I have a .NET assembly which I am accessing from VBScript (classic ASP) via
I have an install project which has a custom action that executes a VBScript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.