keep command prompt window from displaying vbhide

Canon
Canon used Ask the Experts™
on
Hi All,

   I have the following code that i wish could run without the command prompt screen flashing. Is there a way to keep the cmd.exe screen from opening up on my monitor (hidden or minimized maybe)?

the code:

Private Sub Command1_Click()
    On Error Resume Next
    Dim AppToRun As String
    Dim ParamForApp As String
    Dim CmdLine As String
       
    '//set Application to Run
    AppToRun = "CMD.exe"
       
    '//set Command Line Parameters
    '//The "/C" Tells Windows to Run The Command then Terminate
    '//The Command Line (CMD.exe)
    ParamForApp = " /C ren apps apps222}"   '//Make new Directory Called 'apps222'
       
    '//Build Command string
    CmdLine = AppToRun & ParamForApp
       
    '//Shell App And Wait for It to Finish
    ExecCmd CmdLine
End Sub


the function:

Public Sub ExecCmd(CmdLine As String)
    On Error Resume Next
    Dim Proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Dim ReturnValue As Integer
       
    '//Initialize The STARTUPINFO Structure
    start.cb = Len(start)
       
    '//Start The Shelled Application
    ReturnValue = CreateProcessA(0&, CmdLine, 0&, 0&, 1&, _
       NORMAL_PRIORITY_CLASS, 0&, 0&, start, Proc)
       
    '//Wait for The Shelled Application to Finish
    Do
       ReturnValue = WaitForSingleObject(Proc.hProcess, 0)
       DoEvents
    Loop Until ReturnValue <> 258
       
    '//Close Handle to Shelled Application
    ReturnValue = CloseHandle(Proc.hProcess)
       
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
or just add the following 2 lines after the start.cb=len(Start)
start.dwFlags = STARTF_USESHOWWINDOW
start.wShowWindow = SW_HIDE

your modified procedure can be found below

hope this helps..

cheers,

dan
Public Sub ExecCmd(CmdLine As String)
    On Error Resume Next
    Dim Proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Dim ReturnValue As Integer
       
    '//Initialize The STARTUPINFO Structure
    start.cb = Len(start)
    start.dwFlags = STARTF_USESHOWWINDOW
    start.wShowWindow = SW_HIDE
 
    '//Start The Shelled Application
    ReturnValue = CreateProcessA(0&, CmdLine, 0&, 0&, 1&, _
       NORMAL_PRIORITY_CLASS, 0&, 0&, start, Proc)
       
    '//Wait for The Shelled Application to Finish
    Do
       ReturnValue = WaitForSingleObject(Proc.hProcess, 0)
       DoEvents
    Loop Until ReturnValue <> 258
       
    '//Close Handle to Shelled Application
    ReturnValue = CloseHandle(Proc.hProcess)
End Sub

Open in new window

Author

Commented:
Hi MrDany - I tried your modification and am still getting the "flash" from the command prompt screen. I got the flash prior to this as well. Is this normal to have the screen briefly flash or is this due to the quick rename that it is performing?

I was hoping that the screen would not pop-up is all!

Let me know please?

Canon
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
i have no flickering whatsoever...
it works perfectly on my pc

download this file... it's a full vbp project with what you're trying to achieve..
https://filedb.experts-exchange.com/incoming/ee-stuff/7356-ee.zip

btw, this is a site where u can upload files for experts-exchanges, u can login using the same experts exchange username and password..

let me know if this works..

cheers,

dan

Author

Commented:
Hello MrDany - the download link worked perfectly (didn't know that existed) and the example you allowed me to download worked fine. Still don't know how my code kept flashing but yours worked perfectly!

I submitted another question if you are interested in taking a look see. It involves allowing a user to enter in a folder name for renaming as opposed to being hard coded...

Thanks Again

Canon

Commented:
glad i could help.. i'm sure you're working on a full project... just compare your code with mine.. to see what u missed out.. and good luck on your project..

cheers,

Dan

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial