Visual Basic.NET - Shell para windows 7 de 64 Bits

 
Vista:

Shell para windows 7 de 64 Bits

Publicado por HAF (178 intervenciones) el 25/10/2012 10:59:18
Si ha tenido problemas para ejecutar shell en windows 7 de 64 bits aqui os dejo una clase (la he probado perfectamente en WPF)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Threading
Public Class Ejecuta32
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function Wow64DisableWow64FsRedirection(ByRef ptr As IntPtr) As Boolean
    End Function
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Public Shared Function Wow64RevertWow64FsRedirection(ptr As IntPtr) As Boolean
    End Function
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(hWnd As IntPtr, Msg As UInt32, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function
    Private Const WM_SYSCOMMAND As UInt32 = &H112
    Private Const SC_RESTORE As UInt32 = &HF120
    'Private Const OnScreenKeyboardExe As String = "osk.exe"
    <STAThread> _
    Private Shared Sub Main(args As String())
        Dim p As Process() = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Funcion_a_ejecutar1))
        If p.Length = 0 Then
            ' we must start osk from an MTA thread
            If Thread.CurrentThread.GetApartmentState() = ApartmentState.STA Then
                Dim start As New ThreadStart(AddressOf StartOsk)
                Dim thread__1 As New Thread(start)
                thread__1.SetApartmentState(ApartmentState.MTA)
                thread__1.Start()
                thread__1.Join()
            Else
                StartOsk()
            End If
        Else
                   SendMessage(p(0).MainWindowHandle, WM_SYSCOMMAND, New IntPtr(SC_RESTORE), New IntPtr(0))
        End If
    End Sub
    Public Shared Sub StartOsk()
        Dim ptr As New IntPtr()
        Dim sucessfullyDisabledWow64Redirect As Boolean = False
        ' Disable x64 directory virtualization if we're on x64,
        ' otherwise keyboard launch will fail.
        If System.Environment.Is64BitOperatingSystem Then
            sucessfullyDisabledWow64Redirect = Wow64DisableWow64FsRedirection(ptr)
        End If
        Dim psi As New ProcessStartInfo()
        psi.FileName = Funcion_a_ejecutar1
              psi.UseShellExecute = True
        Try
            Process.Start(psi)
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
          If System.Environment.Is64BitOperatingSystem Then
            If sucessfullyDisabledWow64Redirect Then
                Wow64RevertWow64FsRedirection(ptr)
            End If
        End If
    End Sub
 
    Private Shared Funcion_a_ejecutar1 As String
    Public Shared Property Funcion_a_ejecutar As String
        Get
            Return Funcion_a_ejecutar1
        End Get
        Set(ByVal Value As String)
            Funcion_a_ejecutar1 = Value
        End Set
    End Property
 
End Class


Y para Llamarlo:

1
2
Ejecuta32.Funcion_a_ejecutar = "Osk.Exe" ' para ejecutar teclado virtual
        Ejecuta32.StartOsk()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder