Solved

How do I use MountVol remotely (WMI, etc)

Posted on 2011-02-23
4
1,158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

631 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