Wednesday, October 19, 2011

Your exe and nothing else

Most POS developers says to themselves "Oooo!  I want to hide task bar and start button so users can not switch to other exe while using my POS system.  I also want to hide this, disable this and kill this, etc."  Although in reality most developers do not really say "Oooo!" and instead use stronger words but that is the way I want to paint that expression here for fun, LOL!

So they find ways to do that and of course those are always possible via playing with registry settings or in some cases via WinAPIs.

However, why go into the trouble of doing all those things when there is simpler and easier way to achieve that?  Is it possible to make your exe the only thing running and nothing else?  Sure.

A normal windows OS uses Explorer.exe as its shell.  There are other more 3rd party shells out there in the net and I tried some before but because of familiarity with Explorer, I always go back to the default.  What is a shell?

Shell, briefly explained:

A shell is a piece of software that provides an interface for users of an operating system which provides access to the services of a kernel.   Its primary purpose is to invoke or "launch" another program; however, shells frequently have additional capabilities such as viewing the contents of directories. - wiki

So what has an OS shell go to do with what I am trying to say here?  When you use Explorer.exe as shell, then it will load the taskbar, it will load the desktop, it will load a lot of everything.... which in the end you wanted to kill or disable later anyway.  So why go into the trouble of disabling, hiding, or killing those things later..... when we can simply prevent those to be loaded in the first place?

What I am trying to say is use your exe as the OS shell so that is the only thing that will be loaded.... and nothing else.  Below is a simple snippet to do that.  I used scripting here but if you are not comfortable with it, you can use registry.prg that is shipped with VFP (HOME()+"samples\classes\registry.prg"):




**********************
* ShellSwitcher.prg
* Author: Jun Tangunan, October 19, 2011
**********************
Local oForm As Form
oForm = Createobject('ShellForm')
oForm.Show(1)
Return

Define Class ShellForm As Form
      AutoCenter = .T.
      Height = 100
      Width = 300
      Caption = "Sandstorm's Shell Switcher"
      MinButton = .F.
      MaxButton = .F.
      BorderStyle = 1

      Add Object label1 As Label With;
            top=35, Left= 10, Caption = "Please Select what Shell to use later",;
            AutoSize = .T., FontBold = .T.

      Add Object opgshell As OptionGroup With ;
            top = 50, Left = 10, ButtonCount = 2, Value = 1, ;
            AutoSize = .T., BorderStyle = 0

      Add Object cmdgo As CommandButton With;
            top=60, Left= 165, Caption = "Apply", Width = 100, Height = 30


      Procedure Init
            With Thisform.opgshell
                  .option1.Caption = "Explorer (Default)"
                  .option1.AutoSize = .T.
                  .option2.Caption = "This System"
                  .option2.AutoSize = .T.
            Endwith

      Function cmdgo.Click
            If Messagebox("Proceed?",4+32,"Switch Shell") = 6
                  Local loWSH As wscript.Shell
                  loWSH = Createobject("wscript.shell")
                  loWSH.RegWrite(;
                        "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell",;
                        Iif(Thisform.opgshell.Value=1,"Explorer.exe",;
                        "< your exe with full path >"))
                  Messagebox("A log off is necessary, click ok to log off now!",;
                        0+64,"System Restart Needed!")
                  loWSH.Run("CMD /C LOGOFF",2,.T.)
                  Thisform.Release
                  Return
            Else
                  Messagebox("Shell switching is aborted!",0+64,"Oppppssss!")
            Endif
      Endfunc

Enddefine


Here are some more things you need to know to be able to use this:
  1. You should be a member of an Administrator Account because it deals with tampering values of Local Machine in Registry 
  2. I have not killed Task Manager here so once you have tested your exe to be the Shell and would want to go back to the OS default (Explorer.exe), then you can press Ctrl+Alt+Del keys to active Task Manager, run Explorer.Exe, go to where this code snippet is, run it again and switch back to Explorer as the Shell.
 Tested under WindowsXP SP2.

You can incorporate the above codes as part of your project so that you can switch shells from within your exe without invoking the task manager. And once you are comfortable with it, then you can either proceed with disabling the task manager as well so it will really be your exe and nothing else.....


Enjoy!

2 comments:

  1. I prefer (which works without troubles in WIN7 and WinXP):

    loWSH.RegWrite(;
    "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell",;
    Iif(Thisform.opgshell.Value=1,"Explorer.exe",;
    "< your exe with full path >"))

    ReplyDelete
    Replies
    1. Hello Vilhelm-Ion. Nice to see you here! :)

      Yes, for others who may have not noticed the difference, Vilhelm-Ion is saying use Current User (HKCU) than Local Machine (HKLM). HKCU affects the current user and values there can be altered without being an administrator while HKLM affects all users; and so requires you to be an admin to allow changing values within.

      Delete