1

I need to use the API function SetFileValidData, but this works only with file handles opened with "the SE_MANAGE_VOLUME_NAME privilege enabled", and I don't know how to enable that. I searched but it seems too complicated for me. P.S. : I have administrator rights on my computer.

Marus Gradinaru
  • 2,824
  • 1
  • 26
  • 55
  • 1
    Use `AdjustTokenPrivileges` to add `SE_MANAGE_VOLUME_NAME` before you call `CreateFile` to create the handle. You'll need to be running with a used token that is allowed to add that privilege. – David Heffernan Sep 09 '14 at 14:46
  • I don't know how, I never worked with tokens... It seems I need a token handle, and for this I need to open one with a process handle with PROCESS_QUERY_INFORMATION access permission and... I'm lost :( – Marus Gradinaru Sep 09 '14 at 15:31
  • 1
    There are lots of examples on the web of how to call `AdjustTokenPrivileges`. Start here: http://msdn.microsoft.com/en-gb/library/windows/desktop/aa446619.aspx – David Heffernan Sep 09 '14 at 15:56
  • I successfully converted that procedure from C++ to Delphi and I understand how it works... but how I get that token handle ? – Marus Gradinaru Sep 09 '14 at 18:22
  • 1
    Sample code: http://stackoverflow.com/a/6771988/886887 – Harry Johnston Sep 09 '14 at 22:52

1 Answers1

3

To summarise the comments:

  • You need your process token to have the SE_MANAGE_VOLUME_NAME privilege when you call CreateFile to open the file handle.
  • You gain that privilege by calling AdjustTokenPrivileges.
  • Some examples of how to do that can be found on MSDN and here on SO.
Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490