[RESOLVED]How to make a command line wait?
In using the code I created below, I have came across an error
Quote:
The process cannot access the file because it is being used by another process.
So my VB 8.0 2005 code is this...
Quote:
Private Sub Backup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Backup.Click
On Error GoTo ClickErr
Dim fileExists As Boolean
fileExists = My.Computer.FileSystem.FileExists("C:\Program Files\Store2Office\DBBackup.zip")
If fileExists Then
My.Computer.FileSystem.RenameFile("C:\Program Files\Store2Office\DBBackup.zip", "OMC_Backup_DBBackup.zip")
End If
Shell("C:\Program Files\Store2Office\HK_Office.exe /backupdb")
My.Computer.FileSystem.CreateDirectory("C:\Program Files\Store2Office\Archive")
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists("C:\Program Files\Store2Office\Archive")
If folderExists Then
My.Computer.FileSystem.MoveFile("C:\Program Files\Store2Office\DBBackup.zip", "C:\Program Files\Store2Office\Archive\DBBackup.zip")
End If
MsgBox("Databases are backed up")
ClickErr:
MsgBox(Err.Description)
End Sub
So what I am thinking is that the HK_Office.exe is taking a little while to zip up the files for me. So my question is this. How can I make the next line to wait til that process is done before going to the next line to finish my request of moving the files?
Re: How to make a command line wait?
Use the Process class instead of Shell in order to start the program. The process class has a .WaitForExit method that does just that, waits for the process to exit before executing the next line of code...
Re: How to make a command line wait?
Process class (program)?? instead of shell (program)?
Re: How to make a command line wait?
Check out this recent thread for an example of running a program with parameters using the Process class...
http://www.vbforums.com/showthread.php?t=420795
Re: How to make a command line wait?
I am trying to get a full understanding how this works. so the code ou provided was...
Quote:
VB Code:
Dim MyProcess As New Process
Dim MyStartInfo As New ProcessStartInfo
'filename of the program to run, best to use full path
MyStartInfo.FileName = "notepad.exe"
'arguments to pass into the program
MyStartInfo.Arguments = "my arguments"
'sets new startinfo object to MyProcess' StartInfo property
MyProcess.StartInfo = MyStartInfo
'starts the process
MyProcess.Start()
MyStartInfo.FileName = "notepad.exe" is where I would put the program to zip my files right?
now what is the arguments? Is that the next process?
Re: How to make a command line wait?
The arguments is the string that you want to pass into the prog, in this case, "/backupdb", with the exe being "HK_Office.exe" (with the full path to the file)
Re: How to make a command line wait?
Ok.. that explains it now. So what causes it to wait until that process is done before going to the next one?
Re: How to make a command line wait?
well does this process exit automatically after that program and arguments are ran? If so, just add one line after you call MyProcess.Start, and that line would be "MyProcess.WaitForExit"
Re: How to make a command line wait?
Thanks that worked just fine. I have another problem with in the same project but a diffenent part of the code.
VB Code:
Dim xCon As New OleDb.OleDbConnection
Dim xCom As New OleDb.OleDbCommand
Dim xAdap As New OleDb.OleDbDataAdapter(xCom)
Dim xComBuild As New OleDb.OleDbCommandBuilder(xAdap)
Dim ConnnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Store2Office\Emp.mdb;Mode=ReadWrite;Persist Security Info=False"
Dim emp As String = "Emp.mdb"
[B]xCom.CommandText = "Delete * from charges where s_date<#" & TextBox1.Text & "#"[/B]
xCom.CommandText = "Delete * from clockchanges where indate<#" & TextBox1.Text & "#"
xCom.CommandText = "Delete * from clockdata where indate<#" & TextBox1.Text & "#"
xCom.CommandText = "Delete * from mhj_schedule where s_date<#" & TextBox1.Text & "#"
xCom.CommandText = "Delete * from schedule where indate<#" & TextBox1.Text & "#"
xCom.Connection = xCon
xCon.ConnectionString = ConnnectionString
If xCon.State = ConnectionState.Closed Then
xCon.Open()
End If
xCom.ExecuteNonQuery()
xCon.Close()
So my problem that I am getting is that the data is deleted with the first like that is in bold. But the rest of the tables are not touched. Would this be something like before? needing to setup a process or each line?
Re: How to make a command line wait?
Well all those lines are doing is changing the command text, you are only running it one time when you call .ExecuteNonQuery, and the command its going to run is the last thing it was changed to. You would have to execute it once for each command you wish to run I believe, although I haven't messed too much into the database side of things...
Also, since this is an unrelated question, you might want to start a new thread about it in order for the database experts to see it...
Re: How to make a command line wait?
So you mean like such?
xCom.CommandText = "Delete * from charges where s_date<#" & TextBox1.Text & "#"
xCom.ExecuteNonQuery()
xCom.CommandText = "Delete * from clockchanges where indate<#" & TextBox1.Text & "#"
xCom.ExecuteNonQuery()
and every other line too?
Re: How to make a command line wait?
Ok.. I can repost that question..
just a quicky though.. I created a cancel button.. but I can't find any referance as to how to make it close the window (program)
Re: How to make a command line wait?
the database question is on http://www.vbforums.com/showthread.p...22#post2573022
thanks for helping me with this question thanks
Re: [RESOLVED]How to make a command line wait?
...will close the form.
...will exit the program.
Re: [RESOLVED]How to make a command line wait?
Please keep each topic to one thread and each thread to one topic. That way information is nice and easy to find for everyone. Asking multiple unrelated questions in the same thread makes information harder to find. Asking the same question in multiple threads makes life more difficult for those who are helping you, and that's something you should strive not to do.