I have created a .NET Windows application in C#. I want to execute this application when the system becomes idle for sometime. The application is a user login application, i.e. when system becomes idle for sometime, a login page appears where the user logins with his username and password. Then only the user can continue using the system.
How can I make it work out? Please help as I am new in Windows applications.
I thought to run the application as a Windows service. I managed to run the application on Windows service start. But how can I trigger the app to run only when system goes to idle in Windows service? I also need to start the timer after the user logins to check idle time again. Please provide some code examples.
The system already comes with such functionality. On the screen saver configuration page you simply check the box titled "On resume, display logon screen". It can be configured with group policy.
There's absolutely no point re-implementing this.
How about:
Start your form hidden
Get the system idle time
Show your window.
Related
I want to pop up an application using windows services.
Right now the code that I am using is:
System.Diagnostics.Process.Start(#" ");
That code does not pop up the application when I start running the services.
You can not do that. User session interaction has been removed since Windows Vista. The process would be started in the session that the service runs in, which per definition is not desktop interactive.
What you can do is run windowless console-only tools.
Long story: Before Vista all services ran in the same session as the first logged in user ("session 0"). Since this is a security issue, this was changed in Vista, where a dedicated session ("session 0") is active from the start for services. The first user logs into session 1, the next user into session 2 etc.
Due to the separation of these sessions it is no longer possible to create desktop interactive services - there is no desktop session for services.
This also means you can not display message boxes or run desktop interactive tools in session 0 - there's nobody who can see them.
Is that the exact code that you're using?
If so you're not actually giving the process anything to start, just an empty string. You need to pass it the name of the executable.
For example:
System.Diagnostics.Process.Start(#"C:\Windows\System32\notepad.exe");
If this is not the exact code, please post modify the question with the exact code.
I have a windows service which gets the screenshots. But its creating only black screens. I know this happens because of session 0 isolation. I searched on internet and couldnt find any approved solution for this problem any working ideas will be really good.
1- Is there a way to change the session of a windows service and get the desktop screen of another user's session like session 1, session 2?
2- Is there a way to start a console application which runs in an another session other than session 0 from a windows service?
a windows service is designed to run also when there are no users connected, it works like a server process always up and listening, or up and doing something, or idle.
I think what you need is a client application which runs inside every logged user' session and eventually does the job then, if needed, communicates with the service to carry some job done.
I am saying here that instead of having the windows service running in another session than 0 you can create a small executable (probably with no UI at all) that starts up from the start up folder of all users at every user login. such application is then running inside the proper session and has access to it, it can get the screenshot then either store it somewhere itself or call some end points in your Windows Service (running always in session 0) and make the service to elaborate the screenshot taken from the client application of it.
this is the way I would do it, not trying some "magic" to tell Vista and 7 to start a service inside a session of a user that in the end is not logged in yet when the system starts.
Is there a way to change the session of a windows service and get the desktop screen of another user's session like session 1, session 2?
No.
Is there a way to start a console application which runs in an another session other than session 0 from a windows service?
This can be done but it's messy. It involves impersonation of the logged on user, manipulation of user tokens, and launching a process into a different session with CreateProcessAsUser(). This article describes what is needed.
As an aside, you don't want a console application because that will splat a console window on your screenshot. You just want a standard Windows app (using the GUI subsystem) but one that does not show any visible windows.
I wrote a C# application using RESTful web services. This application should interact periodically with our server application. I want this program to keep running in the background even if the user logs out of the computer. How can I do this in C#?
If you don't want your application to stop when the user logs out, then the application can't be running in the user's session (really a WinStation). That implies your app needs to run in a different session. The sessions that don't logout are service sessions. Run Task Manager and add the Session ID column, and view all processes, and you'll see what I mean.
So your application needs to run as, or be launched by, a service.
In addition to the first answer don't keep the service running under the specific user account. If you do so then also it won't work if you logged off.
I wonder is it possible to run my application before login on windows.? Its actually a WinForm application(Preferably other than Windows service).
I mean my application must be running even before log in and it should sit on System Tray from which I can "show" or open Interface for user.
To have:
Something happen between system startup and user login
An icon in the notification area for users to interact with
You must break your application up into two separate components. One of these will be a WinForms/WPF application which provides the notification area icon and allows the user to interact with it. The other will be a Windows Service, or possibly a scheduled task.
Once you've done this, the windows service can focus on doing whatever needs to be done prior to logon and the notification area application can assume responsibility for showing the results, or whatever else to the end user.
To answer the question you posed in comments regarding reading data from the Event Log, yes this is possible. There are other questions on here which will give you that particular answer:
read the windows event log by particular Source
Read event log in C#
This MS article might help but it is a bit old:
http://support.microsoft.com/kb/142905
Hopefully it'll put you on the right tracks though.
I think, it doesn't make sense, to acquire user input before a user has logged into the system. So, if the application needs input from a user, why start it before the use has logged in? If the application just starts some background work, than you should use a windows service, as this is the prefered way in windows.
Type in run gpedit.msc, for Group Policy,
There you can set start up script.
Application will launch before Windows Login,
Step to produce :-
Start --> Run --> gpedit.msc --> Local Computer Policy --> Windows Settings --> Script (Startup/ShutDown),
Add you .exe
It will launch Before login.
Do not try more in Group Policy, it may happen harmful for System
By Programmatic logic,
Try with registry key
this value is updating in registry,
by our program we can update directly registry then we can call application
You can schedule any application to be run when computer is powered on using Windows Task Scheduler. There is a corresponding option there.
But why would you need this? You should use a service for this.
My aim is to create a login form where the login form comes when the system goes idle.This form contains username/ password and comment box where user have to provide reason for why system has goes to idle state.(ie if user left for a meeting or a break,he/she should provide details about it).this should be a window application which i managed to make.
Now i have to make this application run when ever system goes idle and the user can use only when login through this.So windows service is a option to run a program when the system starts and it can be managed well through service. So i made a window service which mange to run the application when the service start.
Now i have mange the window service to call this win app every time system goes idle. what possible ways can i make it work through window service.
I have already mention the above question in a previous post here
please help...
This is the kind of app that users hate with a passion, nobody likes a machine forcing them to do things. They'll try everything they can to get rid of it or sabotage it. Any data it collects is junk. Vista partly solved the problem, services cannot do this anymore.
Don't waste your time on it.