Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[.NET 4.0] Win32 API: SetFileShortName and necessary Privileges

28 views
Skip to first unread message

Christian Treffler

unread,
Sep 3, 2012, 2:41:46 PM9/3/12
to
Hi,

I'd like to change short filenames (8.3-filenames) (.net 4.0, C#). .net
offers no methods to accomplish this, so the solution is the Win32-API.

I can read the short filename, but I have problems changing it. I
searched Google a lot and found lots of hints [1].
The main information is that I need to be logged in as administrator and
to set the SE_RESTORE_NAME privilege. I found lots of example code and
built a method out of that which should be capable of changing the short
filename. But it doesn't work.

My code is here:
http://pastebin.com/JRRYKqmS

After every access of the Win32API I retrieved the last error code
(Comments of the result in my code).
The first two API calls CreateFile and AdjustTokenPrivileges were
successful. But after the SetFileShortName I get the error "A
required privilege is not held by the client".

So either setting of the SE_RESTORE_NAME privilege was not successful,
or another privilege is missing.

Can anybody help here?

TIA,
Christian

[1]
http://tinyurl.com/95vdrt7
http://www.codeproject.com/Questions/325630/Setting-the-Short-Name-of-file
http://tinyurl.com/9b6eldf
0 new messages