Solved

Shelled Process with NO Window Display Using This Code

Posted on 1998-10-01
6
258 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now