Jump to content

[Help] Restart Explorer from batch file...? (x64)


alfreire
 Share

Recommended Posts

Hi... I tried restart Explorer from batch file with this command:

taskkill /F /IM explorer.exestart explorer.exe

Explorer close well, but start only file explorer, not desktop... In task manager there is a explorer restart option, is there any command to do that...?

Regards... ;-)

 

p.d.: in Win 7 x64 works...

p.d.2: Execute those commands from 7z-sfx....

Edited by alfreire
Link to comment
Share on other sites

  • 7 months later...

 

Explorer close well, but start only file explorer, not desktop....

 

I were in the same problem of you and I've developed time ago a mini-tool in .NET (VB) to solve that issue.

You can compile this Class into an exe and just run the compiled exe, the entire desktop is shown not only a explorer window like happened using CMD.

But my program is not for restart explorer, it don't kills explorer, it just start it, so if you want to kill explorer then you need to write that isntruction (in Batch for example using TaskKill command like you was using in your example).

PS: If you want the program compiled then here is: http://www.mediafire.com/download/olj659v29ao8gdv/InitializeExplorer.exe

The source is just a CLI app with a Module containning these lines:

' By Elektro

#Region " Imports "

Imports System.IO

Imports System.Runtime.InteropServices

Imports InitializeExplorer.NativeMethods

#End Region

'''

''' Initializes a new instance of Explorer process.

'''

Module InitializeExplorer

#Region " P/Invoke "

'''

''' Class NativeMethods.

'''

Friend Class NativeMethods

'''

''' 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.

'''

'''

''' 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.

'''

'''

''' The window name (the window's title).

''' If this parameter is NULL, all window names match.

''' IntPtr.

Public Shared Function FindWindowByClass(

ByVal lpClassName As String,

ByVal zero As IntPtr

) As IntPtr

End Function

End Class

#End Region

#Region " ReadOnly Strings "

'''

''' Indicates the directory where the Explorer process is located.

'''

Private ReadOnly ExplorerDirectory As String =

Environment.GetFolderPath(Environment.SpecialFolder.Windows)

'''

''' Indicates the filename of the process.

'''

Private ReadOnly ExplorerFilename As String = "Explorer.exe"

'''

''' Indicates the desk Taskbar Class-name.

'''

Private ReadOnly TaskBarClassName As String = "Shell_TrayWnd"

#End Region

#Region " Process "

'''

''' The explorer process.

'''

Dim Explorer As New Process With

{

.StartInfo = New ProcessStartInfo With

{

.FileName = Path.Combine(ExplorerDirectory, ExplorerFilename),

.WorkingDirectory = My.Application.Info.DirectoryPath,

.UseShellExecute = True,

.CreateNoWindow = True

}

}

#End Region

#Region " Main "

'''

''' Defines the entry point of the application.

'''

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...