elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  [APORTE] Reinicializar el escritorio de forma correcta en Windows 8.1 cuando...
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] Reinicializar el escritorio de forma correcta en Windows 8.1 cuando...  (Leído 1,952 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.821



Ver Perfil
[APORTE] Reinicializar el escritorio de forma correcta en Windows 8.1 cuando...
« en: 1 Febrero 2014, 01:45 am »

Reinicializar el escritorio de forma correcta en Windows 8.1 cuando un programa de terceros mata el Explorer.

Hoy me encontré en una situación algo extraña, necesitaba instalar un programa de terceros ...un reemplazamiento del botón de inicio apra Windows 8, y necesito que este proceso sea automatizado, pero al instalar este programa de forma silenciosa al terminar la instalación se mataba de forma automática el explorer.exe ...ya que el instalador así lo requiere, desaparecia el fondo, el taskbar, el explorer, quedando visible sólamente un fondo de un color solido.

La solución manual a este problema (al cual me he enfreentado muchas veces) es tan simple como abrir el administrador de tareas para ejecutar el explorer.exe, o hacerlo desde la consola de windows (CMD), pero como ya dije necesitaba automatizar la tarea así que intenté hacerlo desde la CMD, el problema es que al parecer esto no es suficiente Windows 8/8.1 (Desde la CMD).

...Por más que intenté ejecutar de forma automatizada el explorer.exe después de la instalación de este software sólamente se abria una ventana del explorer, quiero decir... los elementos del escritorio no se reinicializaban (taskbar, wallpaper, explorer...), y esa es la razón de porque he escrito esta pequeñísima mini-utilidad en VB.NET la cual me ha resuelto el problema.

Aquí tienen el source y un ejemplo de uso real (la aplicación del ejemplo es solo para Windows 8.1) si probais el ejemplo hacedlo en una VM no en vuestro PC ~> http://www.mediafire.com/download/nh8z5bkglh9se36/InitializeExplorer%20Sample.rar

El código fuente de la aplicación sólamente es esto, supongo que habrá escasas personas que tengan el mismo problema, pero bueno, que lo disfruten:

Código
  1. #Region " Imports "
  2.  
  3. Imports System.IO
  4. Imports System.Runtime.InteropServices
  5. Imports RefreshExplorer.NativeMethods
  6.  
  7. #End Region
  8.  
  9. ''' <summary>
  10. ''' Initializes a new instance of Explorer process.
  11. ''' </summary>
  12. Module RefreshExplorer
  13.  
  14. #Region " P/Invoke "
  15.  
  16.    ''' <summary>
  17.    ''' Class NativeMethods.
  18.    ''' </summary>
  19.    Friend Class NativeMethods
  20.  
  21.        ''' <summary>
  22.        ''' Retrieves a handle to the top-level window whose class name and window name match the specified strings.
  23.        ''' This function does not search child windows.
  24.        ''' This function does not perform a case-sensitive search.
  25.        ''' </summary>
  26.        ''' <param name="lpClassName">
  27.        ''' The class name or a class atom created by a previous call to the
  28.        ''' RegisterClass or RegisterClassEx function.
  29.        ''' The atom must be in the low-order word of lpClassName;
  30.        ''' the high-order word must be zero.
  31.        ''' If lpClassName points to a string, it specifies the window class name.
  32.        ''' The class name can be any name registered with RegisterClass or RegisterClassEx,
  33.        ''' or any of the predefined control-class names.
  34.        ''' If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.
  35.        ''' </param>
  36.        ''' <param name="zero">
  37.        ''' The window name (the window's title).
  38.        ''' If this parameter is NULL, all window names match.</param>
  39.        ''' <returns>IntPtr.</returns>
  40.        <DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Unicode)>
  41.        Public Shared Function FindWindowByClass(
  42.            ByVal lpClassName As String,
  43.            ByVal zero As IntPtr
  44.        ) As IntPtr
  45.        End Function
  46.  
  47.    End Class
  48.  
  49. #End Region
  50.  
  51. #Region " ReadOnly Strings "
  52.  
  53.    ''' <summary>
  54.    ''' Indicates the directory where the Explorer process is located.
  55.    ''' </summary>
  56.    Private ReadOnly ExplorerDirectory As String =
  57.        Environment.GetFolderPath(Environment.SpecialFolder.Windows)
  58.  
  59.    ''' <summary>
  60.    ''' Indicates the filename of the process.
  61.    ''' </summary>
  62.    Private ReadOnly ExplorerFilename As String = "Explorer.exe"
  63.  
  64.    ''' <summary>
  65.    ''' Indicates the desk Taskbar Class-name.
  66.    ''' </summary>
  67.    Private ReadOnly TaskBarClassName As String = "Shell_TrayWnd"
  68.  
  69. #End Region
  70.  
  71. #Region " Process "
  72.  
  73.    ''' <summary>
  74.    ''' The explorer process.
  75.    ''' </summary>
  76.    Dim Explorer As New Process With
  77.    {
  78.     .StartInfo = New ProcessStartInfo With
  79.                  {
  80.                   .FileName = Path.Combine(ExplorerDirectory, ExplorerFilename),
  81.                   .WorkingDirectory = My.Application.Info.DirectoryPath,
  82.                   .UseShellExecute = True
  83.                  }
  84.    }
  85.  
  86. #End Region
  87.  
  88. #Region " Main "
  89.  
  90.    ''' <summary>
  91.    ''' Defines the entry point of the application.
  92.    ''' </summary>
  93.    Sub Main()
  94.  
  95.        Select Case Convert.ToBoolean(CInt(FindWindowByClass(TaskBarClassName, Nothing)))
  96.  
  97.            Case False ' The Taskbar is not found.
  98.  
  99.                Try
  100.                    Explorer.Start()
  101.                    Console.WriteLine("Windows Explorer has been re-initialized successfully")
  102.                    Environment.Exit(0)
  103.  
  104.                Catch ex As Exception
  105.                    Console.WriteLine(ex.Message)
  106.                    Debug.WriteLine(ex.Message)
  107.                    Environment.Exit(1)
  108.  
  109.                End Try
  110.  
  111.            Case True ' The Taskbar is found.
  112.                Console.WriteLine("Can't proceed, Windows Explorer is currently running. Exiting...")
  113.                Environment.Exit(2)
  114.  
  115.        End Select
  116.  
  117.    End Sub
  118.  
  119. #End Region
  120.  
  121. End Module


« Última modificación: 1 Febrero 2014, 02:07 am por Eleкtro » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
¿Forma correcta de pasar información entre scripts?
PHP
Scratz 6 2,950 Último mensaje 26 Mayo 2010, 23:04 pm
por ~ Yoya ~
No consigo configurar aMule de forma correcta
Software
do-while 0 2,449 Último mensaje 31 Octubre 2010, 22:26 pm
por do-while
Instalar drivers nvidia de forma correcta en debian
GNU/Linux
ccrunch 2 1,957 Último mensaje 20 Octubre 2013, 20:33 pm
por ccrunch
Forma correcta de empezar un documento .html
Desarrollo Web
Caster 4 2,555 Último mensaje 23 Noviembre 2013, 23:52 pm
por HackID1
Cómo elegir un dispositivo PLC de forma correcta
Noticias
wolfbcn 0 1,806 Último mensaje 9 Diciembre 2013, 00:53 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines