简体   繁体   中英

Windows lock usb port per user in c++

My software is protected by a USB hardware token and I want to achieve the following:

  • A user should be able to start as many instances of the software as he likes
  • A Second user on the same machine should not be able to start the application if the first user is already running the software.

So basically if the first user starts the software I would like to lock the usb port so only this user can access it. The Software is written in C++ and is running on Windows >7 or Windows Server >2008

Any Ideas?

As Jonathon suggested, you can use global names object. Check the example for global shared memory: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx

When process starts, it shall

  1. get the GetUserName (maybe also GetCurrentProcessId ).
  2. open named shared memory, like "Global\\\\MyAppRunningInstances"
  3. Parse every line for values like: Username, ProcessId, heartbeat-timestamp...
  4. If it finds another process with different username, check the heartbeat timestamp, maybe it is long ago crashed :) (if that process wasn't the only one, shared memory mapping will not be destroyed)
  5. If timestamp indicates that "alien" process is running, you can quit current process with a message that there is another user session running
  6. If no "alien" processes detected, add/edit entry for current user.
  7. Do periodic heartbeat update with timestamp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM