Tech Off Thread

5 posts

How to call driver IOCTL from Windows Service?

Back to Forum: Tech Off
  • milindvk

    Hi,

    I am implementing a windows service. The service handles PRESHUTDOWN notification from service control manager. Notification is being received while the device goes to shutdown. Now I need to access a particular driver on receiving the this notification. 

    I am using CreateFile() API to get handle to the driver and send an IOCTL using the handle. But I am getting an error from CreateFile() (error code 2;parameter invalid). But same procedure works when I move the driver access code to a stand alone application.

    Is there a limitation that services cannot access driver with CreateFile? (http://stackoverflow.com/questions/8263380/send-ioctl-to-windows-device-driver-createfile-fails)

    How this can be avoided? 

    Thanks

     

  • Maurits

    2 is ERROR_FILE_NOT_FOUND, which means you're passing the wrong path to CreateFile().

  • milindvk

    I am sure that I am passing the right path. I tried the same logic of accessing the the driver and sending an IOCTL from stand alone application (command line) and was able to open the device and issue an IOCTL. I am getting this problem when I move the logic to Windows service. And as per the discussion (link that I pasted in my previous thread) it appears that

    "The PC/SC service takes exclusive ownership of the devices, so any attempt to call 'CreateFile' will always fail."

    Is this statement true? Any other solution to this problem?

    Thanks

     

  • figuerres

    , milindvk wrote

    I am sure that I am passing the right path. I tried the same logic of accessing the the driver and sending an IOCTL from stand alone application (command line) and was able to open the device and issue an IOCTL. I am getting this problem when I move the logic to Windows service. And as per the discussion (link that I pasted in my previous thread) it appears that

    "The PC/SC service takes exclusive ownership of the devices, so any attempt to call 'CreateFile' will always fail."

    Is this statement true? Any other solution to this problem?

    Thanks

     

    possibly you are hitting a security issue ?

    when you run a "stand alone" program you are running as the current user or if your running as system admin then as that privileged used.

    Windows Services do not normally run as an "interactive user" and often are running as a limited rights user to keep from having the system exploited by rouge software that creates security holes.

    what user does the service run as ?

    also why do you need to talk to that driver during shutdown ?  why not use the smart card api ?

    http://msdn.microsoft.com/en-us/library/dd627646(v=vs.85).aspx

     

  • Maurits

    There is no limitation that services cannot access files. There must be something else different between your service and your standalone .exe.

    If you were getting ERROR_ACCESS_DENIED (5) instead of ERROR_FILE_NOT_FOUND (2) I would suspect a permissions issue, but this seems to be a case of trying to open a device that isn't there.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.