我需要为Windows 8.1开发一个很少的应用程序,该应用程序应以很少的代码组成,因为唯一的目的是初始化Windows 8 OS Desk(不是StartScreen),在第三次之后政党计划杀死了Explorer.exe。
我会更好地解释:
我进行了Windows 8的未定安装,该安装需要静静地安装特定程序(程序为StartisBackplus),以静静地安装程序,作者说要使用参数/silent
执行安装程序:
StartIsBackPlus_Setup.exe /Silent
好吧,如果您没有注意到该程序是Windows 8.1的Windows启动按钮替换,而我遇到的问题是,在该程序的无声安装完成后,该程序杀死/关闭了" Desk"(Explorer.exe过程)和任务栏和墙壁消失,它仅显示纯色背景。
要解决这个问题,我的意思是要手动重新启动桌子,就像打开任务管理器并运行新过程(explorer.exe)一样容易,但是正如我所说的那样我尝试重现此步骤(对于exaple sil sil sil oble opend explorer.exe,从cmd或从开发的.NET应用程序中)它只是打开一个新的Explorer窗口,我不明白为什么CMD只能打开Explorer窗口,但是如果我启动了TaskManager的Explorer.exe进程正确重新定位了整个桌子。
然后,我需要编写一种方法来重新定位Windows Desk的元素(Explorer和Taskbar),就像TaskManager在Manualy Runnuly running Explorer.exe时所做的那样,在安装了有问题的第三方程序后。
。 ...但并不那么容易,例如使用Process.Start
方法启动Explorer.exe过程,因为我已经尝试过它,并且只打开了一个新的Explorer窗口,桌子保持不变,然后是简单的过程。(" Explorer.exe")在此风景中未正确初始化Windows Desk。
然后...在这样的第三方程序杀死Explorer.exe之后,将Windows Desk初始化Windows Desk的正确方法是什么?
这是来自内存的,但请尝试以下操作:
myProcess = New Process()
myProcess.StartInfo.FileName = "C:Windowsexplorer.exe"
myProcess.StartInfo.UseShellExecute = True
myProcess.StartInfo.WorkingDirectory = Application.StartupPath
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
我不得不说,我认为这可能是作者应该知道/处理的事情。获得您的$ 3的支持;)
这是我对桌面重新启动的小工具的代码至少在我的情况下,这效果很好:
#Region " Imports "
Imports System.IO
Imports System.Runtime.InteropServices
Imports RefreshExplorer.NativeMethods
#End Region
''' <summary>
''' Initializes a new instance of Explorer process.
''' </summary>
Module RefreshExplorer
#Region " P/Invoke "
''' <summary>
''' Class NativeMethods.
''' </summary>
Friend Class NativeMethods
''' <summary>
''' Retrieves a handle to the top-level window whose class name and window name match the specified strings.
''' This function does not search child windows.
''' This function does not perform a case-sensitive search.
''' </summary>
''' <param name="lpClassName">
''' The class name or a class atom created by a previous call to the
''' RegisterClass or RegisterClassEx function.
''' The atom must be in the low-order word of lpClassName;
''' the high-order word must be zero.
''' If lpClassName points to a string, it specifies the window class name.
''' The class name can be any name registered with RegisterClass or RegisterClassEx,
''' or any of the predefined control-class names.
''' If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.
''' </param>
''' <param name="zero">
''' The window name (the window's title).
''' If this parameter is NULL, all window names match.</param>
''' <returns>IntPtr.</returns>
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function FindWindowByClass(
ByVal lpClassName As String,
ByVal zero As IntPtr
) As IntPtr
End Function
End Class
#End Region
#Region " ReadOnly Strings "
''' <summary>
''' Indicates the directory where the Explorer process is located.
''' </summary>
Private ReadOnly ExplorerDirectory As String =
Environment.GetFolderPath(Environment.SpecialFolder.Windows)
''' <summary>
''' Indicates the filename of the process.
''' </summary>
Private ReadOnly ExplorerFilename As String = "Explorer.exe"
''' <summary>
''' Indicates the desk Taskbar Class-name.
''' </summary>
Private ReadOnly TaskBarClassName As String = "Shell_TrayWnd"
#End Region
#Region " Process "
''' <summary>
''' The explorer process.
''' </summary>
Dim Explorer As New Process With
{
.StartInfo = New ProcessStartInfo With
{
.FileName = Path.Combine(ExplorerDirectory, ExplorerFilename),
.WorkingDirectory = My.Application.Info.DirectoryPath,
.UseShellExecute = True
}
}
#End Region
#Region " Main "
''' <summary>
''' Defines the entry point of the application.
''' </summary>
Sub Main()
Select Case Convert.ToBoolean(CInt(FindWindowByClass(TaskBarClassName, Nothing)))
Case False ' The Taskbar is not found.
Try
Explorer.Start()
Console.WriteLine("Windows Explorer has been re-initialized successfully")
Environment.Exit(0)
Catch ex As Exception
Console.WriteLine(ex.Message)
Debug.WriteLine(ex.Message)
Environment.Exit(1)
End Try
Case True ' The Taskbar is found.
Console.WriteLine("Can't proceed, Windows Explorer is currently running. Exiting...")
Environment.Exit(2)
End Select
End Sub
#End Region
End Module