Internet Explorer BHO check for multi-instance of site - c++

I'm working on a project for a client. We are building an internal web portal, and for various (mostly political) reasons have ended up building a BHO for IE8. One of the things t does is make sur that only one instance of the portal can be opened at once. It does this by writing a temp file when the portal is opened. Unfortunately this is not optimal as if IE crashes for any reason then the next time the portal is fired up, the user is left staring at an "unauthorised" message until the stale temp file is removed.
So my question is: is there any way within a BHO to see how many times the same url has been loaded? I mean is there some way to get that information directly from IE?
It's actually a little more complicated than that, given that we need to allow popups etc. But this would be a good start.
Thanks for your time.

If you want limit browser instances in the current user session you can use a mutex instead of a file. try acquire the mutex at the startup of the BHO (in the SetSite call) with a reasonable timeout, and release again in the final SetSite call.
If the result is WAIT_OBJECT_0 or WAIT_ABANDONED, there is no other BHO instance holding the mutex, while WAIT_ABANDONED occur when another thread crashed while holding the mutex. If the result is WAIT_TIMEOUT, the mutex is already taken by another BHO instance and you should not let the user to use your web site according to your requirement.
But if I am a determined user I can fire up XP Mode and access the web site from there...

Related

How to tell that the logon screen is currently displayed?

I am writing a service application that will run with local system credentials. I will need to know from my service if the Windows logon screen is displayed at any particular time. Is there any way to do this?
PS. The screens that can be brought up by locking the workstation:
Or by trying to switch the user:
Or after a Ctrl+Alt+Del:
PS. I need this to run on Windows XP and up.
EDIT: The only viable solution that I came up with so far is to see if LogonUI.exe process is running. The issue with this approach is how to distinguish between the actual system logon process and any other process that has that image name?
As described in the comments you are trying to detect whether or not a process in an interactive desktop session should show a message box. There being no point doing so if the interactive session is not active.
In which case I believe that your proposed solution is the wrong one. Instead you should register for session change notifications by calling WTSRegisterSessionNotification. When you do this you'll get sent WM_WTSSESSION_CHANGE messages that allow you to keep track of the current state.
Note that you do this in your desktop app rather than the service. The service still sends its messages to the desktop app. But the desktop app now knows whether or not it is worth showing them.
Update
Remy suggests a better way in the comments:
And if a separate app is being used, there is no reason to detect session changes at all, that app can simply check if its currently assigned workstation/desktop is the currently interactive workstation/desktop instead, comparing GetThreadDesktop() to OpenInputDesktop(), for instance.
All such screens are presented on a separate desktop. You may try to enumerate the user's desktops and compare it with the current (I am not sure the service in session 0 - Vista and up - can do that; if not, spawn a helper process in the user session). This however may give a false positive if an UAC desktop is up. Another corner case is a userless situation (right after boot before any user looged on).
There are several states in the windows.
Logged-Off State
When Winlogon is in the logged-off state, users are prompted to identify themselves and provide authentication information. If a user provides correct user account information and no restrictions prevent it, the user is logged on and a shell program (such as Windows Explorer) is executed in the application desktop. Winlogon changes to the logged-on state.
Logged-On State
When Winlogon is in the logged-on state, users can interact with the shell, activate additional applications, and do their work. From the logged-on state, users can either stop all work and log off, or lock their workstations (leaving all work in place). If the user decides to log off, Winlogon will terminate all processes associated with that logon session and the workstation will be available for another user. If, instead, the user decides to lock the workstation, Winlogon changes to the workstation-locked state.
Workstation-Locked State
When Winlogon is in the workstation-locked state, a secure desktop is displayed until the user unlocks the workstation by providing the same identification and authentication information as the user who originally logged on, or until an administrator forces a logoff. If the workstation is unlocked, the application desktop is displayed, and work can resume.
reference: https://msdn.microsoft.com/ko-kr/library/windows/desktop/aa380547(v=vs.85).aspx
p.s. registering a secure attention sequence (SAS, CTRL+ALT+Delete) is included in Workstation-Locked state
Similarly, there are several desktop types on windows.
Winlogon desktop
Application desktop(=Default desktop)
Screensaver desktop
Secure desktop
I recommend you read this:
https://msdn.microsoft.com/ko-kr/library/windows/desktop/aa375994(v=vs.85).aspx
I don't know my answers are what you want... but I hope it helps in some ways.

Detect change for multiple app instances when there are several logins

Suppose I created an app which runs by two users currently logon, with user1 inactive and user2 active, see below illustration (so there are two process exist simultaneously in system), the app will read/write a physical file, say adding some info to this file.
My question is, when user2 adds some data to this file, after switching back to user1, how can app inst1 knows about the change? (we can of course restartapp inst1 but it is not desirable).
One solution is let app handles session change event, in Windows there is a WTSRegisterSessionNotification which needs a HWND but my app is a console app.
Any ideas?
You can use the Windows API function FindFirstChangeNotification:
http://msdn.microsoft.com/en-us/library/aa364417%28VS.85%29.aspx
You register what conditions you want to be notified about (in your case, probably last update time) and get a handle which you can then wait on. You would, I guess, want to put this in a separate thread rather than blocking your main thread.

How to determine a successful share by addthis service

One of my client wants to get some logic done on server side immediately after a member successfully share a link from his site. The problem is that some time member just open the share dialog by clicking the button and close it without sharing.
I was trying to use add eventListener to event type "addthis.menu.share" but this event get fired as soon as dialog is opened by clicking the service icon. It never determine whether a user really shared the link or just close the opened service dialog without sharing.
SO my question is there any way to know if a user has successfully shared the link immediately after sharing?
Unfortunately, none of the services (FB, TW, G+, etc.) provide any type of callback/response that can be used to determine if the user actually shared the page. This makes it impossible to know if the share actually occurred in realtime. You can use either the APIs from the service like FB:
http://graph.facebook.com/http://www.addthis.com
To get the number of shares or you can use the Analytics API from AddThis:
http://support.addthis.com/customer/portal/articles/381264-addthis-analytics-api#.UJqEWeOe_L4
I hope this helps.

Windows Service with GUI monitor?

I have a C++ Win32 application that was written as a Windows GUI project, and now I'm trying to figure out to make it into a Service / GUI hybrid. I understand that a Windows Service cannot / should not have a user interface. But allow me to explain what I have so far and what I'm shooting for.
WHAT I HAVE NOW is a windows application. When it is run it places an icon in the system tray that you can double-click on to open up the GUI. The purpose of this application is to process files located in a specified directory on a nightly schedule. The GUI consists of the following:
A button to start an unscheduled scan/process manually.
A button to open a dialog for modifying settings.
A List Box for displaying status messages sent from the processing thread.
A custom drawn window for displaying image data (the file processing includes the creation and saving of images).
A status bar - while a process is not running, it shows a countdown to the next scheduled scan. During a scan it also provides some status feedback, including a progress bar.
WHAT I'M SHOOTING FOR is a service that will run on boot-up and not require a user to login. This would consist of the scheduled file processing. However, when a user logs in I would still like the tray icon to be loaded and allow them to open up a GUI as I described above to monitor the current state of the service, change settings, start a scan manually, and monitor the progress of a scan.
I'm sure that I have seen applications like this - that function as a service even when I'm not logged in, but still give me a user interface to work with once I do log in.
I'm thinking that instead of having a single multi-threaded application that sends messages to the GUI thread from the processing thread, I need two applications - a Service to perform the processing and a GUI application to provide visual feedback from the Service and also send messages to the Service (for example, to start a scan manually). But I am new to Windows Services and have no idea how this is done.
It is also possible that I'm completely off base and a Service is not what I'm looking for at all.
Any help / ideas / suggestions would be greatly appreciated! Thank you.
You can't do this as a service.
You'll need to make your Windows Service as a normal service application. This will startup on system startup, and run the entire time the system is up.
You'd then make a completely separate GUI application, which "talks" to the service. This can be set to run when a user logs in, in the user's account.
In order to make them "talk" to each other, you'll need to use some form of IPC. Since these run on the same system (but in different accounts, typically), named pipes or sockets both work quite well.
There is a simple way of doing it.
You can’t have the service access any user’s session (session 1,2,3..) since services are isolated and can access session 0 only. This is a change from 2011.
You should write a win32 program to be launched by your service per each user who logs in using https://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx
The service can continue performing any task that isn’t user specific.

Target IIS Worker Processes on Request

Ok, strange setup, strange question. We've got a Client and an Admin web application for our SaaS app, running on asp.net-2.0/iis-6. The Admin application can change options displayed on the Client application. When those options are saved in the Admin we call a Webservice on the Client, from the Admin, to flush our cache of the options for that specific account.
Recently we started giving our Client application >1 Worker Processes, thus causing the cache of options to only be cleared on 1 of the currently running Worker Processes.
So, I obviously have other avenues of fixing this problem (however input is appreciated), but my question is: is there any way to target/iterate through each Worker Processes via a web request?
I'm making some assumptions here for this answer....
I'm assuming the client app is using one of the .NET caching classes to store your application's options?
When you say 'flush' do you mean flush them back to a configuration file or db table?
Because the cache objects and data won't be shared between processes you need a mechanism to signal to the code running on the other worker process that it needs to re-read it's options into its cache or force the process to restart (which is not exactly convenient and most likely undesirable).
If you don't have access to the client source to modify to either watch the options config file or DB table (say using a SqlCacheDependency) I think you're kinda stuck with this behaviour.
I have full access to admin and client, by cache, I mean .net's Cache object. By flush I mean removing the item from the Cache object.
I'm aware that both worker processes don't share the cache data. That's sort of my conundrum)
The system is the way it is to remove the need to hit sql every new-session that comes in. So I'm trying to find a solution that can just tell each worker process that the cache needs to be cleared w/o getting sql involved.