Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

setPropertyValue does not work with win32_volume?

Posted on 2011-03-08
6
Medium Priority
?
647 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
[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
  • 4
6 Comments
 
LVL 8

Expert Comment

by:crysallus
ID: 35081216
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
ID: 35082801
tried, it does not work
0
 

Author Comment

by:Ikelca
ID: 35082811
and no error msg, this is weird
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 total points
ID: 35084615
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
ID: 35090948
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
ID: 35091072
nvm, i just found out win32_volume is not available to winxp and earlier windows.....
thanks guys
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 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