In my application I'd like to accomplish 2 things when a user wants to take a break and clicks a log out button.
Lock the machine
Launch a custom screen saver that would show the time the user is logged out.
I managed to do the lock easily by:
[DllImport("user32.dll")]
private static extern void LockWorkStation();
I found a tutorial on how to make a custom screen saver. I downloaded the sample code and it worked fine. But when I added the LockWorkStation(); line it killed the screen saver.
Can you help me with this or suggest a workaround?
EDIT
This screen saver from tutorial is just w WinForm. Should I somehow install it to the system? Is it possible form my application level?
The solution most likely is the following:
Lock the workstation
Show the screensaver
For the second step, the following is important:
You application is simply a program showing a window. As such any windows it tries to show are not shown to the user when the workstation is locked.
Your window will only be shown when you register your program as a real screensaver, set it as the current screensaver and than start it, for example using the SC_SCREENSAVE message.
Related
I'm trying to create a screen that would pop up that would stop the user from doing anything on the screen, I want it so the user can only type in the box provided and they can't press any other key to exit the screen (like win R, alt f4, ....), any Ideas on what I can do here? thank you.
There isn't much you can do to prevent all the ways of killing a task. If you were creating a Kiosk style application, you can replace explorer.exe and use a custom shell that you write. Exiting your application then immediately logs off, but you still need to handle things like task manager. But in your case, you want to share the desktop with other users. I think the easiest way is to lock the workstation programmatically
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern bool LockWorkStation();
Then call LockWorkStation(); when you have occasion to do so. Let the OS handle the blocking of the user operations.
I'm writing a small tool that opens programs on specific screens, so that I can set our monitoring screens (1 machine has 2 screens) to reboot overnight and have it restore the monitoring webpages on boot to the correct screens. I had in mind to accomplish this by using .NET's System.Diagnostics.Process class.
I already saw it's possible to open a process and THEN move it somewhere using P/Invokes ( Open notepad to specific location on the screen, and to desired size? ),
however I want to set the target screen BEFORE the application opens, so that for example Chrome in Kiosk mode starts properly with this setup.
Does anyone know how to do this?
We created a similar solution not to long ago using the user32.dll's SetWindowPos. While it does not open the program on the desired window, it takes a couple of milliseconds to do so, so not really an issue for your requirement!
You can have a look at the following gist:
https://gist.github.com/reinhardholl/013a7c3fa319beeaf534#file-display-cs
Pay specific attention to the Display class:
private void ShowAppOnDisplay(App app)
{
SetWindowPos(app.Process.MainWindowHandle, 0, _screen.WorkingArea.Left, _screen.WorkingArea.Top, _screen.WorkingArea.Width, _screen.WorkingArea.Height, SWP_SHOWWINDOW);
}
Let me know if you require some more help!
I am doing win form project.(C#). In that project i am willing to add welcome screen. So i created a welcome screen. But, It want to show a few minitute and automatically closed and open login screen.
System.Threading.Thread.Sleep(1500);
LogIn n = new LogIn();
n.Show();
I try this code in form shown,load, activate events. BUt no use. Any one know what to do?.
Here's a tutorial explaining how to make a splash screen.
Add a line for splash screen in Program.cs. Run a timer in splash screen and close the form.
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FSplash()); // This is your splash form << added
Application.Run(new FMain());
}
In my opinion, you cannot create a splash screen in .NET for a .NET application:
The purpose of a splash screen is to distract users from long waiting times, until the application has been loaded, started and initialized.
Since a .NET application itself already has some startup time, there is no splash screen available within this time.
My solution
So in my applications, I am doing it the following way:
Write a small, tiny native C++ application.
Display a topmost bitmap (window with no borders) when the C++ application starts.
Let the C++ application start the actual .NET application.
The .NET application starts and when it is finished starting and initializing, it tells the C++ application to close. This is done through IPC.
The inter-process communication is done the following way:
The C++ application writes a temporary file.
When calling the .NET application, the file name is passed as a command line parameter.
The C++ application polls regularly whether the file exists.
The .NET application deletes the file as soon as the splash screen has to be hidden.
The C++ application exists as soon as the temporary file does not exists anymore (or a timeout occurs).
I know this is not 100% perfect, it was the most suitable solution I came up since I started developing .NET applications, years ago.
I've got an application (that is targetting .Net Framework 2.0) that is running on startup of the System, and I'm trying to get a NotifyIcon to display.
When my program starts up when a user either Runs it normally or is started as a child process after the system has already logged on everything is fine.
If my application starts up as the system is performing an AutoLogon using POSReady2009 (basically XP with Single User set). Then the NotifyIcon never becomes active.
If you subsequently check (in a timer) the .Visible of the Icon at any point later it always reports that it is visible = true.
If you disable the SSDPSrv and restart the Computer, the Icon displays correctly.
I have a sneaking suspicion this is related to .Net 3.5sp1 installed over the top of a .Net 2 system.
Is there some process that I should be following to ensure that my NotifyIcon is always available to the user.
I have setup RegisterWindowMessage("TaskbarCreated") but I don't get this message called, except when you forcilbly Kill Explorer.exe and restart it. Even so, a NotifyIcon interally registers for these notifications anyway, so it shouldn't be required.
I'm happy to stall the startup of my program, but once the program starts up, I expect that the icon shows correctly.
If there is a KB article that I cannot find detailing this I'd be happy with that too.
Hmm... that's odd.
This may not work, and it's possibly not the best way of doing it - but first of all try putting NotifyIcon1.Visible = True in the Load event.
If that isn't working why not try adding this into a timer...
NotifyIcon1.Visible = False
NotifyIcon1.Visible = True
This should then hide and show the icon everytime the timer ticks, at least then you can see if it's working. Maybe only run the timer 10 times and then it ends, that way the script should hide and show the icon 10 times by which time the system should be ready.
Let me know if this works - if not I'll have a scratchy beard moment and have another think!
Well it's kinda dumb but have endedup needing to modify the process of startup to deal with this issue.
Made the program it's own shortcut that get's placed into the Startup folder by our installer.
The program that triggers this no longer starts it automatically. Instead we inform the other program once we have started up (Dropping a trigger file).
The other program then monitors if the user closes us OR we just crash and automatically re-opens the program. [There is a proper process to follow if you wish to fully close down the system]
Inside the startup of the program we check to see if the SSDP service is available and Not set to Disabled.. if so, wait until this service has started. We then check that SQLServer is running.
We then prepare the NotifyIcon and set it's .visible= true and all is good.
Still have kept the RegisterWindowMessage in the event the user somehow kills windows explorer.
BACKGROUND
I wrote an app in C# that registers windows hotkeys (it takes a screenshot when I press PRINTSCREEN)
My code to register the hotkey, capture screen , etc all works. No issues there.
THE PROBLEM
IF my app is running (and successfully has registered the hotkey) and then I do something that causes a UAC prompt - usually this is caused when, for example, I launch some setup program - then the hotkey is lost. Lost = afterwards when I hit printscreen the event never comes back to my app. I have to close the app and restart.
THE QUESTIONS
Why is the hotkey lost?
What can and should I be doing different differently when registering the hotkey?
NOTES
I've seen this behavior with other applications that register hotkeys - running the app with the hotkey using admin privileges prevents the hotkey from being lost
What can and should I be doing different differently when registering the hotkey?
Avoiding apps like setup.exes that cause the UAC prompt is not a viable solution - the entire purpose of my taking screenshots is to document a setup experience over a number of applications
I have a workaround in that I can launch the app with admin rights - but I would rather avoid having to do make users do that
CODE
My code is very similar to this: http://www.codekeep.net/snippets/ea68475b-c33e-4a71-8008-90f63d7e918d.aspx
Given that Print Screen already takes a screenshot and puts it on the clipboard, have you considered monitoring the clipboard for changes instead?
Look at the SetClipboardViewer API function. For example.
When you do something that may cause an UAC - why not unregister the hotkey first and then register it again afterwards?