Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Dismount drive

243 views
Skip to first unread message

Marco Shaw [MVP]

unread,
May 13, 2008, 2:59:36 PM5/13/08
to
CodeTestDummy wrote:
> Why is not working? It works in the VBS.
>
> $colDrives = get-wmiobject -Class Win32_Volume -namespace "root\CIMV2"
> -computername $strComputer | where{$_.name -eq $strDrive}
>
> foreach($objItem in $colDrives)
> {
> $objItem.Dismount($True, $True)
>
> }

Because you're dealing with remote objects, I'm thinking you might have
to add this line:

...
$objItem.Dismount($true,$true)
$objItem.Put() <--Add this
...

**Not tested**

Marco

Alex K. Angelopoulos at

unread,
May 13, 2008, 3:53:50 PM5/13/08
to
I'm not able to make this work in either PowerShell or VBScript. It appears
to work if executed, but the invocation always returns a result code of 2,
which means that the volume has mount points. Below is my test VBScript
code. It appears that the mount point has to be removed before the volume
can be dismounted.

If I change the second parameter to false, the dismount succeeds - not that
I can tell what that means, since it is still visible in Explorer. However,
the returned result code is a 0. Possibly this is because I'm using a drive
letter assigned USB drive to test this against. This is also a local test as
you can tell, so it doesn't precisely mimic what you did.

Here's the PowerShell version, working against drive K:

get-wmiobject -Class Win32_Volume | where{$_.name -eq 'K:\'} |
%{$_.Dismount($true,$false)}

Here's the VBScript version:


Set volumes = GetObject("winmgmts://./root/cimv2")._
ExecQuery("Select * from Win32_Volume")

For Each volume in volumes

if volume.Name = "K:\" Then
result = volume.Dismount(true, false)
WScript.Echo result
end if
next


"CodeTestDummy" <sharp_mind....@email.TAKETHISOUT.msn.comm> wrote in
message news:E66E0B26-83D1-4620...@microsoft.com...

AlexE

unread,
Jan 22, 2011, 5:27:22 AM1/22/11
to
I struggled exact with the same problem that the DisMount succeeded but the drive still showed up in Explorer. Assigning an empty drive letter (null) helped at the end to successfully dismount the drive. E.g.:

$vol=get-wmiobject -Class Win32_Volume | where{$_.name -eq 'K:\'};
$vol.DriveLetter = $null;
$vol.Put();
$vol.DisMount($false, $false);

Alex

> On Tuesday, May 13, 2008 2:33 PM CodeTestDummy wrote:

> Why is not working? It works in the VBS.
>
> $colDrives = get-wmiobject -Class Win32_Volume -namespace
> "root\CIMV2" -computername $strComputer | where{$_.name -eq $strDrive}
>
> foreach($objItem in $colDrives)
> {
> $objItem.Dismount($True, $True)
>
> }


>> On Tuesday, May 13, 2008 2:59 PM Marco Shaw [MVP] wrote:

>> CodeTestDummy wrote:
>>
>> Because you're dealing with remote objects, I'm thinking you might have
>> to add this line:
>>
>> ...
>> $objItem.Dismount($true,$true)
>> $objItem.Put() <--Add this
>> ...
>>
>> **Not tested**
>>
>> Marco


>>> Submitted via EggHeadCafe
>>> JSONP AJAX and ASP.NET Demystified
>>> http://www.eggheadcafe.com/tutorials/aspnet/b71ea548-93e0-4cec-9fb1-35f641b83e65/jsonp-ajax-and-aspnet-demystified.aspx

0 new messages