Setting the name of a SUBST drive using VBS

Viewed 1019

I'm using SUBST to create a drive letter representing a path on a local drive.

subst Q: "C:\Users\Username\My Documents\blah\blah\blah"

I want to label the new drive E: with a descriptive name different than the volume name of C: This cannot be done through Explorer, or using the LABEL command.

A solution is offered in this question from 2012. It includes a snippet of VBS code to set a drive name in the comments. @SeanC implied that it worked properly back then.

The code looks like this when expanded:

mDrive = "q:\"
Set oShell = CreateObject("Shell.Application")
oShell.NameSpace(mDrive).Self.Name = "AnyName"

In 2019, under Windows 10, this code does not work:

C:\Label_drive.vbs(3, 1) Microsoft VBScript runtime error: Object required: 'oShell.NameSpace(...)'

I'm not at all familiar with VBS - can anyone identify the problem with the script? What has changed that would cause this error now?

Edit: This command is run from an administrator (elevated) command window prompt:

cscript Label_drive.vbs
1 Answers
Related