help to Convert this VBA into a vbscript
-
VBA module Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXsize As Long dwYsize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hObject As Long, ByRef dwExitCode As Long) As Boolean Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long 'Public Sub ShellAndWait(AppToRun)As Integer Function ShellAndWait(AppToRun) As Integer Dim NameOfProc As PROCESS_INFORMATION Dim NameStart As STARTUPINFO Dim rc As Long Dim dwExitCode As Long dwExitCode = -1 ShellAndWait = dwExitCode NameStart.cb = Len(NameStart) rc = CreateProcessA(0&, AppToRun, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, NameStart, NameOfProc) rc = WaitForSingleObject(NameOfProc.hProcess, INFINITE) rc = GetExitCodeProcess(NameOfProc.hProcess, dwExitCode) MsgBox "ExitCode for the process is, dwExitCode = " & dwExitCode ShellAndWait = dwExitCode rc = CloseHandle(NameOfProc.hProcess) End Function
-
VBA module Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXsize As Long dwYsize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hObject As Long, ByRef dwExitCode As Long) As Boolean Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long 'Public Sub ShellAndWait(AppToRun)As Integer Function ShellAndWait(AppToRun) As Integer Dim NameOfProc As PROCESS_INFORMATION Dim NameStart As STARTUPINFO Dim rc As Long Dim dwExitCode As Long dwExitCode = -1 ShellAndWait = dwExitCode NameStart.cb = Len(NameStart) rc = CreateProcessA(0&, AppToRun, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, NameStart, NameOfProc) rc = WaitForSingleObject(NameOfProc.hProcess, INFINITE) rc = GetExitCodeProcess(NameOfProc.hProcess, dwExitCode) MsgBox "ExitCode for the process is, dwExitCode = " & dwExitCode ShellAndWait = dwExitCode rc = CloseHandle(NameOfProc.hProcess) End Function
Try this (Need Script Host 5.5+):
Sub ShellAndWait(AppToRun)
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Shell.Exec( AppToRun )
End SubYVOTD: 15 "The eyes of the Lord are on the righteous and his ears are attentive to their cry; 16 the face of the Lord is against those who do evil, to cut off the memory of them from the earth. " - Psalm 34:15-16 (1 Peter 3:11-12) (NIV)