keep command prompt window from displaying vbhide

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
CanonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dany BalianCTOCommented:
0
Dany BalianCTOCommented:
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

0
CanonAuthor 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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dany BalianCTOCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CanonAuthor 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
0
Dany BalianCTOCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.