Solved

How do I use MountVol remotely (WMI, etc)

Posted on 2011-02-23
4
1,120 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now