Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I use MountVol remotely (WMI, etc)

Posted on 2011-02-23
4
Medium Priority
?
1,168 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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

715 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