Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a service with system authority. Now I want to create a window progress from this service.How can I do it?
Please answer me with code! Thank you!
Posted
Comments
Sergey Alexandrovich Kryukov 19-Nov-13 23:56pm    
What does it mean: "create a window progress"?
—SA
lezard618 20-Nov-13 0:59am    
It's a progress with UI. My English is pool. Sorry about that.
Sergey Alexandrovich Kryukov 20-Nov-13 1:04am    
No problem, thank you for clarification.
—SA

Technically you don't. Windows services don't have a desktop like regular desktop applications.

You can create an API for your web service that a service monitor can connect to. You would then run the service monitor when a user logs in, this monitor can receive events from the windows service about something starting, progress, and when its finished.

How you go about it is up for grabs, either you can use named pipes, MSMQ, remoting, etc. What fits into your specific application is difficult to say.
 
Share this answer
 
Comments
lezard618 19-Nov-13 21:59pm    
In fact I have created a progress from my service, but it do not have Administrator permissions.I want it have Administrator permissions.
lezard618 19-Nov-13 22:02pm    
And my service is not a web service. It's a local system service.
Sergey Alexandrovich Kryukov 20-Nov-13 0:13am    
Fair enough, a 5.
Frankly, the expression "create a windows progress" sound gibberish to me (please see my comment to the question), but perhaps OP wanted to create some UI. This is usually done by creating a separate windowed UI application communicating with the service and only started when a desktop becomes available, after a user logs on.
—SA
lezard618 20-Nov-13 1:14am    
I have logged on.Then I start my serivce.It's like "Apple Mobile Device" in Itunes and it's a service with system permissions.I want the service to run a program with administrator permissions.The program has UI. I used "CreateProcessAsUser" to do it, but the program don't have administrator permissions.It has system permissions.By the way, the user I logged on is not a administrator. It's a normal user.
Sergey Alexandrovich Kryukov 20-Nov-13 1:19am    
OP confirmed my guess about "windows progress", so I translated it into a more detailed answer, please see. Your answer is of course credited.
—SA
Thank you for confirming my guess: you want to create some UI to show progress in the service operation. As Ron correctly pointed out in his Solution 1, you cannot have UI in your service application, as it is non-interactive, but quite a good reason: when a user logs off, your service application still works, but there is no a desktop.

Here is a typical solution: you develop a separate application with UI. Typically, you would need to start it up when some user logs on. The a simplest way to do that is to put a link file in the "Startup" directory for all users. Another approach it to prescribe a path to this application is Registry under the key "Run". Please see:
http://msdn.microsoft.com/en-us/library/aa376977%28v=vs.85%29.aspx[^].

You can do this in your service installation (and should not forget to uninstall when uninstalling it).

Now, when the UI application starts, it should connect with your service application and start exchanging data and events. As both applications are on the same computer, using named pipes would be enough:
http://en.wikipedia.org/wiki/Named_pipes[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365799%28v=vs.85%29.aspx[^].

If can also be MSMQ or other messaging facility, and a lot more.

—SA
 
Share this answer
 
Comments
lezard618 20-Nov-13 1:38am    
Thank you for answer my question.I have created two programs. One is the service with system permissions, and the other is a program with UI.The service will start when the windows starts.When I log on and start the program with UI, it sends a message to the service in a named pipe.Then the program will close.When the service receives the message, it will use "CreateProcessAsUser" to restart the program with administrator permissions. I am not the administrator as I said and I don't know how to do it now, so I ask this question.
Sergey Alexandrovich Kryukov 20-Nov-13 1:48am    
No, never close a program, keep it alive all the time. It will close then the user logs off. You don't need any elevated permissions. You simply communicate with the service and do some acquisition/control of its behavior, with purely informational streams. All the actual action should be done by the service.
(What do you mean "I am not the administrator"? Your user does not have to be, but you need to have admin privileges on your local system to do any serious development.)
—SA
lezard618 20-Nov-13 1:40am    
When the program restart, it has system permissions or normal-user permissions.
Ron Beyer 20-Nov-13 9:17am    
I suppose the question is why do you need admin privileges? CreateProcessAsUser isn't going to create a process as administrator under the interactive desktop by default, and without posting your code, its impossible to tell if you are using it right. You should be using CreateProcessWithLogonW instead for creating processes in the desktop.
Sergey Alexandrovich Kryukov 20-Nov-13 11:26am    
That would be my question, too. I don't think CreateProcessAsUser should be used at all. I advised to create a process from "Startup" directory link or from "Run" registry entry. In these cases, the process will be created automatically under the account of the user who just logged in. By that moment, the service process should already be up and running (if "auto" start mode is used, of course). So, the UI process can start trying to connect to the service immediately.

Other scenarios are also possible. In principle, the UI process can itself listen (on a separate thread, for sure), and then the Server process can connect to it. It would eliminate the need for "auto" start mode. And, finally, both service and UI process can have separate threads listening to each other, with some universal bootstrap scenario. It all depends on the requirements on presentation and control features to be delivered.

In all cases, I would not advise to start any process from the service. The two processes should start independently (their lifetime would never match anyway; this is the most important argument), and, on some events, they should try to "find each other" using IPC. That's the main idea.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900