1.

Solve : close windows on error with batch file?

Answer» <html><body><p>Hi<br/>I have written a batch file that downloads a file from a website and I have added a line that will write text to a log file if there is an error ie no network or website unavailable but the Internet Explorer windows remains open after the batch file ends<br/>Can someone tell me how I can have the Internet Exporer window to close if there is no network connection or the website is unavailabe.<br/><br/>Thanks<br/>GingerAre you going to let us see the batch file, or not?<br/> Quote from: Salmon Trout on September 04, 2010, 10:36:35 AM</p><blockquote>Are you going to let us see the batch file, or not?<br/><br/></blockquote> My cat is called Ginger.<br/>Corruption once again.<br/><br/>Anyway, Ginger, you could try something in the likes of <br/> <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a>: <a>[Select]</a>IF pingDoesntSucceed <br/>DO exit iexplorer<br/> (I don't know, I'm just giving some tips here).<br/> Quote from: Big on September 04, 2010, 08:47:23 PM<blockquote>Corruption once again.<br/><br/>Anyway, Ginger, you could try something in the likes of <br/> Code: <a>[Select]</a>IF pingDoesntSucceed <br/>DO exit iexplorer<br/> (I don't know, I'm just giving some tips here).<br/><br/></blockquote> <br/>That would be the general idea. (will probably use tskill/taskkill iexplore or something to that effect). Ping seems to give an errorlevel of 1 if the host is not found. (although for some reason it is able to resolve <a href="http://www.sdkjfksdhfkjshdjf.com">www.sdkjfksdhfkjshdjf.com</a>, and thinks it exists (?)) It would probably take additional checking with things like ipconfig to be sure that there isn't a internet connection at all (since invalid hosts still seem to resolve, but that might just be my DNS). Another problem is that most task kill programs kill all open tasks of that program, so killing the single process of internet explorer that was started isn't quite as simple as it seems at first glance- you wouldn't want the person running the batch to be using internet explorer (or even worse, a program using IE as  an out of process COM component) and suddenly kill all instances of IE. Only other way is to provide the window title, but IE changes it's window title in such a way that it's somewhat difficult to predict. Ideal solution might require a third-party "<a href="https://interviewquestions.tuteehub.com/tag/application-25616" style="font-weight:bold;" target="_blank" title="Click to know more about APPLICATION">APPLICATION</a> starter" that allows you to get the Pid of the program, which can be used by tskill to kill a specific instance.I think, rather than ponder how to close the right instance of Internet Explorer, I would rather avoid opening it at all, and use something like wget or curl, or a vbscript to find out if the network connection, website and desired file are all available, if so to get the file, if not to take appropriate action.<br/><br/> Quote from: Salmon Trout on September 05, 2010, 12:31:40 AM<blockquote>I think, rather than ponder how to close the right instance of Internet Explorer, I would rather avoid opening it at all, and use something like wget or curl, or a vbscript to find out if the network connection, website and desired file are all available, if so to get the file, if not to take appropriate action.<br/><br/><br/></blockquote> <br/>For some reason that never even occurred to me, even though at the time I replied I was working on a <a href="https://interviewquestions.tuteehub.com/tag/class-18125" style="font-weight:bold;" target="_blank" title="Click to know more about CLASS">CLASS</a> that does something very similar in C#. Code: <a>[Select]</a>F:\&gt;ping www.slkqjdfmlkjsdf.com<br/>Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name a<br/>nd try again.<br/> Quote from: Big on September 05, 2010, 09:07:40 AM<blockquote> Code: <a>[Select]</a>F:\&gt;ping www.slkqjdfmlkjsdf.com<br/>Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name a<br/>nd try again.<br/></blockquote> <br/> Code: <a>[Select]</a>C:\Users\BC_Programming&gt;ping www.slkqjdfmlkjsdf.com<br/><br/>Pinging www.slkqjdfmlkjsdf.com [67.215.<a href="https://interviewquestions.tuteehub.com/tag/65-242054" style="font-weight:bold;" target="_blank" title="Click to know more about 65">65</a>.132] with 32 bytes of data:<br/>Reply from 67.215.65.132: bytes=32 time=87ms TTL=55<br/>Reply from 67.215.65.132: bytes=32 time=86ms TTL=55<br/>Reply from 67.215.65.132: bytes=32 time=85ms TTL=55<br/>Reply from 67.215.65.132: bytes=32 time=100ms TTL=55<br/><br/>Ping statistics for 67.215.65.132:<br/>    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br/>Approximate round trip times in milli-seconds:<br/>    Minimum = 85ms, Maximum = 100ms, Average = 89ms<br/><br/> Quote<blockquote>since invalid hosts still seem to resolve, <strong>but that might just be my DNS</strong><br/></blockquote> <br/><br/>I'm pretty sure it is.<br/>Let's have a try...<br/><br/> Code: <a>[Select]</a>C:\&gt;ping www.slkqjdfmlkjsdf.com<br/><br/>Pinging www.slkqjdfmlkjsdf.com [81.200.<a href="https://interviewquestions.tuteehub.com/tag/64-242053" style="font-weight:bold;" target="_blank" title="Click to know more about 64">64</a>.50] with 32 bytes of data:<br/>Reply from 81.200.64.50: bytes=32 time=29ms TTL=56<br/>Reply from 81.200.64.50: bytes=32 time=36ms TTL=56<br/>Reply from 81.200.64.50: bytes=32 time=28ms TTL=56<br/>Reply from 81.200.64.50: bytes=32 time=32ms TTL=56<br/><br/>Ping statistics for 81.200.64.50:<br/>    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br/>Approximate round trip times in milli-seconds:<br/>    Minimum = 28ms, Maximum = 36ms, Average = 31ms<br/><br/>Hmmm... try a tracert...<br/><br/> Code: <a>[Select]</a>C:\&gt;tracert 81.200.64.50<br/><br/>Tracing route to advancedsearch.virginmedia.com [81.200.64.50]<br/>over a maximum of 30 hops:<br/><br/>  1     7 ms    22 ms    37 ms  10.25.252.1<br/>  2     8 ms    37 ms    16 ms  aztw-geam-1b-ge210.network.virginmedia.net [80.1.243.133]<br/>  3    48 ms    29 ms    23 ms  aztw-core-1b-ae0-0.network.virginmedia.net [80.1.241.13]<br/>  4     8 ms     9 ms    37 ms  brhm-bb-1b-as1-0.network.virginmedia.net [213.105.175.161<br/>  5    52 ms    79 ms    69 ms  manc-bb-1a-as6-0.network.virginmedia.net [62.253.185.134]<br/>  6    14 ms    39 ms    14 ms  manc-bb-1b-ae5-0.network.virginmedia.net [213.105.174.186<br/>  7    34 ms    25 ms    36 ms  te-4-3.ar3.CDG2.gblx.net [204.246.200.177]<br/>  8    29 ms    28 ms    29 ms  64.214.140.138<br/>  9    30 ms    41 ms    37 ms  advancedsearch.virginmedia.com [81.200.64.50]<br/><br/>Trace complete.<br/> Quote from: Tracert output<blockquote>advancedsearch.virginmedia.com</blockquote> <br/>Aha!<br/><br/><br/><br/><br/><br/><br/><br/> Code: <a>[Select]</a>C:\&gt;ping www.slkqjdfmlkjsdf.com<br/>Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name and try again.<br/>That's better.<br/><br/> Quote from: BC_Programmer on September 05, 2010, 09:12:30 AM<blockquote><br/>I'm pretty sure it is.<br/><br/></blockquote> <br/>Sure looks that way<br/><br/> Code: <a>[Select]</a>C:\&gt;tracert 67.215.65.132<br/><br/>Tracing route to hit-nxdomain.opendns.com [67.215.65.132]<br/>over a maximum of 30 hops:<br/><br/>  1    64 ms    14 ms     8 ms  10.25.252.1<br/>  2    45 ms    19 ms   233 ms  aztw-geam-1a-ge147.network.virginmedia.net [80.1.243.1]<br/>  3    33 ms    10 ms    11 ms  aztw-core-1a-ae0-0.network.virginmedia.net [80.1.241.9]<br/>  4    50 ms    31 ms    34 ms  winn-bb-1a-as0-0.network.virginmedia.net [213.105.175.157]<br/>  5    12 ms    44 ms    12 ms  brnt-bb-1b-as5-0.network.virginmedia.net [213.105.172.234]<br/>  6    59 ms    16 ms    16 ms  195.50.91.129<br/>  7    47 ms    17 ms    35 ms  ae-32-52.ebr2.London2.Level3.net [4.68.117.62]<br/>  8    17 ms    70 ms    45 ms  ae-3-3.ebr1.London1.Level3.net [4.69.141.189]<br/>  9    28 ms    15 ms    50 ms  ae-100-100.ebr2.London1.Level3.net [4.69.141.166]<br/> 10    41 ms    31 ms    23 ms  ae-48-48.ebr2.Amsterdam1.Level3.net [4.69.143.81]<br/> 11    68 ms    27 ms    24 ms  ae-2-52.edge4.Amsterdam1.Level3.net [4.69.139.170]<br/> 12    35 ms    46 ms    65 ms  SPLICE-COMM.edge4.Amsterdam1.Level3.net [212.72.40.98]<br/> 13    23 ms    54 ms    57 ms  hit-nxdomain.opendns.com [67.215.65.132]<br/><br/>Trace complete.</body></html>


Discussion

No Comment Found