Auto Restart a Custom Shell on termination

Y

YaronM

Hello,

I'm testing my new custom shell on XPe.
I've tried using the AutoRestartShell = 1 registry value to force windows to
reload my custom shell in case of an unexpected termination. unfortunately,
it doesn't work.

I thought about creating a new system-service application that will monitor
the custom-shell, but I don't know how to accomplish that programmatically.

what techniques do you use to get your shell to auto restart?

thanks in advance,

YaronM
 
Y

YaronM

thanks Solobodan. I saw the setting you mention in the minlogon component.
I currently use the "Windows Logon (Standard)" component and it doesn't have
it.
I'm not sure if I can add both milogon and the "Windows Logon (Standard)"
and which one will take effect.

basically, what I am trying to achive is to have the Explorer as the default
Shell and my Custom-Shell as an alternative shell that I will manually
configure for a specific user. and I need both Explorer and my Custom-Shell
to be AutoRestarted when they accidently crash.

thanks,

YaronM
 
S

Slobodan Brcin \(eMVP\)

Hi Yaron,

Flag that you mentioned should do the job. It does in XPP, there might be some other problem involved here.

Do you have a problem with your explorer shell, or only with your custom shell?

What approach do you use to accomplish autorestart? Sean's or your own?
http://msdn.microsoft.com/library/d.../html/tchDifferentShellsForDifferentUsers.asp

Minlogon and winlogon can't be mixed sine they bring different files with same name.

Regards,
Slobodan
 
K

KM

Yaron,

Tha Config flag is Minlogon specific.
With Winlogon you should use AutoRestartShell dword flag.

Minlogon and WInlogon can't be mixed as they esensially provide similar functions (with a bit different approach) and have the same
name binaries.

How do you start your own custom shell application?

KM
 
Y

YaronM

Hi Slobodan and KM,

I start my custom shell as described in
http://msdn.microsoft.com/library/d.../html/tchDifferentShellsForDifferentUsers.asp
the default shell is Explorer.exe and is used for the local administrator.
the Custom-Shell is user specific and is used for a limited-user account.
I tried using the AutoRestartShell Dword but it only affect the Explorer..
I'm thinking maybe to create somekind of a KeepAlive service that will
monitor the task list and will re-launch the shell if it fails..
I understood that I can't mix Minlogon and Winlogon but I still need this
functionality.

any ideas would be great.

thanks,

YaronM
 
S

Slobodan Brcin \(eMVP\)

Hi Yaron,

I'm still wondering why this functionality do not work for your shell also.
Personally I would prefer to solve this problem rather than to write application for this purpose. Especially since functionality is
already there.

Problem might be with userinit.exe program that use hardcoded explorer.exe file name for some purposes. Maybe (just maybe) if your
application was called explorer.exe autorestart would work for you.

In mean time you can use similar approach that I use on minlogon images.
Your first program that is started should launch "your shell" and stay active in background.
Now when your shell is closed you can respawn it again. Also you can use this application to control/implement software and hardware
WDT features if you need them.

Regards,
Slobodan
 
K

KM

Slobodan,

Right guess. The userinit.exe does use hardcoded explorer.exe (more presicely - %SystemRoot%\explorer.exe). Easy to find out with an
Unicode binary search.

When I deal with different shells for Windows OSes I also prefer writing my own agent app that will take care of launching whatever
I need to depending on user rights. Just more control from my own code :)


Yaron,

Anyway, there is possible another trick (on NTFS only, though):
- have explorer.exe as default shell for any user. AutoRestartShell=1
- after build, rename the explorer.exe to something like MSexplorer.exe
- rename your custom shell app to explorer.exe
- have a peice of code in your custom shell app to launch explorer.exe (e.g., CreateProcess). If MSexplorer.exe launched
properly, do nothing then.
- at runtime lock down MSexplorer.exe access permission (NTFS security) to Admin account only. (or automate this with cacls.exe
during FBA).

I have never tried this but it may work just fine.
Only problems we can expect from some system components that have explorer.exe hardcoded and rely on some MS explorer.exe
functionality much.


Also, regarding the scripting you posted the link to... You are probably aware that most of the scripts there are based on WMI. WMI
component stack is pretty heavy, especially for a Minlogon image. Also, from performance point of view, a monitoring script is way
too worse than you own app (even VB based, but C++ is definitely better). Also,

Regards,
Konstantin
 
Y

YaronM

Hi KM,

I think I will take your approach and use a VB launcher application plus the
explorer renaming.
I will change the NTFS ACL of the MS-explorer to SYSTEM and local Admin,
that will solve the system components you meantioned.
I will post some info on my progress in the NG when I will succeed on doing
that.

many thanks for all your help.

YaronM
 
Y

YaronM

Hi All,

I've create a small launcher tool using VB6 that receive an executable name
and keeps it running in a loop.
such a tool can be used for re-launching a custom shell without relying on
the Windows AutoRestartShell mechanism that works mostly on Explorer (when
using Winlogon).

I design the main form to show a syntax help and example of using the tool.
that way, when the tool is ran w/o any parameter, the form will appear.

I hope it will help anyone of you out-there (many thanks to Slobodan and
Konstantin for their great help).

Cheers,

YaronM

here's the code:
================================================
Private param As String
Option Explicit

Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Declare Function GetExitCodeProcess Lib "Kernel32" _
(ByVal hProcess As Long, _
lpExitCode As Long) As Long

Private Declare Function OpenProcess Lib "Kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Private Declare Sub Sleep Lib "Kernel32" _
(ByVal dwMilliseconds As Long)
'a shell subroutine that will re-launch a program if it is down
Public Sub Relauncher()
Dim llProcess As Long
Dim llReturn As Long

llProcess = OpenProcess(PROCESS_QUERY_INFORMATION, _
False, Shell(param, 1))

Do
GetExitCodeProcess llProcess, llReturn
Sleep 50
DoEvents
Loop While llReturn = STILL_ACTIVE
Relauncher
End Sub

Private Sub Form_Click()
End
End Sub

Private Sub Form_Load()
'read command line parameter. Example of cmdline: Launcher
c:\windows\notepad.exe
param = Trim(LCase(Command$))
'if no parameters then show help
If param = "" Then
Main.Visible = True
Main.Show
Else
'else run application by loop
Main.Hide
Main.Visible = False
Relauncher
End If
End Sub
===================================end of code=========================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top