473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

writing commands to command prompt in VB.NET

Hi, I am having trouble figureing out the best way to open a command
prompt then write lines to it in VB.NET. Currently I have this code,
but it execute's too fast I think because

Dim psi As Object = New ProcessStartInfo
psi.FileName = "cmd.exe"
System.Diagnostics.Process.Start(psi)
SendKeys.Send("abcdefg" & "{enter}")

SendKeys.Send("12345678" & "{enter}")

SendKeys.Send("!@#$%^^&" & "{enter}")

The SendKeys.Send()s seem to be executing so fast that the command
prompt only catches say efg 78 and & in the commmand prompt. And
another thing it seems to do is execute this code twice once for the
down mouse click and one for the up maybe? The effect of the program
running its code twice varies with how long you hold the button down. I
think i need some sort of delays added in but I don't know the function
to do that. And I have no clue how to fix the code running twice. Any
help reguarding any of these issues is much appreciated!

Thank you very much!

Oct 3 '06 #1
6 39464
I figured out how to avoid two coming up by using the Mousedown event
rather than the click event. Although now all of the code is executed
before the command prompt is window is created.

How do you add delays in VB.NET aside from loops?

Oct 3 '06 #2
So what exactly are you trying to accomplish? Maybe there's an easier
way...

Thanks,

Seth Rowe

Sh***********@gmail.com wrote:
I figured out how to avoid two coming up by using the Mousedown event
rather than the click event. Although now all of the code is executed
before the command prompt is window is created.

How do you add delays in VB.NET aside from loops?
Oct 3 '06 #3
Is this what ur looking for?

System.Threading.Thread.Sleep(30000) ' 30 seconds 1000 for every second.

u need a pause in between your commands ?

Miro

<Sh***********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
>I figured out how to avoid two coming up by using the Mousedown event
rather than the click event. Although now all of the code is executed
before the command prompt is window is created.

How do you add delays in VB.NET aside from loops?

Oct 3 '06 #4
Sh***********@gmail.com wrote:
Hi, I am having trouble figureing out the best way to open a command
prompt then write lines to it in VB.NET. Currently I have this code,
but it execute's too fast I think because

Dim psi As Object = New ProcessStartInfo
psi.FileName = "cmd.exe"
System.Diagnostics.Process.Start(psi)
SendKeys.Send("abcdefg" & "{enter}")

SendKeys.Send("12345678" & "{enter}")

SendKeys.Send("!@#$%^^&" & "{enter}")
Is abcdefg and 12345678 and the other command batch files that you are
trying to run? If so, look at starting the cmd.exe and passing in the
name of the batch file at the argument. Like this: This code will
start a batch file and waits for it to exit

Private Sub ExecuteBatFile(ByVal batchfilename As String)
Using m_Process As New Process()
With m_Process.StartInfo
.FileName = "cmd.exe"
.UseShellExecute = False
.CreateNoWindow = True
.Arguments = "/C " & batchfilename"
End With

m_Process.Start()
m_Process.WaitForExit(5000)
End Using
End Sub
Hope this helps

Oct 3 '06 #5
I was trying to avoid using a batch file just due to some of my feilds
having sensitive information. That isn't the case anymore, but still
i'd like to pull this off just using a standard form and pulling up a
command prompt and doin what I need to get done.

I fixed my problems up there, but have run into a far stranger one.

Now im trying to use this statment to copy a couple files from one
directory to another through dos with VB.NET.

copy \\(server name goes here)\(file name goes here)\ ut* c:\data

the ut* is asking for all files with the prefix ut (if you didn't know
that)

when I send this command to the command prompt using the following
statment

SendKeys.Send(strPath & "{enter}")

where strPath = "copy \\(servername goes here)\(file name goes
here)\ut" & ChrW(42) & " c:\data"

the only thing that shows up in the command prompt is * c:\data

Ive tried it several different ways to varying effect... not sure what
is causing the front part to be cut off.

Thankyou sooo much for your help :)

Oct 3 '06 #6
Sh***********@gmail.com wrote:
I was trying to avoid using a batch file just due to some of my feilds
having sensitive information. That isn't the case anymore, but still
i'd like to pull this off just using a standard form and pulling up a
command prompt and doin what I need to get done.
My example showed how to call a batch file, but if you start cmd.exe as
a process, you can then use the redirected StandardInput to send
commands to the command processor:

Public Sub ExecuteDOSCommand()
Using m_Process As New Process()
With m_Process.StartInfo
.FileName = "cmd.exe"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardInput = True
End With

Dim start As DateTime = DateTime.Now

m_Process.Start()
m_Process.StandardInput.WriteLine("copy /Y
\\server\folder\ut* c:\data")

m_Process.Close()
End Using
End Sub
Now im trying to use this statment to copy a couple files from one
directory to another through dos with VB.NET.

copy \\(server name goes here)\(file name goes here)\ ut* c:\data

the ut* is asking for all files with the prefix ut (if you didn't know
that)
The copy command would be copy \\servername\ut* c:\data

You have a space just before the ut*.

But why on earth would you want to use the command prompt to copy the
files when you can use the classes in the System.IO namespace?

Imports System.IO

Public Sub CopyFiles()
Dim destination As String = "c:\data"
Dim filesToCopy() As String =
Directory.GetFiles("\\servername\folder", "ut*")

For Each filename As String In filesToCopy
File.Copy(filename, Path.Combine(destination,
Path.GetFileName(filename)))
Next
End Sub

You'll probably want to add some exception handling to handle any
errors.
when I send this command to the command prompt using the following
statment

SendKeys.Send(strPath & "{enter}")

where strPath = "copy \\(servername goes here)\(file name goes
here)\ut" & ChrW(42) & " c:\data"
the only thing that shows up in the command prompt is * c:\data
I cannot answer this as I do not use SendKeys.

Oct 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kim Ipsen | last post by:
Hi. I don't know if this possible but how would you do it if you wanted to send commands til the comman prompt (and preferrably also receive the output from the command prompt - though not...
5
by: repairman2003 | last post by:
I'm writing a command prompt for unix and I've run into some problems: #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include...
11
by: gert365 | last post by:
I'm working on a scirpt to be used on a windows machine and I need to automate a user's input on the command prompt. For example I'm using os.system('mycommand') to excute the commands I want. ...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
1
by: Josec84 | last post by:
Im writing a script and need help. I need to extract a file using the command prompt. Are there commands to extract files or unzip files(without downloading any add-ons)??? Let's say i have a file...
1
by: yadin | last post by:
hi! i need to know how i can run ussal commands that i ussally type at the windows command prompt from a python file. that is for example from the windows command prompt i ussually type "cd...
0
by: ebindia0041 | last post by:
Any help what is wrong with this code.. I am tring to FTP post a file by command prompt but it not work, system hang up.. commands are in my batch file... System.Diagnostics.ProcessStartInfo psi...
1
by: flanker9876 | last post by:
Hello Everyone, I have Windows XP. I hope that someone can assist me with the command prompt. Does anyone know if the commands I enter into the command prompt are automatically saved to a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.