Canon
asked on
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.h Process, 0)
DoEvents
Loop Until ReturnValue <> 258
'//Close Handle to Shelled Application
ReturnValue = CloseHandle(Proc.hProcess)
End Sub
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.h
DoEvents
Loop Until ReturnValue <> 258
'//Close Handle to Shelled Application
ReturnValue = CloseHandle(Proc.hProcess)
End Sub
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
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
ASKER
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
I was hoping that the screen would not pop-up is all!
Let me know please?
Canon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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
cheers,
Dan
http://www.vb6.us/tutorials/advanced-shell