Question: I'm trying to do a one-line batch command (for use with `autohotkey` with a keybaord shortcut) to:

* disconnect Wifi if it is connected: `netsh wlan disconnect`
* connect to SSID="MyWifi" if Wifi is currently disconnected: `netsh wlan connect ssid="MyWifi" name="MyWifi"`

This outputs some result if it is connected, and outputs nothing if it is disconnected:

```
netsh interface show interface |findstr /C:"Connected"

```

**How to use this in a `if else` condition?**

Example (pseudo code):

```
if ((netsh interface show interface |findstr /C:"Connected") == "")
then netsh wlan connect ssid="MyWifi" name="MyWifi"
else netsh wlan disconnect

```

Answer: 
Can Bad sectors in Hard Drive really cause Data loss?

Yes, they can. It depends upon what worked and what did not. When it comes to Bad Sectors there are some related critical S.M.A.R.T. parameters.

**Reallocated Sector count** - Bad sectors that generally have been remapped to spare area.

**Current Pending Sector Count** - Unstable sectors on the hard disk that are yet to be remapped or reallocated. Sometimes these are SOFT errors and a full disk low-level reformat may correct it.

**Uncorrectable Sector Count** - Number of uncorrectable errors while reading or writing a sector on the hard drive. These may cause permanent data loss.

If the system completely fails to read a bad sector it may not at all reallocate it. In that case the entity e.g. a File that was residing there will get corrupted.

By chance you may be lucky or the issue is latent for now. One fine day you may open a photo and find that the file is actually corrupted.
I would be interested to see your full S.M.A.R.T. report. Showing these 3 critical parameters among all others.
Yes, they most certainly can and frequently are cause for loss of data. It's not uncommon for data recovery labs to have their special hardware designed to clone drives with bad sectors working around the clock, full time. This hardware directly communicates with the drives often using vendor specific commands (VSC) and are highly tweakable (timeouts, skip heads, various resets etc.).

[![Several DeepSpar DDI units in action](https://i.stack.imgur.com/TN9Nw.jpg)](https://i.stack.imgur.com/TN9Nw.jpg)

Of course we can lose the data stored inside the sector that goes bad. If this happens to be a sector that stores a user file, say a JPEG that lost sector will cause the JPEG to corrupt. Also the operating system rather than opening the file will probably not open it and instead present an error message.

We have a more serious problem if we have one or more bad sectors that store file system meta data. It's not uncommon for an operating system like Windows trying to read such sectors over and over causing the system to lock up. We basically lose the ability to access the entire volume with a few strategically placed bad sectors.

But it can be even worse. For example, in the past certain drives with certain firmware issue that kept trying to reallocate bad sectors. These reallocations are recorded in a certain part inside the system area (SA), and continued reallocation caused these areas to overflow and effectively overwrite crucial data inside the SA. And since firmware is stored on the disk's surface as well, these sectors can go bad themselves rendering the drive useless.

Also bad sectors in SSD, SD card and USB flash drives often cause the drive to 'go stupid', the firmware gets so busy handling the anomalies that it leaves no time to respond to read or write commands.

**Recovery.**

If a drive is still responding to commands the first thing we need to do is clone or image a drive. As mentioned a data recovery lab uses specially designed hardware. If you want to try yourself you need to use software that was designed for this task. Examples are ddrescue and HDDSuperClone where the latter is more advanced.

Key with cloning is, is to avoid and spend as little time as possible on bad sectors during a first phase. Get all data that can still be read while stressing a drive as little as possible.

If key file system meta data was knocked out by bad sectors, next stage is virtually reconstructing those as much as possible using file recovery software (which we use on the clone / disk image, *not* the patient drive). A data recovery lab often uses software that's highly integrated with their special hardware.

As a last step repair can be attempted of individual files that were recovered but partially were in bad areas (repair of badly damaged photo).

[![repair badly damaged photo](https://i.stack.imgur.com/uQwiv.jpg)](https://i.stack.imgur.com/uQwiv.jpg)