I was wondering how I could set a specific application (as in any running application, not just my own)'s volume level in c#.
I know I'd probably have to use P/invoke, this is fine. I'm just not sure on how the sound api's work and how I would go about getting/setting the volume of specific applications (like the volume mixer in vista/7 can).
I know it's possible to do programattically because nircmd has a feature that can do it.
Any help would be appriciated, thanks.
I think you should look here. Following the links you'll find interfaces and API functions to use to manipulate endpoints' volume. Together with the documentation, Microsoft provided some code samples in C++. As you said, it is possible to get the same functionalities to work in .NET using platform invoke.
I think (and hope) your request is, for all intents and purposes, impossible. Allowing an application to set its own volume is like allowing an application to override the user's notification icon settings. These settings are user settings, so you can't circumvent them.
Imagine for an instance that a user has the volume of his speakers set way up, but has dimmed the volumes of all individual applications. Your application comes along and goes 'whatevs, I'll just set myself to full volume'. You've just made a user go deaf, or at least cower in a corner of the room, scared to death.
Related
i need to block any screen capture software on the computer from taking screen shots. Since all of them are work on standard API-functions, i think i could monitor and block them.
I need to use C#.
All i have found is how to monitor and block them in a certain program (screen capture program). They are looking for a function in the program, then they change it address on mine function address.
But how can i do it, if i haven't any certain programs? I need to block anyone which tries to take a screenshot.
If your final goal is possible or not I don't know, but for the hooking the API portion I can help you out.
I have used the library EasyHook many times in the past, this will let you hook and intercept system function calls from C# code fairly easily. Just read through the PDF tutorial for setup instructions.
For actually finding the API's I recommend Rohitab's API Monitor, it's still in Alpha stages but it works really well and is free. You just hook it on to a processes and it tells you every external DLL call it makes (with the parameters it passed if you have the xml definition file for the DLL, the program comes with almost all of the windows API dll's pre-defined).
The combination of EasyHook and API Monitor is a great 1-2 punch for mucking with other program's calls.
It is not possible to prevent screenshots from being taken. The battle is already lost because of the DWM (Desktop Window Manager). It's lower level than Win32 and device contexts.
If you want to protect the text in your program, there are a lot easier ways to extract it than doing screenshots and OCR. TextOut and/or Direct2D hooking and accessibility APIs.
If there's a lot of IP in your program. Then don't make it all available onscreen. Make sure it's tedious to crawl the GUI for text, and hard to automate it. And don't load whole texts in memory of the program.
Possible solutions:
1. To prevent copying of text. Draw the text as an image.
2. To prevent accessibility technologies, like screen readers - override WndProc in your control, handle and ignore the window message WM_GETOBJECT.
3. To make it harder if they try to use OCR. Draw graphics behind the text. Human readable, but much harder for a machine to interpret it.
Neither of these methods are invasive for the user.
** A very invasive suggestion **:
If you are really serious about preventing anyone from "stealing" your content.
Implement mouse and keyboard hooks. Filter out typical copy shortcuts. Prevent the mouse from leaving the boundaries of your application.
Allow your application to only run when the OS runs well-known processes and services.
If any process starts which you don't recognize, black out the application and notify the user about it, and request the user to close it. And ofc make sure someone is not just spoofing a well-known process.
Monitor the clipboard as you suggested yourself.
You can ofc soften some of these suggestions based on the context of your application.
As Scott just posted it likely can be prevented with API hooks to see that paint events only go to desktop bound handles and not others, and refuse to paint otherwise. However, you need to consider the following scenarios and see if they're relevant threat to your approach or not:
Your software may be running in a virtual machine like VMWare. Such software has capapbilities to capture screen that does so at "virtual hardware" level, and your API hooks will not be able to discern it - and this would be the easiest way approach if I wanted to bypass your protections.
As a post suggests here, nothing also prevents someone to take monitor cable and plug it into another computer's capture card, and take screenshot that way. Again, your hooks will be helpless here.
Bottom line, you can make it somewhat harder to do, but bypassing such protection may be pretty trivial thing to do.
My 2c.
I have a ASP.NET Web Application. I want to access this application in Smart phones and tablet computer. So please help me on this. What are the changes required?
The answer to your question could range from nothing to everything. At the end of the day, it all depends on what you existing app looks like in a target mobile device (iPad, Android, etc). If your existing app looks and functions properly, then you don't have to do anything. If not, well, you figure out what's wrong and make it work.
Your question really isn't suited for StackOverflow because it is way to broad and impossible to answer.
Asp.net applications can run in web browsers, including the ones that come with smart phones and tablets. The main concern would be the various screen sizes of the various devices. Because they vary so much, a good design concept for your asp.net application would be to layout content in a way it can adapt to the screen size.
The best technology for this within an asp.net application, especially for an application that was already built, would be to implement style sheets (.css)
Look at these styles as an example:
float, clear, max-width and max-height
Check these and other styles at: http://www.w3schools.com/css/
Now, there is also the concept of having your asp.net application detect which device is being used and then generate UI code (or load .ascx controls) accordingly to provide device specific displays.
Check:
Request.Browser.IsMobileDevice
Request.UserAgent (http://msdn.microsoft.com/en-us/library/system.web.httprequest.useragent.aspx)
However, I would only suggest using this to a minimum, because if you make a change to your UI, you won’t want to keep updating multiple instances of the UI for different devices.
A good compromise would be to build a style sheet for each group of screen sizes (smart phone, tablet, PC, etc.) and then detect which device is in use and include the respective style sheet.
NB: there are many open source projects, which could get you running more quickly with mobile development in mind. Check sourceforge.net and codeplex.com for examples.
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 am working on a web project where content security is client's first priority. I need to create a windows app which will track if the user while visiting the website, is running any screen recorder. If he is, I need to log him out. I have knowledge on c#, vb.net. Can you please tell me if it is possible to track if screen recorder is running on user's computer?
You seriously want to prevent access to a web-site being recorded?
The simple answer is no, you can't tell. However, MS does offer some content protection APIs that might be more what you need, IF you are rendering to a DirectX 11 surface:
Direct 3D Video APIs on MSDN has more info.
It might cost colossal resources to implement such solution (that will have holes and must be maintained). Monitoring web site by means of a desktop app sounds like a dirty insecure hack. What if the user has a mobile phone with the camera?
Better, you shall rely upon standard widely accepted security principles of HTTP/TSL, such as proper authentication, authorisation, security policies, encryption, strong passwords etc.
I would like to render a single image using DirectX.
It should work similar to VLC player's "directx video output", were it is not possible to capture a frame using simple screen capturing software or the printscreen-key.
It should not be possible (or very difficult) to make a screenshot!
Does anyone know how this works in VLC player?
Are there any other possible solutions?
Maybe with "Output Protection Manager" (see http://msdn.microsoft.com/en-us/library/dd388980(VS.85).aspx)
I've about 3 years C# programming experiance earnt at school.
I've also done some C++ programming, but I would prever a C# solution maybe using WPF or Managed DirectX.
Sorry for my English and thanks for your help in advance!!!
First, the reason that VLC's content doesn't get captured when you use printscreen or other screen capture techniques is because (at least on older versions of Windows) they are using an 'overlay' to present the video. This is a special GPU construct that allows rendering to a virtual 'plane' above the normal screen surface. Since this bypasses everything else and goes straight to the GPU, there isn't any straightforward way to capture it. NOTE: In the last few releases of Windows the rules changed quite a bit concerning overlays. Apps can't assume that D3D9/DDraw overlays are supported and apps shouldn't use them nowadays since the system has much better methods of presenting content with the same high performance.
Direct3D 9 Overlays
If you are displaying video content using Direct3D 9, you too can use an overlay. See this page on MSDN for information on how to do it. There are a lot of restrictions on the usage of D3D9 overlays and they aren't supported on a lot of hardware, so I'll describe some other approaches.
This technique does not prevent other apps from injecting them into your address space and capturing your presents. Also, because it's not supported on some hardware and some capture APIs actually disable overlays, it doesn't provide very strong protection guarantees.
GPU-Based Content Protection
If you have a lot of time to learn about GPU content protection and you know you'll be displaying a non-standard DRM-protected video format, you can roll your own protected media path using GPU content protection. I'm not an expert in this area, and there are few who are. I wouldn't recommend this, but I wanted to point it out. This page on MSDN talks about how it's implemented in Direct3D 9 and this other page talks about how it's implemented using Direct3D 11.
This technique provides strong guarantees that the content has not been captured, since the key-exchange happens almost entirely through hardware (e.g. HDCP).
Media Foundation Protected Media Path (PMP)
If you are displaying video using a well-supported DRM-based media format, you can use Media Foundation's Protected Media Path, which makes use of the GPU-based content protection described previously. It also encapsulates most of the functionality in a separate protected process that other apps cannot intercept or otherwise interact with. If someone tries to install a test-signed driver or otherwise inject a binary that isn't code-signed by a trusted root authority, Windows will not allow the content to be decrypted and your content will remain secure. This technique provides strong guarantees that the content has not been captured. This is used by Netflix on Windows, Blueray players, and others.
DXGI Swap-chain Flags
Assuming you are presenting content using Direct3D 10.x/11.x (and hopefully now you are, as opposed to D3D 9, in 2014), you can use a number of flags on your swap-chain to lock down your content.
You can pass DXGI_SWAP_CHAIN_FLAG_RESTRICTED_CONTENT in the swap-chain flags in order to fail the swap-chain creation if the system doesn't have HDCP or HDCP-like output protection. This probably isn't necessary for your purposes, but it's good if you are worrying about people capturing the HDMI or analog output.
The flag you definitely want is called DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY. This prevents all screen-capture APIs from ever seeing your swap-chain. It will just appear as a black rectangle to them.
See this page for all the DXGI swap-chain flags.
This technique doesn't provide the strong guarantees that GPU-based content protection provides, but if you are pretty confident that other apps aren't doing crazy things like injecting themselves into your address space and hooking your present calls, you can be be confident this prevents anyone else from seeing your content (except the monitor, of course).
Full-Window Protection
Sometimes you might want to protect more than just DXGI-presented content. In that case, you can actually make use of a similar mechanism to simply protect an entire window from being captured by various screen-capture techniques. It's an API called SetWindowDisplayAffinity. It's equivalent in strength and function to passing the DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY flag for a swap-chain, but it also protects content presented with GDI, older DirectX technologies, etc. Pass the WDA_MONITOR flag to enable protection for a given HWND, or pass WDA_NONE to disable protection.
For full disclosure, I work at Microsoft on the team that handles display logic, including some forms of screen capture and content protection.
Maybe by the sound of it you need to intercept WM_PRINTCLIENT by hooking into a global windows procedure, if the WM_PRINTCLIENT message is used, just return from the hooked window procedure. See here for a detailed information by Feng Yuan about WM_PRINTCLIENT. The other way of doing it is to intercept the clipboard functions where the data is from a particular application and the clipboard contains a bitmap.. See Larry Osterman's blog about this. Here is an article on CodeProject that implements a global windows hook, there's two other links I could supply here and here. (All on CodeProject)