Solved

Shelled Process with NO Window Display Using This Code

Posted on 1998-10-01
6
255 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

760 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

21 Experts available now in Live!

Get 1:1 Help Now