Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shelled Process with NO Window Display Using This Code

Posted on 1998-10-01
6
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses

721 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