CreateFile in unmanaged code fails

Discussion in 'ASP .Net Security' started by Udo Hoerhold, Jun 14, 2006.

  1. Udo Hoerhold

    Udo Hoerhold Guest

    Hi. I'm calling some legacy unmanaged code from a web service (but I can
    duplicate the same problem from an IHttpModule). The unmanaged code calls
    CreateFile to open an existing file. CreateFile always fails with LastError
    == 5 (ERROR_ACCESS_DENIED).

    If I try to call CreateFile directly from the web service, like this:
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern IntPtr CreateFile(string lpFileName, uint
    dwDesiredAccess,
    uint dwShareMode, IntPtr lpSecurityAttributes, uint
    dwCreationDisposition,
    uint dwFlagsAndAttributes, IntPtr hTemplateFile);

    IntPtr hFile = CreateFile( "c:\\tempdb\\file.txt",
    0x80000000,
    0,
    IntPtr.Zero,
    3,
    0,
    IntPtr.Zero );

    This works fine.

    Calling fopen() to open the file from the unmanaged code also works. Only
    CreateFile in the unmanaged code fails.

    I've tried adding the ASPNET user to the Administrators group. I've also
    tried adding:
    <processModel autoConfig="true"
    userName="Administrator"
    password="xxxxxx"/>
    to the machine.config file.

    Does anyone know why this particular scenario fails? I'm assuming it's a
    permissions problem because of the ACCESS_DENIED error, but none of the
    solutions for access problems are working, and it's strange that fopen() will
    succeed when CreateFile() fails.

    Anyone have any ideas?

    Thanks
    Udo Hoerhold, Jun 14, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Liong via .NET 247

    CreateFile - Read/Write client's Stroage

    Sean Liong via .NET 247, Jun 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    526
    bradley
    Jun 9, 2005
  2. =?Utf-8?B?QWJoaWxhc2g=?=

    Unmanaged DLL Instantiation Fails in ASP.NET and Page Expires

    =?Utf-8?B?QWJoaWxhc2g=?=, Aug 1, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    382
    =?Utf-8?B?QWJoaWxhc2g=?=
    Aug 1, 2005
  3. MIUSS
    Replies:
    6
    Views:
    827
    John Harrison
    Feb 28, 2007
  4. David Taylor
    Replies:
    0
    Views:
    137
    David Taylor
    Oct 11, 2004
  5. Paul
    Replies:
    6
    Views:
    263
Loading...

Share This Page