Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > CreateFile in unmanaged code fails

Thread Tools

CreateFile in unmanaged code fails

Udo Hoerhold
Posts: n/a
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

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
uint dwShareMode, IntPtr lpSecurityAttributes, uint
uint dwFlagsAndAttributes, IntPtr hTemplateFile);

IntPtr hFile = CreateFile( "c:\\tempdb\\file.txt",
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"
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?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateFile returns invalid handle value when I use wcscpy in my source... ...need a help. MIUSS C++ 6 02-28-2007 11:06 PM
VBScript FSO: CreateFile OK, OpenTextFile fails Paul ASP General 6 03-17-2006 01:15 AM
Unmanaged DLL Instantiation Fails in ASP.NET and Page Expires =?Utf-8?B?QWJoaWxhc2g=?= ASP .Net 0 08-01-2005 05:06 AM
CreateFile - Read/Write client's Stroage Sean Liong via .NET 247 ASP .Net 3 06-09-2005 12:45 PM
Unmanaged DLL fails when called from web service (permissions ?) David Taylor ASP .Net Web Services 0 10-11-2004 04:43 AM