AW: Das funktioniert.. cmd.exe 64Bit wird gestartet
21.08.2017 15:08:36
mumpel
Eine kleine Erweiterung von mir. Mit Unterscheidung zwischen 32-bit und 64-bit. Und da bei "Shell" das Fenster nicht in den Vordergrund rückt arbeite ich mit ShellExecute.
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nshowcmd As Long) As Long
Public Declare PtrSafe Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" _
(ByVal Enable As Boolean) As Boolean
Public Const SW_HIDE = 0 'Alternative: vbHide, Fenster versteckt öffnen
Public Const SW_MAXIMIZE = 3 'Alternative: vbMaximizedFocus, Fenster maximiert öffnen
Public Const SW_MINIMIZE = 6 'Alternative: vbMinimizedNoFocus, Fenster minimiert öffnen
Public Const SW_RESTORE = 9
Public Const SW_SHOW = 5
Public Const SW_SHOWDEFAULT = 10
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWMINIMIZED = 2 'Alternative: vbMinimizedFocus
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_SHOWNOACTIVATE = 4 'Alternative: vbNormalNoFocus
Public Const SW_SHOWNORMAL = 1 'Alternative: vbNormalFocus
Public Sub RunCMD64()
Dim objWMI As Object
Dim objWMIe As Object
Dim obj As Object
Dim sql As String
Dim strSystemTyp As String
Dim strComputer As String
Dim varSystemTyp As Variant
strComputer = "."
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
sql = "SELECT * FROM Win32_ComputerSystem"
Set objWMIe = objWMI.ExecQuery(sql)
For Each obj In objWMIe
strSystemTyp = obj.SystemType & vbCrLf
Next obj
varSystemTyp = Split(strSystemTyp, "-")
If varSystemTyp(0) = "x64" Then
Call Wow64EnableWow64FsRedirection(False)
Call ShellExecute(0, "open", "C:\Windows\system32\cmd.exe", _
vbNullString, vbNullString, SW_SHOW)
Call Wow64EnableWow64FsRedirection(True)
Else
Call ShellExecute(0, "open", "C:\Windows\SysWOW64\cmd.exe", _
vbNullString, vbNullString, SW_SHOW)
End If
End Sub
VBA/HTML-CodeConverter, AddIn für Office 2002-2016 - in VBA geschrieben von Lukas Mosimann. Projektbetreuung:RMH Software & Media
Code erstellt und getestet in Office 16 - mit VBAHTML 12.6.0