How to remove Volume Name on removable drive?

  • Thread starter Thread starter Steve Marshall
  • Start date Start date
S

Steve Marshall

Hi all,

I have an application that can use many different compact-flash cards as
storage for different jobs the client is working on. I have added a
function to erase all files from a flash card, and that works fine.

But I would also like to be able to make the Volume Label on each flash card
the job name its files belong to. I can't work out how to either write the
Volume Label to the cards, or to remove it when I erase them. I did this
in VB5 by using a Windows API call - surely VB.NET 2003 is smarter than
that?

Anybody know the "right" way to do this in VB.NET?

Thanks
 
I don't think there's a framework (or VB) way to do it.... but
SetVolumeLabel(...) is such an easy API to call... just use that. What's the
big deal? Alternatively, you can also spawn a Label command using
Process.Start("cmd.exe", "/C label drive:label"). Change /C to /K to keep
the window around for debugging purposes. /C dismisses the command prompt
window as soon the command finishes.

But, really, it doesn't get any easier than SetVolumeLabel API AFAIK.
 
Yes, that's what I've done. To remove the label I just set it to an empty
string, which also seems to have the desired effect.

Thanks for the reply.
 
Have you tried System.IO.DriveInfo.VolumeLabel?

http://msdn2.microsoft.com/en-us/library/system.io.driveinfo.volumelabel.aspx

NOTE: Requires VS 2005.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi all,
|
| I have an application that can use many different compact-flash cards as
| storage for different jobs the client is working on. I have added a
| function to erase all files from a flash card, and that works fine.
|
| But I would also like to be able to make the Volume Label on each flash
card
| the job name its files belong to. I can't work out how to either write
the
| Volume Label to the cards, or to remove it when I erase them. I did this
| in VB5 by using a Windows API call - surely VB.NET 2003 is smarter than
| that?
|
| Anybody know the "right" way to do this in VB.NET?
|
| Thanks
|
|
 
Man, I wonder if anyone has gauged just how much of the Win32 API Microsoft
has managed to wrap in the framework? Seems to me that as of .NET 2.0,
they're nearning 100% (of the core API), no? That's a great accomplishment.
 
Here is the .NET 1.x to Win32 API map:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/win32map.asp

Not sure where or if there is a .NET 2.0 to Win32 API map.


Another good resource for .NET & Win32 APIs is http://www.pinvoke.net


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Man, I wonder if anyone has gauged just how much of the Win32 API
Microsoft
| has managed to wrap in the framework? Seems to me that as of .NET 2.0,
| they're nearning 100% (of the core API), no? That's a great
accomplishment.
|
| --
| -C. Moya
| www.cmoya.com
|
|
 
The CLR and Framework team (teams? plural) are truly doing outstanding work.
I wish the IDE and Designer teams had the same vision and
attention-to-detail.
 
Back
Top