EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Preventing volume label rename

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
Posted: 01/05/2010 12:30:18
by Tegdeep Kondal (Basic support level)
Joined: 01/05/2010
Posts: 3


I am trying to prevent the user from renaming the volume's label.
(i.e. User opens "My Computer" and decides to rename the mounted volume.)

The original volume label is hard-coded and is returned by the OnGetVolumeLabel callback as such:

void CbFsGetVolumeLabel(CallbackFileSystem* Sender, LPTSTR VolumeLabel)
   std::wstring strLabel = L"DD";
   wcscpy(VolumeLabel, strLabel.c_str());

However, the user is able to change the label, and this label stays in the Explorer window, even after hitting refresh. It seems that the "OnGetVolumeLabel" callback is not called upon refresh.

I also tried to throw an exception in the OnSetVolumeLabel callback as such:
void CbFsSetVolumeLabel(CallbackFileSystem* Sender, LPCTSTR VolumeLabel)
   DWORD dwErrorCode = 0;
   throw new ECBFSError(dwErrorCode);

The problem with this is that Windows gives the user a rather unappealing message (see pic below). I even tried with different error codes, but it seems that throwing an exception will always give you the same result.

Is there a way to prevent the user from renaming the volume?
The simplistic approach would be to trigger an update right after the user changes the name so that the OnGetVolumeLabel callback can be called.


Posted: 01/06/2010 03:45:44
by Volodymyr Zinin (EldoS Corp.)

Try to throw from CbFsSetVolumeLabel some another error - for example ERROR_ACCESS_DENIED.
Posted: 01/07/2010 08:33:19
by Tegdeep Kondal (Basic support level)
Joined: 01/05/2010
Posts: 3

It doesn't help. I get the same error message from Windows.
Isn't there a way to trigger a refresh after CbFsSetVolumeLabel ?
Or if I could call the CbFsSetVolumeLabel programatically, it would solve the problem as well.
Posted: 01/07/2010 11:34:02
by Eugene Mayevski (EldoS Corp.)

Just a guess - try calling NotifyDirectoryChange method on the root folder. This should tell Windows to re-read information, and since this is a root directory, maybe it will also check the disk label?

Sincerely yours
Eugene Mayevski
Posted: 01/07/2010 13:10:39
by Volodymyr Zinin (EldoS Corp.)

Don't use the "new" operator during the exception throwing.
Try to call:
Posted: 01/07/2010 14:13:00
by Tegdeep Kondal (Basic support level)
Joined: 01/05/2010
Posts: 3

Thanks Vladimir. The proper error message is displayed. However, the best solution in our case would be to not get any error messages from Windows. Is this possible?
Posted: 01/07/2010 15:15:19
by Volodymyr Zinin (EldoS Corp.)

You can do nothing in your OnSetVolumeLabel callback and only return success. But it seems the system caches the new label and doesn't ask the file system again. I've found that the Explorer stores new labels in the registry. Maybe it helps you somehow...
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.



Topic viewed 2179 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!