如何从Vb.net运行explorer.exe [英] How Can I Run explorer.exe from Vb.net

查看:161
本文介绍了如何从Vb.net运行explorer.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试过下面的代码打开explorer.exe

但当它执行我的电脑时Windows显示出类似于按键的情况:开始+ E。

我无法找到任何TaskBar.Its仍然隐藏。

我想以这样的方式打开资源管理器进程,

它不应该打开任何窗口,但资源管理器应该在那里。



我用来结束资源管理器的代码:





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:


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

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







请帮助



在此先感谢




Please Help

Thanks In Advance

推荐答案

好吧,您可以使用下面的代码隐藏任务栏和开始球体(注意这已被改编)来自此CodeProject文章用于隐藏Vista和Windows 7中任务栏和启动球的简化解决方案 [ ^ ]

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[^]
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





这只会隐藏开始菜单Orb和任务栏(包括系统托盘)。



但是,你的用户仍然可以点击Windows键调出开始菜单,或者使用Alt-Tab导航到另一个程序。



我发现此代码禁用了Windows键在DaniWeb上 [ ^ ]转载如下



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





你需要将 HookKeyboard() UnhookKeyboard()添加到 TaskBarAndStartShowHide 函数,不要忘记在离开之前将UnhookKeyboard()放入 FormClosing 事件中!



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!


这篇关于如何从Vb.net运行explorer.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆