Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to set Volume ID?

Posted on 1998-06-23
12
Medium Priority
?
258 Views
Last Modified: 2013-12-03
I want to change the Volume ID (not the label) for a given drive.
Is there a Win32 API call to do that?
0
Comment
Question by:Guiseppe
  • 6
  • 3
  • 2
  • +1
12 Comments
 

Author Comment

by:Guiseppe
ID: 1408396
Adjusted points to 50
0
 
LVL 2

Expert Comment

by:abesoft
ID: 1408397
Use SetVolumeLabel():

BOOL SetVolumeLabel(
  LPCTSTR lpRootPathName,  // address of name of root directory for
                           // volume
  LPCTSTR lpVolumeName   // name for the volume
);

So,
    SetVolumeLabel( "C:\\", "MyDrive");
should be what you need...
0
 

Author Comment

by:Guiseppe
ID: 1408398
I think you did not read the question very well. I explicitly stated that I don't want to change the LABEL of the volume. What I want is to change the VOLUME ID, also known as VolumeSerialNumber.

There is a function to retrieve that ID (GetVolumeInformation). I want to know if there is also a function to change the VOLUME ID.

Hope I made myself a bit clearer.

0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Expert Comment

by:tkirby052098
ID: 1408399
The volume serial number is a pseudo-random 32-bit number generated during formatting.  Since this is intended to exist for the life of the volume, no function was provided to change it.  If you REALLY have to change it, you will need to write directly to the boot information region of the drive.  Look in the file system docs for the location.
0
 

Author Comment

by:Guiseppe
ID: 1408400
Well, I REALLY want to change it. Where do I have to write to?
How do I write to sector that contains the volume ID?
0
 

Expert Comment

by:tkirby052098
ID: 1408401
Where to write? on the disk of course!  Seriously, I can't say from memory, but if you look in the *file system docs*, somewhere in there you will find what you seek.  It's in the boot sector, I think...

How to write...Use CreateFile, there is an example of the syntax here on the exchange (title was direct file writing or similar).  There is a specific syntax for doing direct file i/o.

As they say, the rest is an excercise for the student....
0
 

Author Comment

by:Guiseppe
ID: 1408402
Can you be a little more specific? I'm not a windows programmer. That's exactly why I ask some experts advice.

I know that I have to write on the disk. But can you also tell me the sector number?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1408403
Dirk, remember the DLL I sent you?  Use it to read the first sector (#0), change the ID and write it back.  The ID is in offsets 39 to 42 (in a reverse order if you treat it as a string of Bytes, in the "correct" order if you treat it as a single Long).

Please remember that Volume IDs came to be with DOS 4 so any drive/diskette formatted with an earlier version wil not have one.

BTW, you can also get the ID using GetFileInformationByHandle()
0
 

Author Comment

by:Guiseppe
ID: 1408404
I am reopening this question for Alexo, since his answer has more specific information.
0
 

Expert Comment

by:tkirby052098
ID: 1408405
Good luck to you.  Sorry for the lack of detail.  I thought you were a programmer...
0
 
LVL 11

Accepted Solution

by:
alexo earned 400 total points
ID: 1408406
Details in my comment from "Date: Wednesday, June 24 1998 - 04:55AM PDT"
0
 

Author Comment

by:Guiseppe
ID: 1408407
Everything works as it should work.

Alex, you are a genius. I bet all the people from Tel Aviv to Moskou will agree with me  :-)))

Sjaloom!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

824 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