Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shelled Process with NO Window Display Using This Code

Posted on 1998-10-01
6
Medium Priority
?
272 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
dabellei earned 540 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

926 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