我需要为Windows 8.1开发一个非常少的应用程序,它应该包含很少的代码行,因为唯一的目的是在第三方程序杀死explorer.exe后初始化Windows 8操作系统桌面(不是启动屏幕)
我会更好地解释一下:
我做了一个无法安装的Windows 8,它需要静默安装一个特定的程序(程序是StartIsBackPlus),安静地安装程序,作者说用参数{{1执行安装程序}}:
/silent
好吧,如果您没有注意到该程序是Windows 8.1的Windows开始 - 按钮重播,我遇到的问题是在该程序的静默安装完成后,该程序会杀死/关闭“桌面” “(explorer.exe进程),任务栏和墙壁消失,它只显示纯色背景。
要解决这个问题,我的意思是手动重新初始化桌面,就像打开任务管理器并运行一个新进程(explorer.exe)一样容易,但正如我所说,这需要完全无人值守,目前我尝试重现这一步(从CMD或从开发的.NET应用程序中默默地打开explorer.exe)它只是打开一个新的资源管理器窗口,我无法理解为什么CMD只打开一个资源管理器窗口但是如果我启动来自TaskManager的explorer.exe进程正确地重新初始化整个桌面。
然后我需要编写一个方法来重新初始化windows桌面(资源管理器和任务栏)的元素,就像在安装了这个有问题的第三方程序之后,当操作explorer.exe时TaskManager所做的那样。
...但是启动explorer.exe进程并不是那么容易,例如使用StartIsBackPlus_Setup.exe /Silent
方法,因为我已经尝试过它只打开一个新的资源管理器窗口,桌面仍然消失,然后是简单的Process.Start(“Explorer.exe”)无法在此场景中正确初始化Windows桌面。
然后......在像这样的第三方程序杀死explorer.exe之后,初始化Windows桌面的正确方法是什么?
答案 0 :(得分:2)
这是来自记忆,但试试这个:
myProcess = New Process()
myProcess.StartInfo.FileName = "C:\Windows\explorer.exe"
myProcess.StartInfo.UseShellExecute = True
myProcess.StartInfo.WorkingDirectory = Application.StartupPath
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
我不得不说,我认为这可能是作者应该了解/处理的事情。获得价值3美元的支持;)
答案 1 :(得分:0)
这是我正确重新初始化桌面的小工具的代码,也许它可以进一步改进(使用比TaskBar更好的元素检查)...我知道,但这至少在我的情况下运行良好:
#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