• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

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
0
Canon
Asked:
Canon
  • 4
  • 2
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now