Hi,
You can create a file like the following
HANDLE hHandle = CreateFile(L"\\.\k:\echow.txt",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, 0, 0);
BUT, the easiest thing to forget is that the driver is not run under the
account your
are logged in with. It is as default under Local Service, and therefore you
need
to give access to this user in the folder you want to use.
If you want to change the user you have to use
SECURITY_IMPERSONATION
with the CreateFile when you open your driver handle, not creating the
file itself in the driver.
More about this under MSDN
http://msdn2.microsoft.com/en-us/library/aa363858.aspx
Also some minor changes is needed in the driver. The inf file has to add an
UmdfImpersonationLevel row. For the echo driver it would be something like
[Echo_Install.NT.Wdf]
UmdfService=WUDFEchoDriver,WUDFEchoDriver_Install
UmdfServiceOrder=WUDFEchoDriver
UmdfImpersonationLevel=Impersonation
Google UmdfImpersonationLevel to get some background.
Regards,
Daniel
----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Monday, October 29, 2007 7:01 PM
Subject: [ntdev] CreateFile returns invalid handle with ERROR_ACCESS_DENIED.
>I am attempting to create a file (on my C: driver) under a software only
>PnP driver:
>CreateFile((LPCTSTR)file,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL).
>
> I am returned an invalid handle and GetLastError returns
> ERROR_ACCESS_DENIED. This is a UMDF driver similar to the Echo sample in
> the WDK.
>
> What would be proper way to have the correct permissions to create and
> write to a file?
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>