Hide Command Prompt Window when RUN Batch file

Here is the example from my ToolBox extract whatever you need/want.

I call batch files like this …

jhTools.Run('cmd.exe','/c the_batch_filename.cmd')

When the last parameter inRunAs=True, admin rights will be requested.

jhTools.Run             PROCEDURE(STRING inFilename,<STRING inParams>,<STRING inStartPath>,<BYTE inWait>,<BYTE inHide>,<BYTE inRunAs>)

procName                   EQUATE('jhTools.Run')

ShellExecInfo              GROUP
cbSize                        ULONG
fMask                         ULONG
hwnd                          ULONG
lpVerb                        LONG
lpFile                        LONG
lpParameters                  LONG
lpDirectory                   LONG
nShow                         LONG
hInstApp                      ULONG
lpIDList                      ULONG
lpClass                       LONG
hkeyClass                     ULONG
dwHotKey                      ULONG
lpUnion                       LONG
hProcess                      ULONG
                           END

szOperation                CSTRING(12)
szFilename                 CSTRING(256)
szParams                   CSTRING(256)
szPath                     CSTRING(256)
dwResult                   LONG

hWND                       LONG
dwProcessID                LONG

   CODE
      !-- Check the Filename
      IF ~inFilename 
         RETURN(FALSE)
      .
      
      IF inRunAs
         szOperation = 'runas'
      ELSE
         szOperation = 'open'
      .
      
      szFilename = CLIP(inFilename)

      !-- Wrap a file name containing a space with double quotes if necessary ..
      !--
      IF INSTRING(' ',szFilename,1,1) AND szFilename[1] ~= '"'
         szFilename = '"' & szFilename & '"'
      .

      !-- StartIn Path ..
      IF inStartPath
         szPath = CLIP(inStartPath)
      ELSE
         szPath = ''
      .
      
      szParams = CLIP(inParams)

      
      CLEAR(ShellExecInfo)
      ShellExecInfo.cbSize = SIZE(ShellExecInfo)
      ShellExecInfo.fMask = 040H  ! SEE_MASK_NOCLOSEPROCESS (0x00000040) 
      ShellExecInfo.hwnd = 0
      ShellExecInfo.lpVerb = ADDRESS(szOperation)      
      ShellExecInfo.lpFile = ADDRESS(szFilename)    
      ShellExecInfo.lpParameters = ADDRESS(szParams)   
      ShellExecInfo.lpDirectory = ADDRESS(szPath)

      IF inHide
         ShellExecInfo.nShow = 0
      ELSE
         ShellExecInfo.nShow = 10
      .
      

      !-- ShellExecuteExA ..
      !-- Returns TRUE if successful; otherwise, FALSE. Call GetLastError for extended error information.
      !-- If the function fails, it returns an error value that indicates the cause of the failure. 
      !-- The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. 
      !-- It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or it's error codes.

      IF ShellExecuteExA(ADDRESS(ShellExecInfo)) = True
                  
         !MESSAGE('ShellExecute SEInfo.hProcess = ' & SEInfo.hProcess & |
         !   '|inWait = ' & inWait,procName)
         
         IF ShellExecInfo.hProcess
            !-- Do we need to wait for this process to finish ?
            IF inWait = TRUE
               
               dwResult = WaitForSingleObject(ShellExecInfo.hProcess, -1)
            .
            
            !-- Close the Process Handle once finished
            CloseHandle(ShellExecInfo.hProcess)
            
            RETURN(TRUE)
         .

      .
      
      RETURN(False)

I use these prototypes …

ShellExecuteExA(LONG lpShellExecuteInfoA),LONG,PASCAL,NAME('ShellExecuteExA')
WaitForSingleObject(LONG hHandle,ULONG dwMilliseconds),LONG,PASCAL,NAME('WaitForSingleObject')
CloseHandle( Long hObject ),Long,Pascal,Proc,Name('CloseHandle')
2 Likes