exteral program control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, would it be possible for my program to open another program, disk defrag
for example, push the "defrag" button, then wait for it to be done, then
close it? thanks
 
iwdu15 said:
hi, would it be possible for my program to open another program, disk defrag
for example, push the "defrag" button, then wait for it to be done, then
close it? thanks

I know you can do that but you have to find the windows handle to the
defrag window and then figure out the coords to the button. It would
seem a lot easier to use the command-line utility in defag to do it.
Look in the defrag help file it talks about it in there. As to
launching the process from VB. Look at the Process class and the
Process.Start method. Also have a look at the ProcessInfo class.

Good luck
Chris
 
i tried that and all i got was a mess....heres my code:
Dim defrag As New Process
Dim defragSI As New ProcessStartInfo("C:\windows\system32\cmd.exe")

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

defrag.StartInfo = defragSI
defrag.StartInfo.UseShellExecute = False
defrag.StartInfo.RedirectStandardInput = True
defrag.Start()

Try
defrag.StandardInput.WriteLine("defrag c: /f")
defrag.WaitForExit()
Catch ex As Exception

End Try

End Sub

and all that happens is my form and the command prompt, for some reason,
loop and make a new prompt and form over and over. what am i doin wrong?
 
iwdu15 said:
i tried that and all i got was a mess....heres my code:
Dim defrag As New Process
Dim defragSI As New ProcessStartInfo("C:\windows\system32\cmd.exe")

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

defrag.StartInfo = defragSI
defrag.StartInfo.UseShellExecute = False
defrag.StartInfo.RedirectStandardInput = True
defrag.Start()

Try
defrag.StandardInput.WriteLine("defrag c: /f")
defrag.WaitForExit()
Catch ex As Exception

End Try

End Sub

and all that happens is my form and the command prompt, for some reason,
loop and make a new prompt and form over and over. what am i doin wrong?

You don't want to start a cmd.exe process, you want to start a dfag.msc
(think that's right, but look at the shortcut you use to launch defrag
from windows) process with some command line option that are in the help
file. You don't need to send anything to standardinput, you are
starting the defrag program directly.

Chris
 
i cant find the commands in the help file, the only thing i can find is it
using the command prompt...and after i get the commands, how would i tell
Disk Defrag to do that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

PC very slow after un-installing software 4
IPad remote 10
Defrag on hard drives with mutiple file systems 2
Disk defrag not completing 8
shutdown 8
Defrag not your SSD 11
WinXP Defrag. 7
Windows XP Unable to Defrag 1

Back
Top