Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have made a windows service in .Net 4.5. I want to check if the explorer.exe process is started or not on the machine through my service and if not, then start the process.

i have heard about the difference between sessions that win service runs in session 0 and all other processes runs in session 1 of windows. may that's why i am unable to start the explorer.exe from my service.

I have tried till now :

method : 1
VB
<pre lang="vb">Dim pro As New ProcessStartInfo("C:\Windows\explorer.exe")
        pro.UseShellExecute = True
        Process.Start(pro)


method : 2
VB
Shell("C:\Windows\explorer.exe", AppWinStyle.MaximizedFocus)


method : 3
VB
Process.Start("C:\Windows\explorer.exe")


but couldn't apply any of them successfully.. please help me out..
Posted
Comments
[no name] 28-Mar-13 12:47pm    
I don't really have an answer to this but this does not make any sense to me. I would think that if explorer was not already running, then neither is your service. Can you maybe explain a scenario where you would need to start explorer since it should already be running anyway.
vivek.khatri 29-Mar-13 1:13am    
actually i have made a metro style app that will authenticate the user after he has logged into windows. i have managed somehow to put my metro app in startup using task scheduler and a script.

the windows service will continuously check for a value in my database (.xml file) i.e. is the user authenticated or not.

if the user is authenticated, then check for explorer is started or not, if NOT STARTED THEN START IT.

if the user is NOT authenticated, then again check for explorer is started or not, if YES THEN KILL EXPLORER.EXE.

the value in my database (.xml file) will be changed only after the user authentication through my metro app.

Hope u got it my concept, if any query, just ask me..
Sergey Alexandrovich Kryukov 28-Mar-13 13:22pm    
Why doing all that? All solutions make no sense because nothing can guarantee that Explorer.EXE is located there. There are no situations when hard-coded path names can be useful.
—SA

You can't do this. If your code worked at all, Explorer would be running in Session 0, completely invisible to the user logged in that the desktop. Actually, IIRC, Explorer won't even launch in Session 0.

As of Windows Vista, Services can no longer interact with the users session. This is because of the security risks involved.

You cannot do what you want to do.

Besides, there's really no reason to do this at all. If Explorer is killed off, the system will restart it automatically. If, however, Explorer fails to start, this means the system is in such a screwed up state that it needs to be restarted anyway.
 
Share this answer
 
Comments
vivek.khatri 29-Mar-13 1:19am    
let me explain my concept which i want to achieve.

actually i have made a metro style app that will authenticate the user after he has logged into windows. i have managed somehow to put my metro app in startup using task scheduler and a script.

the windows service will continuously check for a value in my database (.xml file) i.e. is the user authenticated or not.

if the user is authenticated, then check for explorer is started or not, if NOT STARTED THEN START IT.

if the user is NOT authenticated, then again check for explorer is started or not, if YES THEN KILL EXPLORER.EXE.

the value in my database (.xml file) will be changed only after the user authentication through my metro app.

i hope now u can help me out.

Can u make me a VB.Net snippet that will derive the user's ID and token from session 1 and then i can call the explorer.exe by providing it the user's session details.

Sorry for my poor english as its not my first language..
Dave Kreskowiak 29-Mar-13 9:40am    
You're, apparently, not listening. YOU CANNOT DO THIS! You're entire concept is FATALLY FLAWED. You can NOT kill Explorer.exe with it automatically restarting itself. You can NOT launch a process from one session in another session, reguardless if you have the logged on users security token.

This can NOT be fixed!
What error is returned when your code fails to start explorer?

And what version of Windows are you working on? Session 0 Isolation in Windows Vista and beyond may affect your approach...
 
Share this answer
 
Comments
vivek.khatri 29-Mar-13 1:05am    
Actually my windows service will work with my metro application simultaneously. Therefore, the service will be run only in windows 8.

No error occurs while starting the explorer, still it doesn't start.. sorry for my poor english.

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