Results 1 to 8 of 8

Thread: Running Windows shell

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Post

    Hi!
    I am making my own shell. And I need to exit within it and run shell as normaly (explorer). How to do it? If i type shell "explorer.exe", it runs normal application exploring disk C:.



    ------------------
    Thanks,
    John, 14 years old

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Could you please give me a little more detail on what your trying to do?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Post

    Ok.

    When Windows starts, it runs a program, located in System.ini. Standardly, there can be found "shell=explorer.exe", but you can change it to any of your/others program.

    Well, now I have Windows running my program and nothing else. But, (e.g) my application isn't perfect (or some other reason) and I need to run the standard Windows explorer with taskbar, systray etc.

    And here is the problem :-( . When I run an explorer.exe from my app, it starts normal file browser.

    I need to run normal Windows (with desktop,...) from my shell (without restarting the computer)

  4. #4
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Why don't you just change the system.ini file back to its normal state?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Post

    Because I need to RESTART the computer using this method!!!!!!!!!!!!!!! :-(

  6. #6
    Lively Member
    Join Date
    Oct 1999
    Posts
    66

    Post

    Hehehehe ) (sorry, I wouldn't know how to do it)

  7. #7
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    WELL THEN RESTART YOUR COMPUTER!!!!!!

    [This message has been edited by rino_2 (edited 01-30-2000).]

  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's some code I wrote for a Similar Question Just Yesterday.

    It basically replaces the Shell, (Explorer.exe), to show my own Login Form, then if you enter the right password, it replaces the Shell again with Explorer.exe and does a LogOff to quickly restart Windows in the Default Shell..

    In a Module, (Startup Object)..
    Code:
    '******************************************
    '* Replacement Shell Module
    '* Written by Aaron Young, Jan 29th 2000
    '******************************************
    
    Option Explicit
    
    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const EWX_FORCE = 4
    Private Const EWX_LOGOFF = 0
    Private Const EWX_REBOOT = 2
    Private Const EWX_SHUTDOWN = 1
    
    Sub Main()
        Dim lRegKey As Long
        Dim sShell As String
        Dim sWinDir As String
        Dim bLoggedin As Boolean
        
        'First make sure this App is Run when Windows Starts so we can make sure we always
        'have the chance to make this App the Shell before a Reboot.
        If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", lRegKey) = 0 Then
            Call RegSetValueEx(lRegKey, "PreShellLogin", 0&, 1, ByVal "prewin.exe", 10)
            Call RegCloseKey(lRegKey)
        End If
            
        'Get the Windows Directory
        sWinDir = Space(255)
        sWinDir = Left$(sWinDir, GetWindowsDirectory(sWinDir, 255))
        'Get the Filename of the Current Shell
        sShell = Space(255)
        sShell = Left$(sShell, GetPrivateProfileString("boot", "shell", "", sShell, 255, sWinDir & "\system.ini"))
        
        If LCase(sShell) <> "prewin.exe" Then
            'If the Shell isn't this App then Change the System.ini to make it the Shell Next time
            'the System is Rebooted.
            Call WritePrivateProfileString("boot", "shell", "prewin.exe", sWinDir & "\system.ini")
        Else
            'We're using our own Shell, so show the Login Form
            frmLogin.Show vbModal
            bLoggedin = Len(frmLogin.Tag)
            Unload frmLogin
            Set frmLogin = Nothing
            
            If bLoggedin Then
                'If the User Logged in Correctly, Change the System.ini to use the Default windows
                'Explorer Shell, then Restart Windows, (Takes a Split Second, Fake Logout)
                Call WritePrivateProfileString("boot", "shell", "explorer.exe", sWinDir & "\system.ini")
                Call ExitWindowsEx(EWX_FORCE Or EWX_LOGOFF, 0&)
            Else
                'If the User didn't Login correctly or Cancel, Shutdown Windows.
                Call ExitWindowsEx(EWX_FORCE Or EWX_SHUTDOWN, 0&)
            End If
        End If
    End Sub
    In the Form, frmLogin..
    Code:
    Private Sub cmdCancel_Click()
        Unload Me
    End Sub
    
    Private Sub cmdOK_Click()
        'Check the Password
        If txtPassword = "letmein" Then
            'If it's valid, load the Tag with a string value
            Tag = "OK"
        End If
        Unload Me
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If Visible Then
            'If Closing the Form, just Hide it to return operation to the
            'calling Sub, otherwise, if it's hidden, let it unload.
            Hide
            Cancel = True
        End If
    End Sub
    I'm sure you can adapt my code to suit your own purposes.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width