Link to home
Start Free TrialLog in
Avatar of amateur_player
amateur_player

asked on

closing cmd.exe from vb.net automatically (urgent)

I executed a batch file that ftp's files from vb.net. If the files are not downloaded in 5 minutes i kill the download process and retry again. I implemented the following statements. I want the cmd.exe window to be closed automatically. On my machine this program works with cmd.exe not requiring any manual intervention but on the machine where this program was supposed to run i had to manually click on end now. Does any one has suggestion. Thanks
                                      Try
                                            proc.StartInfo.UseShellExecute = False
                                        Catch ex As Exception
                                        End Try
                                        Try
                                            proc.CloseMainWindow()
                                        Catch ex As Exception
                                        End Try
                                        Try
                                            proc.Kill()
                                            proc.Close()
                                        Catch ex As Exception
                                        End Try
Avatar of wguerram
wguerram

Is your program a console window?

or you run the cmd.exe to do something?
Avatar of amateur_player

ASKER

I have a windows application that runs for every few hours and retrieves the files from remote site. i HAVE A batch file that runs a file FTP.txt. The FTP.txt has information of all the files to be downloaded along with ftp server user name, password, ftp directory name and name of the file to be downloaded. There are around 40000 files to be downloaded. The batch file is opened by VB.net by the following code. When the batch file is opened it opens a cmd.exe window and starts doing FTP. I download 40000 files, 100 at a time. If 100 are not downloaded in 10 minutes i.e. if cmd.exe does not quit in 10 minutes i forcibly close the cmd.exe and rerun it again. There have been issues with their ftp server because of which i could not implement wininet dll methods. so i had to use batch file to download the files.

                    proc = New Process
                    proc.StartInfo.FileName = BatchFileName
                    proc.Start()
My concern is i could not quit the cmd.exe window. Because of this whenever new thread is started there are a number of cmd.exe windows on desktop. The code i wrote works on my machine but not on the machinbe where it was supposed to run
Thanks
Have you try the SHELL function instead?
can you provide me an example how i can call the shell
Thanks
my main concern is when i have   proc.StartInfo.UseShellExecute = False then the command prompt is closed on my machine. When it is set it to true  a new window that says end now or cancel opens and when we click end now the window is closed. why the same statement (   proc.StartInfo.UseShellExecute = False)  does not work on the other machine and i have to manually click end now on that machine
Thanks
ASKER CERTIFIED SOLUTION
Avatar of wguerram
wguerram

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nope. The operating system on live machine was windows 2000 and on mine windows xp. Now i added one line    proc.StartInfo = New ProcessStartInfo
 and i am keeping a watch see if it works.
                                            proc = New Process
                                            proc.StartInfo = New ProcessStartInfo
                                            proc.StartInfo.FileName = BatchFileName
I found the answer. The above code works only on operating systems above windows 2000. If you use wininet.dll for ftp that also works on operating systemn above windows 2000
thanks