Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I've Tried The Below Code to Open The "explorer.exe"
But When Its Execute My Computer Windows Shows Up which Resembles The Key Press: Start+E.
and I Can't Find ANy TaskBar.Its Still Hidden.
I Do Want To Open The Explorer Process In Such A Way That,
It Should Not Open Up Any Window,But Explorer should Be There In The Process.

The Code I Used To End The Explorer:


VB
Sub KillExplorer()
       Dim taskKill As ProcessStartInfo = New ProcessStartInfo("taskkill", "/F /IM explorer.exe")
       taskKill.WindowStyle = ProcessWindowStyle.Hidden
       Dim Process As Process = New Process()
       Process.StartInfo = taskKill
       Process.Start()
       Process.WaitForExit()
   End Sub



The Code I Used To ReStart Explorer

VB
Sub RestartExplorer()
      System.Diagnostics.Process.Start("explorer.exe")
  End Sub



Please Help

Thanks In Advance
Posted
Comments
[no name] 11-May-14 7:54am    
Windows probably can't find "explorer.exe" try supplying the path to it.
Jeniz Zeenu 11-May-14 8:17am    
Still Same
CHill60 11-May-14 8:52am    
I't not clear what you are trying to achieve. Windows+"E" will start Explorer. Your code in RestartExplorer will start Explorer. What is the relevance of the Taskbar being hidden?
Jeniz Zeenu 11-May-14 9:09am    
I Used the first code in order to hide the task bar and stop the user from using start menu.but when i tried to re enable it with the second code, it didn't worked + the my computer folder opened up.nothing else happened.i wan't to fix it.
CHill60 11-May-14 9:18am    
Killing explorer is probably not the best way to hide the task bar! I can show you a better way if you like ...

1 solution

Well, you can hide both the Taskbar and the Start Orb with the code below (Note this has been adapted from this CodeProject article A Simplified Solution for Hiding the Taskbar and Start Orb in Vista and Windows 7[^]
VB
Imports System.Runtime.InteropServices
Public Class Form1
    <DllImport("user32.dll")> _
    Private Shared Function FindWindow(ByVal className As String, ByVal windowText As String) As Integer
    End Function
    <DllImport("user32.dll")> _
    Private Shared Function SetWindowPos(ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
    End Function
    <DllImport("user32.dll")> _
    Private Shared Function ShowWindow(ByVal hwnd As Integer, ByVal command As Integer) As Integer
    End Function
    <DllImport("user32.dll")> _
    Private Shared Function IsWindowVisible(ByVal hWnd As IntPtr) As Boolean
    End Function
    Private Const SW_HIDE As Integer = 0
    Private Const SW_SHOW As Integer = 1
    Private Const SW_TOGGLE As Integer = -1
    ''' <summary>
    ''' Shows or Hides both the Taskbar and Start Orb
    ''' </summary>
    ''' <param name="ShowHide">Set to SW_HIDE (0) to Hide
    ''' Set to SW_SHOW (1) to Show
    ''' Set to SW_TOGGLE (-1) to determine what to do first </param>
    ''' <returns>True if no errors otherwise false</returns>
    Private Function TaskBarAndStartShowHide(ByVal ShowHide As Integer) As Boolean
        Dim bRet As Boolean = False
        Try
            'Get the window handles that we need. Note Start Orb is no longer sub-window of task bar
            Dim TaskBarHwnd As Integer = FindWindow("Shell_traywnd", "")
            Dim StartOrbHwnd As Integer = FindWindow("Button", "Start")

            'Determine whether we are hiding or showing the items
            Dim action As Integer = ShowHide
            If ShowHide = SW_TOGGLE Then action = IIf(IsWindowVisible(TaskBarHwnd), SW_HIDE, SW_SHOW)

            'Do the deed
            If TaskBarHwnd <> 0 Then
                ShowWindow(TaskBarHwnd, action)
                If StartOrbHwnd <> IntPtr.Zero Then
                    ShowWindow(StartOrbHwnd, action)
                End If
            End If
            bRet = True

        Catch ex As Exception
            bRet = False 'bret is actually already false
        End Try

        Return bRet

    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TaskBarAndStartShowHide(SW_TOGGLE)
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        TaskBarAndStartShowHide(SW_SHOW)    'Don't leave without re-enabling the Start Menu!
    End Sub
End Class


This will just hide the Start Menu "Orb" and the Taskbar (including the system tray).

However, your user could still hit the Windows key to bring up the Start Menu, or use Alt-Tab to navigate to another program.

I found this code to disable the windows key on DaniWeb[^] reproduced below
'Event Info structure
Public Structure KBDLLHOOKSTRUCT
    Public vkCode As Integer
    Public scanCode As Integer
    Public flags As Integer
    Public time As Integer
    Public dwExtraInfo As Integer
End Structure
'Event types
Private Const WM_KEYUP As Integer = &H101
Private Const WM_KEYDOWN As Short = &H100S
Private Const WM_SYSKEYDOWN As Integer = &H104
Private Const WM_SYSKEYUP As Integer = &H105

'Keyboard hook related functions
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As KBDLLHOOKSTRUCT) As Integer
Private Delegate Function KeyboardHookDelegate(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
Private KeyboardHandle As IntPtr = 0 'Handle of the hook
Private callback As KeyboardHookDelegate = Nothing 'Delegate for the hook
Private Function Hooked()
    Return KeyboardHandle <> 0 'If KeyboardHandle = 0 it means that it isn't hooked so return false, otherwise return true
End Function
Public Sub HookKeyboard()
    callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
    KeyboardHandle = SetWindowsHookEx(13, callback, Process.GetCurrentProcess.MainModule.BaseAddress, 0)
End Sub
Public Sub UnhookKeyboard()
    If (Hooked()) Then
        If UnhookWindowsHookEx(KeyboardHandle) <> 0 Then
            KeyboardHandle = 0 'We have unhooked successfully
        End If
    End If
End Sub
Public Function KeyboardCallback(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
    'Variable to hold the text describing the key pressed
    Dim Key = lParam.vkCode
    'If event is KEYDOWN
    If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then
        'If we can block events
        If Code >= 0 Then
            If Key = 91 Or Key = 92 Then
                Return (1) 'Block event
            End If
        End If
    End If
End Function


You'll need to add HookKeyboard() and UnhookKeyboard() into the TaskBarAndStartShowHide function and don't forget to put UnhookKeyboard() into the FormClosing event before you leave!
 
Share this answer
 
Comments
[no name] 11-May-14 11:08am    
There was a time where deterministic destructors helped to solve "don't forget...". I'm missing them ;)
CHill60 11-May-14 11:10am    
There's a song in there somewhere ... "Those were the days my friend ...." :)
[no name] 11-May-14 11:13am    
Thank you, ok I will send a youtube link to MS ;)
...and yes +5
Gunawan.Jinnu 27-Jan-18 20:39pm    
Wonderfull solution :)

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