Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have created website project, and am using IIS version 6 as the web server when developing. When I try to debug this method (createfile) bellow in order to read from USB .

C#
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);

const uint OPEN_EXISTING = 3;
const uint GENERIC_WRITE = (0x40000000);
const uint FSCTL_LOCK_VOLUME = 0x00090018;
const uint FSCTL_UNLOCK_VOLUME = 0x0009001c;
const uint FSCTL_DISMOUNT_VOLUME = 0x00090020;

bool success = false;
int intOut;
string deviceId = @"\\.\H:";
long DiskSize = 2056320000;

SafeFileHandle diskHandle = CreateFile(deviceId, GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if (diskHandle.IsInvalid)
{
   //Console.WriteLine(deviceId + " open error.");
            
   Debug.WriteLine(Marshal.GetLastWin32Error());
   return 0;
}


I get this error num (5=access denied), but it works fine in other types of projects like (windows forms , console application , asp project ).

How can this be solved?

thank you in advance


[edit]Code block and indexation added[/edit]
Posted
Updated 18-Nov-13 22:53pm
v4

Assuming that the device is plugged into your server, you would have to talk to the administrator of your web server - you cannot access any device in "drive H" without adequate permissions - which would not normally be given for security reasons, and more than your website code would be allowed to change the startup of the server itself.

If it connected to the client computer, then in all probability you can't touch it at all - it is possible, but under very specific circumstances which do not occur for 99% or more of users.
 
Share this answer
 
thank you for your attention, but the solution has been found, we just need to give permissions to the application pool by changing the identity property to (Local system)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900