I want to make a application that runs with no form interaction with user and only specific person can run a form and change config setting. The application is desktop reminder which runs every 4 months and shows up a notification.
I don't have any idea how to start it. Please guide me with some good suggestions.
If you have an application that needs to notify the user once every 4 months, its a bit overhead to have it running all the time.
Use the Task Scheduler in Windows, to schedule this command to run (once per day, or every week) check if the condition is met. If not silently exit.
You can effectively create a windows Service and then configure it to allow it interact with the desktop through the Services administration console.
However, for security reasons in W2008 Server (and I assume that more or less it will be the same with W7 or even Vista, you'll have to try it) this behaves differently, and services that interact with the desktop are not allowed. Actually, I remember that when I created and showed a Window I got a notification and when clicking on it the desktop switched to another one with my window. Still, no issue with XP, I've done it.
Related
So I created a Windows Service using C# and created an installer in Visual Studio for it. It's set up to run manually as I don't want it running all the time. I then have another application (C# WPF) that should have an option to turn the service on and off (the service itself creates a web service that in turn communicates back to my WPF application). This works fine in Windows XP, but testing it on a Windows 7 machine, it won't start. Surprisingly it does throw an exception and crash, it just does nothing. I believe this is a permissions problem. If I go to the services control panel using the same Windows 7 account, I'm not able to start or stop the service either.
So my question is, is there a way to set my service so that regular user accounts can start and stop it? And is there a way to set my installer to do this automatically.
I don't want my WPF application to have run as administrator!
Whilst I believe that it is possible to secure a service so that regular users can start and stop it, I do not recommend doing so. This will create a lot of complication and is a potential cause for confusion. I always prefer to keep things simple, especially when it comes to installation and security.
So, if we can't let the user start and stop the service we probably need to let the service run all the time. Since you don't want the service to be active all the time I suggest you give the service its own internal Running flag. When this is set true, the service is active and does busy things, otherwise the service remains idle. You can use your preferred IPC mechanism (sockets, named pipes, WCF etc.) to allow the user to toggle this switch.
Windows 8 has a feature to allow services to start on demand, basically in response to some kind of trigger. But for Windows 7, your only real option is to set it to start automatically on startup. You could set it to start delayed, so that its not adding to the time it takes windows to start.
Regular users cannot start and stop services.
EDIT: Reading the link in the comment above it sounds to me as that is a blanket ability for users to start and stop services. I think the question here is about how to do this for a particular service.
Also, while it may be possible to set the service to run as that particular user, it really means it only works for that particular user and other users on the work station would not be able to use the application as they'd not be able to start or stop the service, assuming that the service running as a user implies that the user may control it, which may not be the case.
Also in reading the comments and other answer, I'm left to wonder if the service can be used by any user which can run the application. That is, if user A logs on to the work station and starts this app (and thus the service), locks it and walks away, what happens when use B logs on and tries to run the same service? Can the service support multiple users at the same time, or will funny things begin to happen if the service is utlized by the application running multiple times.
This really sounds like what is desired is for a background to be started when the application starts. This thread (or threads) would do the work of the service, and by their nature would end when the application ends. Of course more detail in the question would help give a better answer.
Of course if it is appropriate as a service, I see no reason not to have a service with a worker thread that sleeps, and another timer thread that acts as a producer that checks if there's work to do.
I've created a service that runs as the Local System user. This service launches and monitors a Silverlight Out-of-browser application using native interop and the CreateProcessAsUser() method (to run it as the currently logged-in user, rather than Local System). I'm able to get a handle on the spawned Process and do things like Kill() it, however, I've become aware that the service is unable to get a handle to the main window of the child application because the child application is running as a different user. I'm running on Windows 7.
My end goal is to respond properly to when the Process stops responding (i.e. Process.Responding == false) so that I can kill the application and restart it. However, Process.Responding requires a handle to the main window of the process (Process.MainWindowHandle, to be exact), however, in this scenario, Process.MainWindowHandle always returns 0.
I'm stumped here. Is there any way for one user to get a window handle to a process running as another user in Win 7?
Thanks in advance for any and all help.
No, that's not possible. Windows Services are completely isolated from user-mode applications for security reasons. If you could get the handle to a window, you could manipulate and otherwise interact with that window, leaving open a huge security vulnerability.
More information is available here:
How can a Windows Service start a process when a Timer event is raised?
How can I run an EXE program from a Windows Service using C#?
windows service (allow service to interact with desktop)
Need suggestion on replacing Windows Service by invisible WinForm Application
Strictly speaking, what you're using the Windows Service for in the first place is bad design. It shouldn't be creating or launching any user-mode processes, or interacting with the user in any way. Remember that services run even when there is no user logged in! Thus, they shouldn't be starting applications.
A better solution is a simple background application, set to launch automatically when the user logs in. This background application could then launch the Silverlight application, monitor its state, and interact with it as necessary, because both would be running under the context of the same local user account. The effect is similar to a service, but without any of the drawbacks of isolation. The easiest way to do this in Visual Studio is to create a WinForms application (or possibly a WPF application, I have less experience in that area) that simply doesn't show any forms/windows.
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.
I have a C# Windows Forms interactive app and a related C# windows service.
On the particular machines where these are deployed, the login and app startup are automatic. The interactive app always starts well before the service. The app has a status indicator to show when it has connected to the service, but these machines are slow and it takes 45-60 seconds for my service to finally get started. During this time, there is nothing happening on the screen.
I should point out that my service starts quickly... it's the dependent (and other) services that are taking some time to start.
I would like to have some sort of indication of the windows startup progress displayed while the application is waiting for the service. I was thinking of showing a progress bar showing something like started_automatic_services/automatic_services. Is there some other more appropriate method?
One possibility would be to use a WMI event query to monitor the services starting up, which would allow you at least to give an idea of progress
Starting services:
Service 1 started
Service 2 started etc.
The MSDN sample Subscribing to and Consuming Management Events should be enough to get you going, as it specifically illustrates querying services for state changes.
Why not use a tray icon? An image that represents a 'broken' or uninitialized connection to your service would be the initial one used, and once the service comes up you can change that to a 'normal' or 'all is well' icon. Some AV software clients do that.
You could also use the same icon with an overlay, maybe a small hourglass on the lower right corner or something like that, and then remove it.
Maybe showing a progress bar every single time the user boots could be rather intrusive and annoying.
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.