I am a newbie in c#..Please dont get annoyed by my question if its kinda silly one..
I need to see the disabled playback and recording devices by c# code and want to enable or disable it as per my need.
How can I approach..??
I made a code using DirectX.DirectSound API but it is limited to enumerate the devices which are only enabled and i am not able see the disabled devices present. And I don't think there is any method of disabling or enabling the devices.
I'll be very thankful to u for the help.
And please also suggest me how can I do this with using other API's if possible.
I realize this is a really really old thread... but I landed here trying to find out how to list disabled audio devices, and I was successful with a C++ project called AudioEndpointController
Simply change the line:
PlaybackDevice = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pDevices);
to:
PlaybackDevice = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_DISABLED, &pDevices);
As far as i know, it is not possible to programatically enable/disable devices. As for the first part of your question (need to see disabled devices), this is in fact possible but not using c# alone, you'll have to use WASAPI for this either by using C++/CLI or using explicit PInvoke in C#. You're looking for IMMDeviceEnumerator::EnumAudioEndpoints which takes a flag indicating if you want to see disabled/unplugged etc. devices. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371400%28v=vs.85%29.aspx. The nice about WASAPI's IMMDevice interface in this case is that it exposes a GUID which corresponds to the device's DirectSound id, so you can actually use WASAPI to detect which devices are active/inactive etc. and do all your other stuff using DirectSound. For this, you'll want to use IMMDevice::OpenPropertyStore, and query for the PKEY_AudioEndpoint_GUID property. This is the exact same thing that's passed in to DirectSound's DSEnumCallback function.
Related
I'm writing a small c# program, I don't want the final user to take screenshots while using my program, is it possible? Or even if he takes one, how can I know it?
Thanks in advance and sorry if this is a poor-content question due to my lack of experience in c# coding.
You can create a system-wide keyboard hook using the low-level keyboard filter and cancel any printscreen keyboard combination. But if someone has also installed a helper application (like Gadwin or something) it'll become a lot more difficult because you won't know beforehand what keyboard shortcut you should catch (most tools allow to specify your own hooks).
Here's an article on using hooks in C#
and here's a ready-made keyboard hook library for .net that uses global mouse and keyboard hooks (use Google to find more freeware and commercial libraries and tools).
On a side note: it's generally not preferred to change the system behavior. Screenshots are system behavior and serve a distinguished purpose for trouble shooting. If you prevent this, users will not be able to show you a screenshot of something wrong. But if you must do it, you can do it.
EDIT: on a deeper level, you can install an API hook. All screenshot applications use API calls to get the content of a (part of) the screen. But API hooks are hard to get right. A more trivial way is probably by writing a user-level driver. While you can prevent all this, it is really worth all the trouble?
You might want a keyboard hook. But it'll tell you if the user pressed the "print screen" key, not if someone programmatically take a screenshot using some GDI function.
I doubt it's possible to prevent all the ways of taking a screenshot.
General answer: No. It's not possible to detect this - especially from C#. There are dozens of ways to take screenshot and even applications written in C++/WinAPI can only detect some of them, but not all.
Also consider - what if user is running your app in virtual machine? He'll be able to take screenshots at host machine and you can do absolutely nothing to detect (not even prevent) this.
I'm writing an app (in C#) which as a part of it must simulate and send some key strokes to another application. I'm using http://inputsimulator.codeplex.com/ project for simulating keys, and it works in many applications, but in some it doesn't - i.e. Mortal Combat 4.
I've googled about it, and found many answers varying from 'it's impossible' to 'you must use XXX library' etc. Those answered scared me a lot, and even nearly convinced I'm not able to do it at that time, BUT...
M$ Virtual Keyboard works. It works in ALL applications. So it IS possible... Does anyone of you, clever guys, know how can I achieve this?
Ok, I think I finally got it to work. I used API Monitor recommended by Neal P and it showed just minimal differences between OSK calls and mine. A bit later I've tried to make my calling thread sleep some time between sending messages with press and release key and that was it.
Although you were able to achieve your purpose, the way you achieved it does not fundamentally answer your question: How to simulate keyboard input in ALL applications?
There's a bunch of situations where the common user mode Microsoft API already mentioned does not work, like game applications that use the DirectInput API or protected games.
I have built a library that can help in this situations, it provides a simple C API that internally communicates with device filter drivers. It is able to send input for DirectInput based games and also is able to bypass some game protections. I have checked and it is still able to bypass some known game protections by using the x64 version of the library. Game protections commonly hook only the x86 system's api. Well, at last now, 18 February 2012, this is what I'm seeing happening.
Take a look at SendKeys on MSDN
My project
I am working on a small program which has to set an alarm if the user locks the computer without removing the Smart Card from the computer.
I am using C# with WPF and .Net 4.0 and my smartcard is version V4.2C
My problem
I have all the functionality to work but I simply don't know how to detect if the Smart Card is in the Smart Card Reader.
I have tried to search on google but with no result so I hope some of you can help me.
Usually you would want to use the PC/SC framework for talking with a smart card, but it can be quite some work to implement from scratch yourself.
I would recommend to look into some existing project and get some ideas from there, as there are many projects that implements PC/SC in .NET.
Take this one from CodeProject for example.
Well, if I google for "C# smartcard" the first link which pops up is a code project article. It appears that the project provides events for detection of smartcard insertion/removal which is probably what you want.
Have a look at http://code.google.com/p/pcsc-sharp/
Works very well for me on 32bit and 64bit platforms, and supports mono too.
Besides the use of PC/SC to detect the presence of the card , from your description that doesn't seem very secure if the presence of the card in the reader is the sole condition for (un?)locking the PC without alarm, unless you scan periodically the card for some randomly generated data or some similar process which would ensure that the card isn't present since onbly the card could generate the right random sequence?
I'm using DirectShowNet.dll to grab a photo
of my web camera.
Anytime my camera initializes it first shows me this
screen. Where can I turn it off?
http://www.goat-it.com/!tino/screen.jpg
Looks like your code is pulling up the prop pages for your camera. I have only been able to get this property page to show if I explicitly write code to do it. How are you getting the image? Graph -> CaptureGraphBuilder2 + SampleGrabber -> SampleGrabberCB?
You could use the Win32 FindWindow command to find it and then send a WM_COMMAND to press the OK button?
Edit: Well if you want to do it the more "proper" way (Though my experience is from the C++ end, but I assume its much the same) you may want to locate the video capture filter. Once you've located that you can query interface it to see if you can access its IPropertyPage (IIRC) interface. If you can then you should just be able to call Deactivate.
Alas I don't have access to a webcam at the moment so I can't check on how exactly to do this ...
Are you using the ICaptureGraphBuilder? If so it may well be worth learning how to enumerate all the devices and attach them together yourself. It will give you a MUCH better understanding of whats going on :)
My webcam has a button, with which you take a photo of current frame
when using it's original software what came with it when I bought it.
Is there any way to use that button to take photos in my program.
I would be using C#.
I was thinking of using Windows Image Acquisition (WIA) or avicap32
for using webcam in my software.
Any help would be appreciated. Where do I start?
EDIT:
I see that you didn't understand me. I need to know if my phisycal camera button is pressed.
I am using DigiMicro 1.3 camera (Manufacturer is DNT), which isn't really a webcam but a USB microscope, but
it behaves like a webcam.
Does the camera actually require that the software be running when you press the button? I know some webcams implement this feature at the driver level. If that's the case, I don't think there's much you can do without interacting directly with the USB port, which would be incredibly difficult and likely not worth the trouble. I can't find any technical documentation on the vendor's website with that kind of information.
The "MicroCapture" software doesn't come with any DLLs that have exported functions, so P/Invoking doesn't appear to be an option. Unfortunately, I can't get the driver installed, so I can't check if it comes with any P/Invoke-able DLLs.
Sorry, but since there's no standard interface for that kind of functionality and the vendor doesn't provide any specific information on it, I don't think this is possible. I would suggest contacting DNT directly about it. They may have some component that will do what you need.
This Coding4Fun post guides you through pretty much everything you need to do to get started using WIA, including adding the reference to a project, displaying the select a device dialog, and of course actually taking the picture :P.
Coding4Fun - Look at me! Windows Image Acquisition
I suggest that you take a look at the DirectShow.NET library. It has great functionality for capturing images/videos off connected devices. It also comes with several samples to get you started quickly.