Solved

setPropertyValue does not work with win32_volume?

Posted on 2011-03-08
6
632 Views
Last Modified: 2013-12-17
here is my code, basically, i want to assign drive letter "H“ to a removable usb drive
but when I try to set value for drive letter, there is no exception or error, nth happens.
problem seems to be following line, but i couldnt find out how to fix it.
mo.SetPropertyValue("DriveLetter","H:");

im using win7 and tested with administrator previllage when running debug.
can someone please help?
public static void Main(string[] args)
        {
            RetrieveDiskInfo_DriveLetter rdd = new RetrieveDiskInfo_DriveLetter();
  ManagementClass mc = new ManagementClass("Win32_Volume");
            ManagementObjectCollection moc =mc.GetInstances();
           
            if(moc.Count!=0)
            {  
           try{
           
            foreach (ManagementObject mo in moc)
                {
              
                    if (mo["DriveType"].ToString() == "2")
                       {
                            Console.WriteLine(mo["Drivetype"].ToString());
                            Console.WriteLine(mo["DeviceID"].ToString());
                                 mo.SetPropertyValue("DriveLetter","H:");
                       }
                    
                  }
             }
            catch (Exception ex)
               {
                            Console.WriteLine(ex.ToString());

               }
                
            
        }
      }

Open in new window

0
Comment
Question by:Ikelca
  • 4
6 Comments
 
LVL 8

Expert Comment

by:crysallus
Comment Utility
Have you tried putting a slash at the end of the drive letter?

mo.SetPropertyValue("DriveLetter",@"H:\");

Open in new window

0
 

Author Comment

by:Ikelca
Comment Utility
tried, it does not work
0
 

Author Comment

by:Ikelca
Comment Utility
and no error msg, this is weird
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
Comment Utility
Call Put() to save changes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

class Program
{
	static void Main(string[] args)
	{
		ManagementClass mc = new ManagementClass("Win32_Volume");
		ManagementObjectCollection moc = mc.GetInstances();

		foreach (ManagementObject mo in moc)
		{
			if ((uint)mo["DriveType"] == 2)
			{
				try
				{
					mo["DriveLetter"] = "Z:";
					mo.Put();
				}
				catch (Exception ex)
				{
					Console.WriteLine("Error: {0}", ex.Message);
				}
			}
		}
	}
}

Open in new window

0
 

Author Comment

by:Ikelca
Comment Utility
ummm thanks for the reply, it works now on win7
but somehow it gets unhandled exception on WINXP
the debugger points to ManagementObjectCollection moc = mc.GetInstances();
do you know how come this happens??
0
 

Author Comment

by:Ikelca
Comment Utility
nvm, i just found out win32_volume is not available to winxp and earlier windows.....
thanks guys
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

16 Experts available now in Live!

Get 1:1 Help Now