I recently ran into trouble using a DeviceInterface with .NET 2.0. I
have a WDM driver that implements a Device Interface and does not create
a legacy name. This particular device is a Serial Port device but I
have found that this problem appears to exist with all the .NET stream
classes. When I call the SetupDiXXX functions to get a device interface
I get back something like
\?\vs03port#com#6&1b7299&3&0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}.
With Win32 I then call CreateFile and pass it this string. However I
have found that if I use FileStream or SerialStream with the string
returned by SetupDIXXX then I get an error that an illegal character is
in the path. It turns out that the ‘?’ is the illegal character and
because if I change the string to
\.\vs03port#com#6&1b7299&3&0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
I get FileStream will not open Win32 devices such as disk partitions and
tape drives. Avoid use of "\." in the path.
According to Microsoft support they don’t allow \ for security reasons
because they don’t want users to use the SerialPort class to open
devices \PHYSICALDRIVE0 or \C: which I can understand but isn’t this
the wrong way to be preventing that? Shouldn’t they use the SetupDiXXX
functions to validate that the path passed in belongs to the class of
devices that the stream supports, in my case the Serial Port class.
Am I missing something here or did the .NET group implement their
security incorrectly?
- Steve -