What is the best way to scan the local Windows system for attached USB devices using C++? I need to get a list of Vendor and Product IDs to match against the my device's IDs. If there is a way to scan for a specific VID/PID combination, that would be even better. My end goal is to retrieve the virtual COM port Windows has assigned to the device. If there's a way to do all that, it would be fantastic. As always, examples are much appreciated. Thanks.
This is pretty much an MSDN example of what you want:
http://msdn.microsoft.com/en-us/library/ff558728%28VS.85%29.aspx
It seems you'll need the WDK if you want to access this kind of functionality (every MSDN search I can think of suggests this).
I was able to resolve this by querying WMI for the needed information. Basically, I was able to start with Microsoft's example code, modify it a bit, and finally build it into my own class that does what I need.
http://msdn.microsoft.com/en-us/library/aa390423%28v=VS.85%29.aspx
This list of Computer System Hardware Classes was also helpful:
http://msdn.microsoft.com/en-us/library/aa389273%28v=VS.85%29.aspx
I used the WMI Code Creator to preview the results of what looked to be promising classes.
In the end I used the following:
Namespace: root\CIMV2
Class: Win32_SerialPort
Property: PNPDeviceID and DeviceID
Related
How is it possible to select which network interface to use?
I have multiple VPNs installed, Hamachi for example (25.0.0.0)
It is the first one in priority list in my "network adapters" window on Win7.
However, when I use sockets in SFML, it still uses my "local interface", which is 192.168.etc.etc.
Some games I saw are always using local interface, some of them are using the first one in priority list, some of them allow player/user to choose which one to use.
How is it handled in SFML?
I looked through documentation, but haven't found anything about it.
Google did not help too, probably because I don't know how to phrase my question properly.
I want to get the groups the local machine belongs to in the domain.
The function NetGroupEnum() returns these groups, but only when the computer is online.
The problem is what do I do when I am offline?
I know the information is available because I can find it using various tools, but I don't know how they're doing it.
I've been looking for quite some time, doesn't anyone know how?
Important: I don't want to use WMI.
Also, a solution in C# is also okay, but WINAPI is much more preferable.
EDIT: To be more specific, I am trying to find out which security groups the local machine belongs to. I can see it using gpresult.exe even when I am offline.
It sounds like you want NetQueryDisplayInformation with level = 3 to retrieve group information.
This will retrieve locally-cached information when possible, so they can work when the computer is offline (and even when online, typically give faster response that NetGroupEnum anyway).
I'm writing a metro app for Windows 8 (C# 5) to act as a power control app allowing the user to enable and disable various devices the computer will likely have. For now, I'm just thinking bluetooth and wireless network adapter. Eventually I'll add other devices, but one step at a time.
The main aspects I'm worried about is reliably finding devices, enabling and disabling them, and querying their state (is the device already enabled?). I need to be able to do any of these on a variety of machines with a variety of different devices, including multiple NIC or Bluetooth hardware setups.
I've looked into devcon on Win7, but I'm worried about reliably discovering the devices. If I grab the wrong devices, who knows what I'll be disabling, not to mention it won't disable what I intend to disable. Also I haven't tried it on Win8 yet and it may not be a portable app, I don't want people to install it and then my app.
WMI is powerful but always a bit intimidating to wander around in without a little guidance. If that's my best bet, I would appreciate some resources.
Command line or .Net library is what I'm hoping for, but I haven't tried this kind of stuff before so I'm open to any other alternatives. Also, any foresight into working with other devices like cellular network cards or devices I haven't thought of yet would be great.
Much of what you want (eg Bluetooth APIs) are indeed sandboxed away from Metro apps. There are some substitutes in the Windows namespace, though whether they will meet your needs I don't know. Take a look at http://msdn.microsoft.com/en-us/library/windows/apps/hh464945 which has links to the suggested alternatives for working with devices.
Specifically the Windows.Devices.Enumeration namespace says it's about finding devices. However as I read the page it seems like it's more about discovering and less about controlling. I wouldn't be surprised to find you can't control them. But that's where I'd start digging.
I have a program that is using a configuration file.
I would like to tie the configuration file to the PC, so copying the file on another PC with the same configuration won't work.
I know that Windows Activation Mecanism is monitoring hardware to detect changes and that it can tolerates some minor changes to the hardware.
Is there any library that can help me doing that?
My other option is to use WMI to get Hardware configuration and to program my own tolerance mecanism.
Thanks a lot,
Nicolas
Microsoft Software Licensing and Protection Services has functionality to bind a license to hardware. It might be worth looking into. Here's a blog posting that might be of interest to you as well.
If you wish to restrict the use of data to a particular PC you'll have to implement this yourself, or find a third-party solution that can do this. There are no general Windows API's that offer this functionality.
You'll need to define what you currently call a "machine."
If I replace the CPU, memory, and hard drive, is it still the same computer? Network adaptor, video card?
What defines a machine?
There are many, many licensing libraries out there to do this for you, but almost all are for pay (because, ostensibly, you'd only ever want to protect commercial software this way). Check out what RSA, Verisign, and even microsoft have to offer. The windows API does not expose this, ostensibly to prevent hacking.
Alternately, do it yourself. It's not hard to do, the difficult part is defining what you believe a machine to be.
If you decide to track 5 things (HD, Network card, Video card, motherboard, memory sticks) and you allow 3 changes before requiring a new license, then users can duplicate the hard drive, take out two of the above, put them in a new machine, replace them with new parts in the old machine and run your program on the two separate PCs.
So it does require some thought.
-Adam
If the machine has a network card you could always check its mac address. This is supposed to be unique and checking it as part of the program's startup routine should guarantee that it only works in one machine at a time... even if you remove the network card and put it another machine it will then only work in that machine. This will prevent network card upgrades though.
Maybe you could just keep something in the registry? Like the last modification timestamp for this file - if there's no entry in the registry or the timestamps do not match then fall back to defaults - would that work? (there's more then one way to skin a cat ;) )
I'm developing a small windows app using c++ and i would like to get some kind of fingerprint of the software/hardware on a pc so that i can allow the app to be run only on certain pc's.
I am aware that the app can be cracked but i'm really interested in implementing something like this.
Any ideas how could i achieve this?
It basically depends on how tight you want to couple your software to the underlying hardware. For example you could get some hardware information from the registry, read out the MAC address from the LAN card, retrieve the gfx manufacturer, the CPU id, etc. and hash all these data.
You could then use this hash as a challenge code which is sent to your company. The customer then receives the signed (with your private key) version of this hash.
Upon start up your application is able to check if the signature of the hash is good or bad (i.e. has been signed by your company).
This not only binds your software to a certain hardware configuration, but also forces the crackers to patch your application (because they would need to patch the public key from your executable and replace it in order to write a keygen). Many people consider twice installing a crack obtained from various sources in contrast to just entering a valid serial copied from a keygen.
Edit:
In order to check the signature of the hash, anything from RSA over DSA to ECC can be used. I can recommend Crypto++ or libTomCrypt for that.
There's no reliable way known to do this in a vanilla PC; people have been trying for years. The problem is that you might change any component at any time, including the CPU and the BIOS ROMs. The closest people have come is using a cryptographically protected "dongle" but that has proven both to be unsatisfactory in operation, and not very secure.
If you come up with something, patent it; it would be very valuable.
As the others have said there is nothing perfect for what you want. I made a half-hearted attempt for a similar issue and ended up with a mix of drive volume ID (not good because it can be reformatted) and the OS key (from windows).
In the end I didn't spend much time on it as if people really want to crack your software they'll probably be able to do it. I left the dinky licensing "protection", but it is pretty poor.
Spend the time/effort on making them want to buy it by making it outstanding.