Determine what application/location the clipboard is pasting to? - c#

I have a C# application that needs to determine where the clipboard is pasting to before it does so in order to disallow the paste to applications that are not allowed/supported. This will be a security application extension that companies will be able to enable when employees are attempting to copy from and paste outside of confidential, internal documents.
Is this possible? I've done a thorough search and looked through the following link, but didn't find anything that would be useful.
https://msdn.microsoft.com/en-us/library/windows/desktop/ff468802(v=vs.85).aspx
edit: I can easily determine if the application being copied from is one of ours, so this will only be enabled in that case. Copy/paste functionality through the rest of the system will work as it always does.

Related

Programmatically copy in-use files

In my C# code I want to be able to use some Shadow Copy mechanism in order to copy files that are being used by another process.
I've seen that solutions exist on the web, in enterprise or command line tools. But could it be done programmatically in order to mimic a simple file copy?
It appears that alphavss does what you want. The sample file VssBackup.cs here seems to do exactly what you want.
This class encapsulates some simple VSS logic. Its goal is to allow a user to backup a single file from a shadow copy (presumably because that file is otherwise unavailable on its home volume).

How to write a window service that track the number of times a specific folder was Opened

I Hope that this is the Correct way of asking this question. first my problem is that i want to know that how many times a specific folder was opened from the time my windows service start's. I don't want to write a desktop application for this purpose because i want it to happen in the background and also later i may want to add some more functionality. So that is why i need to be it a windows service.
is there some kind of OS Event that i can handle during my code, i.e the event is fired when a user open's folder.
If this is not the correct method then please let me know some other method that can help.
That's not possible in C#. You can be notified of changes within a directory and infer from that that the directory was opened--but there are many times when a directory is opened and nothing will be changed. What you're describing is most like a File System Filter Driver.
From What is a File System Filter Driver:
A file system filter driver can filter I/O operations for one or more file systems or file system volumes. Depending on the nature of the driver, filter can mean log, observe, modify, or even prevent.
Writing a filter is relatively easy, considering there are templates that you can use to base your work from. But, they do consist of kernel-mode code meaning they're not written with C# (they are typically written with C) and they are drivers.
for more details: http://msdn.microsoft.com/en-us/library/windows/hardware/ff540382(v=vs.85).aspx

Change display information (like name) of files from a shell extension for explorer.exe

I'm currently working with a Chinese SMB server, on which almost all the company files are stored.
As the structure doesn't change, I'd like to be able to put a "label" on files, based on a rules (something that allow me to handle generated files, which includes dates for example).
I need only support for win7 and above, and I'd like my informations to be read from a text file rather than relying on some metadata or client's data.
So I thought of writting a shell extension to do the work. My problem is, that by looking at the documentation, I didn't find something that allow me to change the name. The best solution I've found so far is to go with the infotip handler, but I wondering if anyone has a better way to do this.
In short, it needs:
1) To be compatible with win7 (and above),
2) To be visible at first sight
3) To use a readonly fs
After extensive research, I've found that the best way to do it is to write a Shell Namespace extension.
I'll be able to provide a virtual directory representing my server's structure, and translate the names the way I want.
This seems a little overkill though, but there's no other way to change the informations displayed as the display name is managed by an IShellFolder which provides it to an IShellView
One excellent source of informations I've found about it, and the most up to date so far, is an article on Michael Edenfiled's blog

How to get copied text from memory without pasting?

I got one requirement which is when the user copy any text the system should get the copied text from the memory into the program without require the user to paste it in a txtbox or similar control. I searched on the internet but I didn't get any information. can somebody suggest or provide some references so that I can follow...????
any help would be highly appreciated...!!!!
From a web development standpoint, you can not access the clipboard directly. You will have to create either a Flash or Silverlight hook into the clipboard to get the data.
Example
Another Example
For security reasons, you will never be able to do that in Javascript.
As it is already pointed out accessing clipboard is either not possible or restricted for security reasons for all components running on a page in a browser (restricted == is unlikely to be enabled by anyone, especially for such "spy on clipboard" purpose).
For standalone application you can either scan clipboard all the time or use clipboard filters.
Native functions are around SetClipboardViewer and GetClipboardData.
Managed: Clipboard.

Patch an application

I need to create a patching routine for my application,
it's really small but I need to update it daily or weekly
how does the xdelta and the others work?
i've read around about those but I didn't understand much of it
the user shouldn't be prompted at all
Ok this post got flagged on meta for the answers given, so I'm going to weigh in on this.
xdelta is a binary difference program that, rather than providing you with a full image, only gives you what has changed and where. An example of a text diff will have + and - signs before lines of text showing you that these have been added or removed in the new version.
There are two ways to update a binary image: replace it using your own program or replace it using some form of package management. For example, Linux Systems use rpm etc to push out updates to packages. In a windows environment your options are limited by what is installed if you're not on a corporate network. If you are, try WSUS and MSI packaging. That'll give you an easier life, or ClickOnce as someone has mentioned.
If you're not however, you will need to bear in mind the following:
You need to be an administrator to update anything in certain folders as others have said. I would strongly encourage you to accept this behaviour.
If the user is an administrator, you can offer to check for updates. Then, you can do one of two things. You can download a whole new version of your application and write it over the image on the hard disk (i.e. the file - remember images are loaded into memory so you can re-write your own program file). You then need to tell the user the update has succeeded and reload the program as the new image will be different.
Or, you can apply a diff if bandwidth is a concern. Probably not in your case but you will need to know from the client program the two versions to diff between so that the update server gives you the correct patch. Otherwise, the diff might not succeed.
I don't think for your purposes xdelta is going to give you much gain anyway. Just replace the entire image.
Edit if the user must not be prompted at all, just reload the app. However, I would strongly encourage informing the user you are talking on their network and ask permission to do so / enable a manual update mode, otherwise people like me will block it.
What kind of application is this ? Perhaps you could use clickonce to deploy your application. Clickonce very easily allows you to push updates to your users.
The short story is, Clickonce creates an installation that allows your users to install the application from a web server or a file share, you enable automatic updates, and whenever you place a new version of the app on the server the app will automatically(or ask the user wether to) update the app. The clickonce framework takes care of the rest - fetching the update , figure out which files have changed and need to be downloaded again and performs the update. You can also check/perform the update programatically.
That said, clickonce leaves you with little control over the actual installation procedure, and you have nowhere close to the freedom of building your own .msi.
I wouldn't go with a patching solution, since it really complicates things when you have a lot of revisions. How will the patching solution handle different versions asking to be updated? What if user A is 10 revisions behind the current revision? Or 100 revisions, etc? It would probably be best to just download the latest exe(s) and dll(s) and replace them.
That said, I think this SO question on silent updates might help you.
There is a solution for efficient patching - it works on all platforms and can run in completely silent mode, without the user noticing anything. On .NET, it provides seamless integration of the update process using a custom UserControl declaratively bound to events from your own UI.
It's called wyUpdate.
While the updating client (wyUpdate) is open source, a paid for wybuild tool is used to build and publish the patches.
Depending on the size of your application, you'd probably have it split up into several dll's, an exe, and other files.
What you could do is have the main program check for updates. If updates are available, the main program would close and the update program would take over - updating old files, creating new ones, and deleting current files as specified by the instructions sent along with a patch file (probably a compressed format such as .zip) downloaded by the updater.
If your application is small (say, a single exe) it would suffice to simply have the updater replace that one exe.
Edit:
Another way to do this would be to (upon compilation of the new exe), compare the new one to the old one, and just send the differences over to the updater. It would then make the appropriate adjustments.
You can make your function reside in a separate DLL. So you can just replace the DLL instead of patching the whole program. (Assuming Windows as the target platform for a C# program.)

Categories

Resources