Solved

How do I use MountVol remotely (WMI, etc)

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

867 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

18 Experts available now in Live!

Get 1:1 Help Now