Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Running A DOS Command WITHOUT The Command Window Appearing


I want to run a DOS command from my Visual Basic program - and I can do that fine, but I want to do it without the Command Window popping up. Is there a way to do this?? because if the command window pops up it makes my app look very scruffy.


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Running A Command Line Program From VB Without Window Closing
Here is what I am trying to do:

Use the shell function (in VB) to run a simple program that I made in C++/ASM. The problem is if I run the (C++) .exe in Windows Explorer it opens and then closes right away. I need to access it from VB anyway so is there some parameter I can pass to shell to stop the Command Prompt window from closing?

I tried Shelling this in VB: cmd.exe "Full path to the C++ .exe" and all it did was bring me to the directory that the C++ .exe is in.

Here is my code:

VB Code:
Private Sub cmdRun_Click()    Dim sPath   As String        sPath = Replace$(txtPath.Text, ".cpp", ".exe", , , vbTextCompare)    Shell "cmd.exe " & """" & sPath & """", vbNormalFocus    End Sub

sPath has the proper path (I checked in debug mode) but the command window only brings me to the file that the .exe is in.

Any ideas?

Running A Command When The User Clicks The Close Button On The Window (X)
Hi I am sure this is very simple I just can't find it anywhere. How would I go about running the code "End" when the user clicks on the "X" (close button) at the top right of my VB application.

When they hit the X on my child window I need it to close the Exe. I can't do it just on unload because I have another button that unloads the window and I don't want the application to to close with that button. Thanks

Running SQL Command

The following code takes a string (SQL server command, for example SELECT 1) and attempt to excute it

Public Function runTheScript(ByVal chosenScript As String) As Boolean

Dim objError As ADODB.Error

On Error GoTo ErrorHandler

Set strResult = New ADODB.Command

strResult.Open chosenScript, cnxDatabases, adOpenForwardOnly, _

Set strResult = Nothing

runTheScript = True
Exit Function


runTheScript = False
Exit Function

End Function

The trouble is that the code doesn't work! The line

strResult.Open chosenScript, cnxDatabases, adOpenForwardOnly, _

is giving an error and causing the function to return false ever time. What am I doing wrong?! Oh and cnxDatabases is my active connection which is already established.

Need Help Running DOS Command
When I type a command in a DOS window, it works. But it doesn't work when I call it from VB.

I am trying to modify the PATH environment vriable of windows 2000.

stPath = """%PATH%;d: emp emp 123 qw"" -m"

%PATH%;d: emp emp 123 qw

DOS Command:
d:vb_worksetwinvarenvsetx.exe PATH "%PATH%;d: emp emp 123 qw" -m

C:WINNTsystem32;C:WINNT;C:WINNTSystem32Wbem;d: emp emp 123 qw

Any ideas?

Problems Running DOS Command
I'm trying to run the following lines but I keep getting an error:
sShellString = "cmd /c osql -E -S DatabaseServer -d DatabaseName -i \SQLFilePath est.sql -n"
Shell sShellString, vbNormalFocusIf I paste
"cmd /c osql -E -S DatabaseServer -d DatabaseName -i \SQLFilePath est.sql -n"
"osql -E -S DatabaseServer -d DatabaseName -i \SQLFilePath est.sql -n"
in the cmd window by itself, it runs okay, but if I try the above code in VB, it gives me the error: "'osql' is not recognized as an internal or external command, operable program or batch file."

Any help is greatly appreciated! Thanks!

Running Dos Command Line Within VB

I developed a little VB application a couple of months ago to assist me run a series of SQL scripts instead of doing it manually. The application requires the server name, database name, as well as the path for the scripts.

The following command line executes a SQL script through the command line :

isqlw -S MyServer -d pubs -U sa -P -i input_file -o output_file

My question is as follows : I have a set of 10 scripts in a ListView, how do I get the above line to execute in command prompt from within VB?

Any suggestions?

Running A Command Line.

I was wondering how to go about sending something to a Command line. I have processed a textbox and have a varible holding a Command line command.

to make it a little clearer this is the command I want to send:

cscript /nologo c:doc2pdf.vbs
ologo "pathtofile

It's a script to automate PDF conversions, I only just ran into some functions that automate sending files to the Distiller.

How do I send this varible through the Command line? Is there someway to do this with the Shell function?

Would be really handy if anyone knew.


Running A DOS Command From Inside VB
I am trying to run a DOS command inside of my VB program. Does anyone know how I could do that?
If not, does anyone know how to run a program that isn't a .exe program from inside VB?

Finally, if anyone knows of a good place to go vent my frustration about my boss who knows nothing about programming and only knows how to delagate please let me know.


Running A Command Argument
I need to figure out how I can run the command below from VB6 code.


I need to run this like it was running from the Start --> Run command.

Shell Command Not Running
I am writing following code to run shell command

strf = "c:inforep.exe c:" & Txtsecuritydomain.Text & " >> c:a.txt"
Shell strf, vbNormalFocus
Set file = fs.GetFile("c:a.txt")

but after this it gives error file not found,actually a.txt is not getting created what change i need to do in the code.
secondly i want after exe execute the command line window should get close automatically
pls anyone can help

Running VB6.exe From Command Line
Hi, I'm wanting to create a script to automatically amend the Project->References of a number of DLL projects and then compile them into new DLLs.

I have found the argument for 'MakeDLL' but can't seem to see if there is any way to amend the project references within the project without opening it up and doing it manually through the menus.


Running DOS Command From VB [Problems]
ok im trying to run FC.exe (file checker, sees if there are any differences in files)

here is my code:

[in the general declerations]
Const SYNCHRONIZE = &H100000 'contants for cmdShell

[the function itself]
Private Sub cmdShell(Command As String)

'i didnt write any of this, copied from RCRS version1

Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long

lPid = Shell(Command, vbHide) 'get Processor ID number of command shell
Debug.Print Command
If lPid <> 0 Then
lHnd = OpenProcess(SYNCHRONIZE, 0, lPid) 'Get a handle to the shelled process.
If lHnd <> 0 Then 'If successful, wait for the
lRet = WaitForSingleObject(lHnd, INFINITE) ' application to end.
CloseHandle (lHnd) 'Close the handle.
End If
'MsgBox "Just terminated.", vbInformation, "Shelled Application"
End If
End Sub

[the call to the function]
'now check out the files and pipe it to a change file
Call cmdShell("cmd /c C:winntsystem32fc.exe " & App.Path & "
ew.txt " & App.Path & "old.txt /N /W > " & App.Path & "changes.txt")

when i run the program, fc doesnt do anything, it never write the changes.txt file! I dont get any errors at all, just nothing happens. What do you suggest would be the problem?



Running A Shell Command
Does anyone know why the code

Private Sub Command1_Click()
Shell "C:>rmdir Test", vbNormalFocus
End Sub

doesn't work?

Running A Command On Mouse Over
Hey I was wondering if there is a way to run a command when the mouse is over a command button or a picture. I have a row of command buttons with pictures ontop of them and what I want to do is have it so that when the user moves the mouse over one of the command buttons it runs a code like picture1.Visible = True. Can someone tell me how to do that? Thanks in Advance!!


Running A Dos Command In A Vbscript
Hi! I'm trying to write a script that is to be used on older computers that do not have WMICore installed on them. On each machine that this script is run on, i need to take the name of that machine and write it to a text file. i have a few questions:

1) Will i be able to use FSO (File System Object) on computers that don't have WMI installed? I assume so, but i want to be sure FSO isn't part of the windows management instrumentation.

2) Since these machines don't have WMI, i'll have to get their computer names by using the dos "set" command. for example, the dos command
 Code:set / find "COMPUTERNAME=
will return the name of the computer. How do i run this command in a vbscript so that i can assign the result of the command to the variable and then write it to the text file. NOTE: that should be a vertical bar after "set" in the code, but i can't seem to type one in here, it keeps converting it to a forward slash.

also, i was thinking perhaps there would be an easier way to do this. can i append a line on to a text file simply using dos? if so, i could just write a batch file that would take care of this. i'm aware of the "edit" command in dos, but i would need something that can run silently in a batch file without requiring any user interaction.

thanks in advance for any help you can provide!

Edited by - Derek_Ween on 9/5/2003 12:25:03 PM

Send Command To Running App?
How do I etc send a command to a running application?
Say I have "cmd" open, how do I make a function from my application to send etc: "cd .." to the cmd console?

Or a running game. I've gotten it to work but not the way I wanted it. The way I managed to do it, it starts the .exe file that its suppose to send the command to, on new... so there's two running windows...

Anyone has tips or solution for this?

Dos Command In My Window
im trying to figure out how to do a dos command.. netstat.. and have the results in my textbox.. can anybody point me in the right direction?

Command Window In GUI
I have a program that I want 1 out of x (x=user opened) tabs to be able to
be the input/output for a command line window. BUT I don't want to open the
cmd.exe program in a external window...any ideas?

Command Window

I am using the command prompt in Windows to perform some tasks. So in the VB code I use the Shell command to acces the command prompt. Now I use a program that creates files depending on which directory you call the program from when you are in some directory in DOS. For example, if I'm currently in directory "C:" in my command prompt, and I write the command for that program (by for example specifying the path for it) to create new files, the files are stored in "C:" because I am there currently. How can one change the directory from VB code and then call the program?
Currently, I use this code:

ProcessID = Shell(sCommandLine)
If ProcessID Then ' PID non-zero (True) so Shell worked
hProcess = OpenProcess(SYNCHRONIZE, False, ProcessID)
Call WaitForSingleObject(hProcess, INFINITE)
Else ' PID zero (False) so Shell failed
MsgBox "Could not generate .ps files"
End If

The sCommandLine variable has the command to start the program. Can I somehow write to that variable so that I change the current directory in DOS, and then call the program? Grateful for help!

Window Run Command API
Hi, All

I've to launch an application only one time on a given PC. For this, I've built a program that explores all open windows of the system. I would like to find the searched windows by comparing the command it runs, but I can't find the right API.
Today I compare a Window Title but this is not sufficent in my case

Running Arguments On The Command Line From Vb6
I need to run the following arguments on the command line:
cd c:Program filesMicrosoft SQL Server90Shared
sac out server1.out -DE

This will export the database engine settings from SQL server to a file called server1.out

I know how to do this using a batch file and then calling it from VB using the shell command but I need to do it directly from VB instead, is this possible?

Running Program From Command Line

I've got a question.

is it possible if you run your program through the command line to give it an extra parameter with it. an example

myprogram.exe parameter

is it possible to read the parameter in a variable? so you can use it in your program. (I'm using vb 6)

I hope you know what I am trying to explain

Running DOS Instructions Using Shell Or Command$
I've been looking around for the answer to this but haven't quite found it yet

I want to execute an actual DOS instruction from the command line (in this case a cddirectory style command) - within my VB executable. Any tips on how to go about using Shell to do this? I know there is a Command$ variable in VB but I am unsure how to populate it and I have looked and tried some methods.

Thank you!


Simple Help Running Sleep Command
OK this should be easy. I have an old computer (NT 4.0 SP6 Pentium II 400MHz) with VB6.0 installed on it. I am trying to write some simple code and the add some delay I add a line "Sleep 1000". When I try to execute the program the program responds that function is not found. Now Sleep should be a fundamental function so I imagine there is something wrong with the setup.

Does anyone have any ideas? Can I just add a reference to VB commands? I don't have disks to reinstall.

Running Program From Command Line
I have a program that will need to be run from a command line. This is pretty simple, correct? All you do is type in the name of the program from the correct folder, and it will run the executable.

Tricky part (for me), the program extracts data from an excel spreadsheet and places the info into an ascii file. Is there a way for me to type in the spreadsheet name in the command line?

For example: strSpreadsheet represents the Excel Spreadsheet
Dos Command line: "Program Name" "Spreadsheet Name"

Can I set strSpreadsheet = "Spreadsheet Name" that the user types in at run time?

Any help or suggestions would be greatly appreciated.

Running A Smiple Unix Command From VB6
I have a program which downloads a file of data from Unix. However, at least some of my users forget to run a unix command on the server to convert the file to ASCII.

Does anyone know how I can get this to happen. I have seen programs that do run unix commands, but I'm pretty sure they are not VB. The command is a simple command line that moves data from a Text Area to an ascii file.

Problem Running Command In Shell

I am trying to run the following command in a shell thru VB but it seems not to be working for me:

This is the command:
C:Program FilesGNUGnuPGgpg.exe --passphrase-fd 0 -o D:henry-scriptspass.txt -d D:henry-scriptspass.gpg <

This is the simpel script i have written:
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

' open maximized and wait
WSHShell.Run "C:Program FilesGNUGnuPGgpg.exe --passphrase-fd 0 -o D:henry-scriptspass.txt -d D:henry-scriptspass.gpg <
", true

Set WSHShell = Nothing

If i try any other Executable it work but when i try to add some variables then it goes wrong.

Has anyone got any idea?

Running External Command (Closed)
Hello everybody

I`ve been fiddling with the Shell and ShellExecute API call in order to execute this command!

mysql -u username -pPassword <backup.sql bio_tech

The parameters are not being sent intact after the "<" symbol. So the mysql backup is not being restored. Can anybody give me some working code for this?

thx, in advance

George Papadopoulos

Running BAT Files With The Shell Command
I am in the unfortunate possition of having to run *.bat files from the shell command. I am looking for better ways of handling *.bat files. I am hoping that there is a way of getting a return value from a *.bat file so that I can tell when the *.bat file has completed running.

Any ideas are welcome.


Running An Executable From Within A Command Button
I am designing a form that will launch
3 setup files (e.g., setup1.exe, setup2.exe, setup3.exe) from 3 different command buttons. All of these files are to be "burned" on a cd.

Eventually, I will save this file as setup.exe and call it from autorun.inf so that it loads automatically when a person puts the cd in his/her cd player.

What code should I use?

Running Command On Remote Host?
Hi all!
I need to run a command in a dos prompt on a remote windows host. I also need to retrieve the output
from the command that i run. Can i use winsock for this, and if so, how would i go about doing that?


Running A Command On Form Exit
Whats the Proper code for running a command when the user clicks the red exit button on the top right of the Visual basic program? I want to make it so that when they exit the program it deletes the values of my registry strings. Allso is there a way to make it so that the Red Exit button doesn't show or is grayed in? Thanks in advance.


Running EXE With Command Line Argument
Hello to all

Here i am getting Error on runnig the EXE with command line argument. If I run it without command line argument it works but i need to be pass argument. It works properly with IDE with Command line argument (from property box on Make tab). but after creating exe I run it with command line argument it gives Error "Referenced Memory could not Read". i am running my application like this

MyAppl.exe 12345

12345 is command line argument.
if you have any solution pls let me know

Terminating A Command Window
Im shelling out to a command prompt to retrieve some netbios statistics ie

commandline = "nbtstat -a " & & strAsset & " c: emp.txt"
RunCommand (commandline)
Shell Environ("COMSPEC") & " /c " & strCommand, vbHide

I need to terminate this after one second regardless of its success. Implementing the timer is not a problem- its terminating the process/window. If the command was successful then it will obviously not exist after the time interval- if it is unsuccessful it will hang for a period of time- hence the reason for termination. Im using vb5 at the moment- but about to move to vb6 to implement some regEx stuff so a solution in either would be grand.

Any help much appreciated!


Help! Textbox As A DOS Command Window
Hi everybody, I need to do something that I realy don't know how to do it.

I want to control a textbox to act exactlly like the DOS command prompt windows. So the mouse don't do anything, and the UP and DOWN arrows too and cannot erase what is already written in the textbox except for the current line.

In fact, I'm doing a terminal to communicate to an embedded system via the serial port so I want a form containing only a menubar and a big textbox working like the DOS, so if you know an other way to do what I want, you can propose it too.

I need it ASAP please. Thank you guys, you help me so much.


Write Command To Dos Window

I want VB to write a command (of an edit-box for example)
in the MS-Dos Window

or to execute the command somehow else

(sorry I dont know the programm well)

thx Patrick

Command To Open Immediate Window
Hi all,

i have some code that i trigger from a form button, the code prints to the immediate window- how can i open the immediate window with a command?

or will opening the immediate window alway force the code window to open? if so is there any way to show the contents of the immdiate window in a text box?



Closing A Command Window
I really need help on closing a command window that i have created using the following code:

VB Code:
Public Function ExecCmd(cmdline$)    Dim proc As PROCESS_INFORMATION    Dim start As STARTUPINFO    Dim ret&    start.cb = Len(start)    ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)    ret& = WaitForSingleObject(proc.hProcess, INFINITE)    ret& = CloseHandle(proc.hProcess)End Function

This is the usage of it:

VB Code:
Call ExecCmd(App.Path & "
ar a " & rarName & ".rar " & "*.*")

Now the problem is that when i run the code on my XP machine it works perfectly, the window appears and compresses my files and then automatically closes itself. However, when i run it on a Win2K machine, the window appears, but does not close itself, rather i have to close it manually, which i don't want my users to have to do.

Can anyone tell me why this code doesn't perform on 2K, or if there is a way to check if the window has closed and close it if it hasn't closed?

Any help with this problem would be greatly appreciated, my boss is practically screaming for this to be finished.

Ask For Code Of New Window Command
I am creating a normal Text Editor with VB. May I know how to create New window (Code) command in the Menu to initiate a new text editor ? Thanks.

Killing A Command Window
I am executing a shell statement that opens a command window. how can I have this window close after the shell statement has been executed?

Writing To Command Window
I need help writing to the command window.

I have a program that only has a SUB MAIN(). (No user interface).

When I run the program from a dos prompt, I want to
display text messages in the current dos command window that was used to
run the program.

I can create a separate console window and write to that, but I want to
the messages to the current dos prompt window .

Any help would be greatly appreciated.


Working With A Command (DOS) Window...
I've been working on this for hours and it's driving me insane.

I need to send this text to a command window:Code:Program.exe vv "C:Temp DirFile.dat" > list.txtIf I use that code by hand in the command window it works fine.

I'm using this code to do it from VB:Code:sWinID = Shell("C:TempProgram.exe vv " & Chr(34) & "C:Temp DirFile.dat" & Chr(34) & " > " & "list.txt", vbNormalFocus)

The first part of code executes fine, but for some reason the code seems to get cut off after File.dat and the " > list.txt" part isn't included as part of the argument. Any idea's why that is?

I just noticed this old thread. I seem to be having the same problem as this person... It seems that the > character is the problem. Any logical reason for that?

Edited by - firebush on 10/7/2004 4:54:07 PM

Is There Anyway To Emmulate The Dos Command Window?
ok I'm learning java and right now the only way I know how to run one of my classes is to open a command prompt then navigate to the containing folder and then run it from there.
I was wondering is there was anyway I could use the Shell command, or something to do this then send the output to a text box?

if you need more info let me know?

Running A Macro Containg Solver Command
I "recorded" a series of solver commands and linked this macro to a button on my spreadsheet.

It works when I'm recording, but when I try to activate the macro using the button, I receive :

"Compile error: Sub or function not defined".

The code I use is :

Sub solve()
SolverOk SetCell:="$P$27", MaxMinVal:=3, ValueOf:="0", ByChange:="$C$26:$N$26"
SolverAdd CellRef:="$C$40:$N$40", Relation:=1, FormulaText:="$C$39:$N$39"
SolverAdd CellRef:="$C$40:$N$40", Relation:=3, FormulaText:="$C$38:$N$38"
End Sub

Thanks for the help

Running Commands In Command Prompt Without Showing It
I want to run few commands in command prompt, thru my vb program, without showing the command prompt. How can this be cone?

Whats The Api Command To Check A Certain Process Is Currently Running?
I was trying to make a timer procedure that checks if mirc32.exe is running else my project will automatically close.

private sub timer1.timer()
... whats the command to check if theres mirc32.exe in the process list?
if mirc32 is not in process list then
kill my project
end sub

im so clueless

Problem Running Application Using Shell Command
Hi, running application in vb made my project easy by using Shell(appPath,windowstate) command.

now, i got a list of applications in my database with its correct path, the prob is, when i try to run those application one-by-one, they all run except for one application which is the most important applications for my client pc (because it is the most favorite application of my costumers), but the program runs abnormally when i run it using shell command, i checked the application's path, but it is correct, when i try to run that application w/o my prog, it ran normally, even its shortcut on my desktop, normal!

What probablly the problem is??

I think it's not with my code, cuz the other application runs normaly, except with that application. BDY, the application i am talkin' bout is a game application, do you know MU Online? by Mobius? it is an online game like Ragnarok!!! also ragnarok runs normally in my project, except really MU...

But when i compiled my program and create the exe file, i try to paste that exe program to the folder where MU resides, then i run my prog, then click the button, THEN iT RAN NORMALLY!?!?!... i check out the properties of MU's shortcut in my desktop, there I see 2 paths: the "target" path w/c is the whole path of the application including the mu.exe file, the other is the "start in" path, where also display the application path but excluding the mu.exe file.

i think the problem is within the application i am trying to run, not in my program, or maybe there is something wrong with the shell command, maybe parameters or sumthin'....

does anyone encounter this type of problem???

then if so, can you share it to this forum, so that i can find a solution to my problem... and it will gladly appreciated!!!... thanx....


Command Line Arguments When Program Is Running
is it possible for your program to accept command line arguments while it is already running?
sorta like winamp does, you enqueue a file while winamp is running and it adds the file to the playlist...

that's pretty much what i want to do, right click on a file and add it to a listbox in my already running program, anyone got tha smarts?

Copyright 2005-08, All rights reserved