Solved

Shelled Process with NO Window Display Using This Code

Posted on 1998-10-01
6
262 Views
Last Modified: 2010-04-30
'Question: I need this to run with out any window activity.
'Just want to get back the error codes that a program
'returns when completed.
'Just paste this into a form and change the
'ExecCmd("\norman\win95\nvcpre.exe a: /Q") to anything
'that needs no user input and will return error codes to 'read.

      Private 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
      
      Private Type PROCESS_INFORMATION
         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long
      End Type
      
      Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
         hHandle As Long, ByVal dwMilliseconds As Long) As Long
         
      Private 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
      
      Private Declare Function CloseHandle Lib "kernel32" _
         (ByVal hObject As Long) As Long
      
      Private Declare Function GetExitCodeProcess Lib "kernel32" _
         (ByVal hProcess As Long, lpExitCode As Long) As Long
      Private Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const INFINITE = -1&
      Public Function ExecCmd(cmdline$)
      Dim proc As PROCESS_INFORMATION
      Dim start As STARTUPINFO
         ' Initialize the STARTUPINFO structure:
         start.cb = Len(start)
         ' Start the shelled application:
         Ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
         ' Wait for the shelled application to finish:
         Ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         Call GetExitCodeProcess(proc.hProcess, Ret&)
         Call CloseHandle(proc.hProcess)
         ExecCmd = Ret&
      End Function
      Sub Form_Load()
        Dim retval As Long
'Run Virus Application NO USER INPUT OR INTERACTION
'DOS Error Code Return 0 = NO VIRUS 1 = VIRUS
         'Use any program that returns a error code
         retval = ExecCmd("\norman\win95\nvcpre.exe a: /Q")
         MsgBox "Process Finished, Exit Code " & retval
      End Sub  
 
0
Comment
Question by:BuzzLightYear
  • 3
  • 2
6 Comments
 

Author Comment

by:BuzzLightYear
ID: 1437729
Using VB5
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1437730
Set the nvcpre.exe program properties to "Run Minimized" and "Close on Exit"...

0
 

Author Comment

by:BuzzLightYear
ID: 1437731
Tried that been there NO GO
When Example nvcpre is run in a DOS window at the command prompt there is no screen activity. You will just get back the prompt.
Example:
C:\>nvcpre <Enter>
C:\>
You would have to call nvcpre from a batch file to get the error codes and create echo calls for screen activity.
My Need is to Make sure that the application I call from VB5 controls the screen not the application.
With this code it's not the application that is controlling the window but how STARTUPINFO is setup, I think because if I knew I won't be asking the question.

Good Try Mark
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 2

Accepted Solution

by:
dabellei earned 180 total points
ID: 1437732
Start.wShowWindow = SW_HIDE
Start.dwFlags = STARTF_USESHOWWINDOW

add those at the begining of your code before calling createprocess  your windows wont show up on the screen.


0
 
LVL 12

Expert Comment

by:mark2150
ID: 1437733
????

I don't understand?

I thought you wanted the DOS child to run invisibly when fired from windows...

Then you say "Make sure that the application I call from VB5 controls the screen not the
application.". I'm *CONFUSED*. If you *WANT* the child app to be visible set the properties to "RUN MAXIMIZED".

Running your program in a DOS window is *NOT* a fair test of how it will run when it is spawned as a child from VB5.

Please clarify...

M
0
 

Author Comment

by:BuzzLightYear
ID: 1437734
dabellei
You read my question and understood the answer. Thank You
I had all ready seen the answer from you when you tried to answer someone else. about batch files.



0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question