Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I use MountVol remotely (WMI, etc)

Posted on 2011-02-23
4
Medium Priority
?
1,175 Views
Last Modified: 2012-05-11
I would like to run the MountVol command on a bunch of RIS servers to take advantage of the extra capacity available on the E drives as the REMINST share is running out of space on D. I have tried and tested this and all is well.
However I have over two hundred machines with the same problem and I need a scripting solution. I was thinking there might be some kind of WMI class I could utilise. I realise as a last ditch effort I could remotely run a process that executes mountvol on the servers in question but I'd like to know if there is a cleaner method to do this directly without having to spawn separate processes. Obviously the solution would need to find the volume GUIDs of the remote machinesetc for this to work. Thanks.
0
Comment
Question by:bondy666
  • 2
  • 2
4 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 34965935
Hi, you can use the DOS MountVol command, but you'd need to execute this script using something like PSExec so that it runs on the remote computer.  Here is an example that uses MountVol to change a drive letter.

Regards,

Rob.
ChangeDriveLetterWithMountvol "Y:", "Z:"

Sub ChangeDriveLetterWithMountvol(strSourceDrive, strTargetDrive) 

    Dim objShell, objExec
    Dim strVolume
    
    Set objShell = WScript.CreateObject("WScript.Shell")
    
    ' Get volume associated to the old drive letter.
    '
    Set objExec = objShell.Exec("mountvol " & strSourceDrive & " /L")
    strVolume = Trim(objExec.StdOut.ReadLine())
    While objExec.Status = 0
        WScript.Sleep(100)
    Wend
    
    ' Unmount the drive.
    '
    Set objExec = objShell.Exec("mountvol " & strSourceDrive & " /D")
    While objExec.Status = 0
        WScript.Sleep(100)
    Wend
    
    ' Mount the drive on the new drive letter.
    '
    Set objExec = objShell.Exec("mountvol " & strTargetDrive & " " & strVolume)
    While objExec.Status = 0
        WScript.Sleep(100)
    Wend

End Sub

Open in new window

0
 

Accepted Solution

by:
bondy666 earned 0 total points
ID: 34968640
Thank you but as I mentioned in my question, I realise I can do something like this as a last resort. What I was after was something more direct WMI solution which didn't require a third party solution. In fact I have just come accross what I was after and it was simpler than I thought. It can also be run sucessfully remotely. What was initially holding me back was the fact I am on an XP machine and this only works on OS's higher than XP which I hadn't realised. Once I ran it from a 2003 box all was fine. The solution is below.
Thank you for taking the time to reply, much appreciated.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Volume Where Name = 'C:\\Temp\\VolMount\\'")

For Each objItem in colItems
    objItem.AddMountPoint("F:\\")
Next

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34974240
Sure, well that's an easier way to do it.  I think I did come across a while back, but couldn't use it because I use XP, so I forgot about it.

Rob.
0
 

Author Closing Comment

by:bondy666
ID: 35005086
My solution was exactly what I was looking for without the need to spawn other processes and involve third party solutions.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question