Opening a handle to a device in Python on Windows Opening a handle to a device in Python on Windows windows windows

Opening a handle to a device in Python on Windows


Solution: in python you have to use win32file.CreateFile() instead of open(). Thanks everyone for telling me what I was trying to do, it helped me find the answer!


I don't know anything about Python, but I do know a bit about drivers. You're not trying to 'open a file in kernel space' at all - you're just trying to open a handle to a device which happens to be made to look a bit like opening a file.

CreateFile is a user-mode function, and everything you're doing here is user-mode, not kernel mode.

As xenon says, your call may be failing because you haven't loaded the driver yet, or because whatever Python call you're using to do the CreateFile is not passing the write parameters in.

I've never used giveio.sys myself, but personally I would establish that it was loaded correctly by using 'C' or C++ (or some pre-written app) before I tried to get it working via Python.


You're question is very confusing to say the least.

1> The code you pasted is using a trick to communicate with the driver using its 'DOSNAME' i.e.

\\.\DRIVERNAME

2> Have you created & loaded the 'giveio' driver ?

The reason the driver handles this calls is because of this

http://msdn.microsoft.com/en-us/library/ms806162.aspx