Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

28 Jan 2020

Copying files from a MicroSD card to PC fails

On an Android phone the 64GB MicroSD storage expansion card was nearly full. I replaced it with a 128GB card. I plugged the old 64GB card in my Windows PC and started copying the photos and videos from it to my hard disk. There was nearly 64GB of data so I left it copying... Upon my return I found it had stopped after only copying only a few files. There was a semaphore error.

Maybe there was a corrupt file? The MicroSD card could be corrupt or faulty?

I tried the file copy again but this time I used the Robocopy command line, it is more robust than Explorer and I felt perhaps it would do a better job. Robocopy also stopped after copying just a few files. It was as thorough the SD card was no longer recognised by my PC.


Robocopy ERROR 121 (0x00000079)
The semaphore timeout period has expired.

I tried a different USB port
I tried a different SD card reader
No success.

I ran the Robocopy command, when it got stuck I removed the SD card physically from the computer, then plugged it back in. It would copy more files... Until getting stuck again. I successfully used this method to copy a large number of files but with hundreds of files this was not a viable solution.

I noticed that mostly smaller files were being copied more often than larger ones. Video files of 100MB just got stuck.

For the video files over 50MB I used 7-Zip to create a compressed file with volumes. I ended up with lots of 1.44MB files. I managed to copy these smaller files to the C: drive and extract the video file. I continued with this for a time, I was mostly successful. But this was slow and the semaphore error came up again. 



Solution
I did a lot of searching on the web, I came across an application called Backupper. I tried this to synchronise a folder on the old MicroSD card to my C: drive. This worked! It does take a long time and it is quirky software because it has a percentage complete that goes steadily to 76% and appears to get stuck there. But it is still working, if you open Explorer to the destination folder you will see new files appear. Be patient though, in my case I left it running all day.


In the above screen shot you'll see that it couldn't read a file. In this case you'll just have to accept that, because it can't work miracles, some files might be corrupt/damaged. I did recover most of the files though.


Conclusion
If you have the semaphore error do not despair. Try Backupper, it's worth a go.

Of course it does raise a question over the reliability of MicroSD cards. My feeling is that when you have used a card extensively and almost filled it with so many files, the possibility of a failure like this grows. Contemplate replacing your micro SD card every few years and of course back up. Google Photos backup is free therefore at least for JPGs you can safeguard them. For videos maybe copy them off your phone periodically?

I hope this was helpful. Many thanks to Backupper.
https://www.ubackup.com/download.html


Disclaimer
I am not guaranteeing anything here. This is just my experience! Good luck.


Related
You might also be interested in the following recent article I wrote about a problem I found with MicroSD cards. This is more related to the speed of the card and which one to purchase.
https://mgxp.blogspot.com/2019/12/which-microsd-card-should-i-use-in-my.html

16 Mar 2018

WMIC /format - Invalid XSL format (or) file name.

You may see an error when using WMIC /format switch, as in the following example where I wanted to write a list of the installed patches on my computer to a CSV file:
wmic /output:"d:\patches.csv" qfe list full /format:csv

But I got this error: Invalid XSL format (or) file name.


Solution
Copy the XSL files as follows:

from
C:\Windows\system32\wbem\en-us\*.xsl
to
C:\Windows\system32\wbem

Once you've done that, when you run the WMIC command with the /format switch, it will work. I have successfully tested this on a Windows 7 computer.


Reference
https://stackoverflow.com/questions/9673057/wmic-error-invalid-xsl-format-in-windows7



16 Feb 2018

List the members of an Active Directory group

From a Windows computer would you like to see a list of the members of a particular Active Directory (network) group? In this article we'll explore how to do this and how to extract and rearrange the usernames into a conventional vertical list.

List the members of a group
Open a command window - press Win-R, type CMD and press Enter
Enter the command: NET GROUP "your group name" /domain

You should replace "your group name" with the name of the group you wish to see the membership of. Remember that the double quotes " " are important, often Active Directory group names have spaces in them, using the quotes is essential for the group name to be recognised. 

Here's an example:


The result is OK. The users in the group are listed under the dotted line. The only thing that's not good is that they are listed in three columns. This makes it difficult to easily extract these usernames for other uses. For example, you may wish to send an e-mail to everyone in this group or display this list in a report. This problem is especially acute when there are many hundreds of group members.


Create a vertical list of usernames
The aim is to create a list as follows:
RIPLEY
DALLAS
ASH
LAMBERT
KANE
PARKER
BRETT
This is much easier to work with in Excel or Outlook.

I've written a small script using AutoIt. Before you go further, ensure you have AutoIt installed on your computer. It's an excellent scripting language because after you create your script you can compile it to an EXE and use it standalone, without having to install anything on the computer where you use it. More information on AutoIt can be found here:
https://mgxp.blogspot.ch/2013/05/autoit-scripting-language-for-windows.html

The script I've written is called Membership. It runs the above NET GROUP command, the output is written to a text file. That file is read by the script, the names are extracted and written to a new text file in order vertically. 


Source Code

#cs ----------------------------------------------------------------------------
 Membership.au3
 AutoIt Version: 3.3.14.2
 Author:        Michael Gerrard, mgxp.blogspot.ch, February 2018

 Script Function:
 List users who are the members of an AD group to a file.

#ce ----------------------------------------------------------------------------

$group      = "your group name"  ;change to a valid AD group name!
$title      = "Membership"
$inputFile  = @ScriptDir & "\membership.tmp"
$outputFile = @ScriptDir & "\membership.txt"
$n          = 8 ;line counter (starts at 8)
$u          = 1 ;user counter

; Run the NET GROUP command to list the users
RunWait(@ComSpec & ' /c NET GROUP "' & $group & '" /domain > ' & $inputFile, @ScriptDir, @SW_MINIMIZE)

; Open the input file and read the lines
$file  = FileOpen($inputFile, 0) ;open read only
$aFile  = FileReadToArray($file)
If @error Then  ;An error occurred reading the current script file
    MsgBox(16, $title, "There was an error reading the file.")
 Exit
EndIf
FileClose($file)

; Step through the lines and output the usernames to the output file
$file = FileOpen($outputFile, 2) ;create a new file
While $aFile[$n] <> "The command completed successfully." ;loop through the lines

 $aSplit = StringSplit($aFile[$n], " ") ;split the line into users
 For $u = 1 To $aSplit[0] ;step through the possible users

  $ws = StringIsSpace($aSplit[$u]) ;some users are white spaces
  If $ws = 0 Then ;if not white space
   FileWriteLine($file, $aSplit[$u]) ;write the user to the output file
  EndIf
 Next ;loop again to find another user

 $u = 1  ;reset to 1
 $n = $n + 1 ;increment the loop
Wend

FileClose($file)
FileDelete($inputFile) ;delete the temporary input file
Run("notepad " & $outputFile, @ScriptDir)
Exit

Copy and paste the above code into a text file.

Save the text file as Membership.au3

The first line in the code is where a variable is defined for the group name:
$group = "your group name"
Change the text in double quotes to the name of the your group.


Run the script
As long as you have AutoIt installed you can either run the Membership.au3 file or compile it to an EXE for standalone use.

Remember to change the variable $group to the group name of your choice before running or compiling the script.

NOTE: For the script to work it should be in a folder with a path structure without spaces. For example, if it's in D:\VeryImportant\Files that will work fine. If it's in D:\Very Important\Files then it will not work.

When you run the script it will open Notepad with the usernames in a vertical list like this:


From Notepad you can copy/paste the list to Excel, Word or where ever. Also, it is possible from Excel PowerView to query this text file, this can be useful if you wish to match it to other data you may have in a corporate database.


Conclusion
It's a real shame that the NET GROUP command doesn't have the ability to list the names vertically to start with. However, using AutoIt it's possible to get around this and make a simple but effective solution. I hope this is of help to you.






26 Jan 2018

Finddocx - a script to find and backup documents from the C:, where ever they may be hiding!

Are you working in IT support, have you ever had to backup user documents from the C: drive before replacing or re-imaging their computer? I've had to do this and I know what a nightmare it can be. Copying the Documents folder is not enough, there are always more user documents elsewhere, potentially anywhere on the computer! Sometimes the user doesn't even know where their treasured files are.

In this article we'll look at a solution, to use Robocopy to scan the C: drive for document files and back them up (for example; copy to a USB flash drive).


Robocopy
This is a free command line program included with Windows as standard. In my example here I'll be using Windows 7 but this will also work for Windows 10 as well.

If you'd like to learn more about the basic functionality of Robocopy please see my previous article on the subject: https://mgxp.blogspot.ch/2015/01/robocopy-backup-and-file.html


Finddocx 
Finddocx is just a name I've given my script. It consists of two files, a command (batch) file and a Robocopy job file.


Finddocx.cmd (command file)
The command (batch) file, double click to execute. This contains the source and destination locations. Here's what it looks like inside:

ROBOCOPY C:\ %username% /JOB:finddocx 
pause

The first line is as follows:
ROBOCOPY <source> <destination> /JOB:<jobfile>

In my example I will search the entire C: drive (C:\). The backup files will be stored in a folder named after my own Windows username, the %username% is a variable. The /JOB:finddocx will use the finddocx.rcj for parameters.

The pause command at the end is just to stop the command window from closing when the script ends.


Finddocx.rcj (job file)
The job file. It contains various parameters including which file types to backup. The following is inside the file:

:: Finddocx example job file
:: mgxp.blogspot.ch
:: January 2018

:: Use two colons :: to disable a command from running. 
:: This job file is a modified version of one generated by Robocopy.
:: See Robocopy /? for more details. 

:: 
:: Include These Files :
::
 /IF  :: Include Files matching these names
  *.doc?
::  *.xls?
::  *.ppt?
::  *.pdf
::  *.txt
::  *.png
::  *.jpg
  
::
:: Exclude These Directories :
::
 /XD  :: eXclude Directories matching these names
  AppData
::
:: Copy options :
::
 /S  :: copy Subdirectories, but not empty ones.
 /COPY:DAT :: what to COPY for files (default is /COPY:DAT).
 /PURGE  :: delete dest files/dirs that no longer exist in source.
::
:: Retry Options :
::
 /R:0  :: number of Retries on failed copies: default 1 million.
 /W:30  :: Wait time between retries: default is 30 seconds.
::
:: Logging Options :
::
 /LOG+:log.txt :: output status to LOG file (append to existing log).
 /TEE  :: output to console window, as well as the log file.

In the above job file, where you see two colons :: it means that the text on that line is ignored. In other words, :: means a comment.

/IF
You'll notice that there's an /IF command at line 12. Below it there is a list of file types. In my example above only *.doc? is enabled. However, if you wish, remove the :: next to the others to backup more file types. You could also extend this list and add even more file types.

/XD
Add folders here that you do not want it to search. I've put AppData here because it was just giving 'access denied' errors so I prefer to exclude it. You can add more folders here as needed.


Setup Finddocx
The following is an example only:

  1. Insert a USB flash drive
  2. Create a folder on it called "finddocx"
  3. Copy the source code for finddocx.cmd (above)
  4. Open Notepad and Paste
  5. Save the file to the USB drive into the finddocx folder as finddocx.cmd
  6. Copy the source code for finddocx.rcj (above)
  7. Open Notepad (a new window) and Paste
  8. Save the file to the USB drive into the finddocx folder as finddocx.rcj
  9. Edit the finddocx.cmd and rcj files as needed (you may wish to add more file types to search for, you may wish to change the destination folder, etc). 

Run Finddocx
Here's what happens if I double click my finddocx.cmd, a command window will open you'll see thousands of files zoom by:


Don't worry, don't touch, just let it work. Once it has finished press a key to close it.

Look in the folder on your flash drive:

A log.txt file has been created, open in Notepad to see what happened, what was backed up, if there were errors, etc.

You'll see a folder with your username, in my example "Michael". This is where the backup is. Double click Michael (or whatever your folder is called) and you'll see something like this:


There will be sub-folders. These represent the folders from your C: drive. If you explorer these folders you'll find the various doc files that were backed up. The folder structure where they were found on your C: is maintained and replicated here.


Notes
  • The second time you run Finddocx with the same user it will delete the existing files on your backup destination (USB drive) and replace them with new copies from the C: drive.
  • Using the %username% variable means you can take your USB flash drive from computer to computer backing up data. The backed up files will be stored in separate folders on your USB drive.
  • Instead of using %username% you could edit the finddocx.cmd and change it to backup to %computername%.
  • If you want to create your own Robocopy job file from scratch you can do. You must use the /SAVE:<job> parameter. Please see the Robocopy documentation or Robocopy /? for details.


Disclaimer
Use at your own risk! The script I've included here is just an example to get you started. I am not guaranteeing anything. I am not responsible if you mess something up! Take care, especially with user data.


Conclusion
This script is just a start, using it and the power of Robocopy you can easily backup user files. Of course it can't replace a proper backup solution but as explained in the introduction, it could be a simple way to make a copy of important user files prior to replacing a computer or re-imaging it. I hope you found this article useful.






25 Jan 2018

Close Java AutoIt Script

If you are running a program that relies upon Java Runtime, sometimes it crashes and even using End Task doesn't seem to remove everything from memory. I was often having this problem so I wrote a small script with AutoIt to look for Java and close it, over and over again until it is gone from memory! You could adapt this script to close any troublesome program of course, just change the $proc= variable line in the script below.

Here's the script in case you find it useful:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         Michael Gerrard, http://mgxp.blogspot.com

 Script Function:
 Close a process

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

$title  = "Close Java"
$proc  = "jp2launcher.exe"

If ProcessExists($proc) > 0 Then ;if it is running...

 ; Confirm that it should be closed
 $ok = MsgBox(33, $title, "Close " & $proc & "?")
 If $ok = 1 Then ;if OK
  While ProcessExists($proc) > 0
   ProcessClose($proc)
   Sleep(500) ;pause half a second
  Wend
 Else ;if Cancel
  Exit
 EndIf

 ; Check again to see if it is running now...
 If ProcessExists($proc) > 0 Then  ;it is still running
  MsgBox(0, $title, "Failed!")
 Else ;it is not running
  MsgBox(0, $title, "Success!")
 EndIf

Else ;if it is not running...
 MsgBox(0, $title, $proc & " is not running")
EndIf
Exit

Copy the above code, save it in a text file called CloseJava.au3

Compile using AutoIt https://autoitscript.com

Double click the resulting CloseJava.exe, it'll say:


Click OK





Conclusion
Just a small script that demonstrates how useful AutoIt is. Of course I've shown how to close Java but you could use the same script to close a different program. Just alter the $proc= variable.



4 Apr 2017

Windows PC Backup Strategy

It is good to have a strategy and it is especially true when it comes to backing up your photos, documents and other precious data. Who knows what might happen, maybe your computer will die, you'll be flooded, a plague of locust will descend or worse still your computer is taken over by ransomeware! Whatever ill might befall your computer, make backups, it is your best insurance policy against any disaster.

There is a concept that I think is very important as a minimum, it is the 321 backup rule:
  • Have at least three backup copies of your data
  • Store the backup copies on two different media
  • Keep one backup copy off-site
But how do we put that into practice and what tools can we use? In this article we'll explore all of these questions and answer a few more too!

For a Windows PC there are three types of backup, they provide three different layers of insurance against different disasters. I recommend you use all three. The frequency you run them is up to you but I'll explain more below:


1) System Image Backup and System Repair Disc
What happens if there is a total disaster such as your computer hard disk drive dies? If that happens how do you restore your system?

Windows contains a free program called System Image Backup. You can use this to create a snapshot of everything that is on your computer. It will also prompt you to create a rescue disc called the System Repair Disc. Here's an easy to follow article on this:
https://www.howtogeek.com/howto/4241/how-to-create-a-system-image-in-windows-7/

It's important to create the System Repair Disc because it will enable you to start your computer in the event that Windows is corrupt or you are installing a brand new replacement hard disk (if your old one failed).

The System Image Backup has a downside though. You cannot use it to restore individual files. This means it is only useful in the event of a complete disaster. If you just accidentally deleted a file, there's no way you could easily get it back using the System Image Backup.


2) Full System Backup
Backs up all system and data files. This backup can be used to restore all files or individual files. Run this periodically, once a month for example.

Windows 10, 8.0 and 7 (but not 8.1) come with a free Backup and Restore utility:
https://www.howtogeek.com/howto/1838/using-backup-and-restore-in-windows-7/
I recommend you use it with a large capacity external USB hard disk drive as it can store multiple backups.



3) File Backup
Backs up only data files or only those files you are using often. Run this daily or better still, use a tool like File History (included free with Windows 10, 8.1 and 8) to backup any file immediately it has been changed. This is the best because, depending on the amount of storage you have, multiple versions (history) of the files will be stored. You must configure File History to use a USB drive, I recommend having a small USB flash drive permanently plugged into your computer for this purpose. 

An even better alternative is use a Cloud backup solution such as Carbonite - it's not free but it does have some advantages. It works in a similar way to Windows File History. Files are backed up as you change them, multiple versions of files are stored in the backup. The big difference is that if the worst happened and your house burns down, your USB drive would be toast but your Cloud backup would be safe. Apart from having to pay for it, there's another downside to Cloud backup; security. Who is taking care of your files? How secure are they? Serious companies like Carbonite encrypt your files and of course you should make sure you have a strong password. But it is true to say that using Cloud backup does introduce this extra dimension for you to be concerned about.

Of course there's also cloud storage drives like DropBox, OneDrive, GoogleDrive, etc. But these are not backup solutions, they are designed to be used for working and sharing files. Even so, you could copy important files to such storage as a kind of backup solution.



More points to consider:

Multiple Backups
I recommend you have at least one System Image Backup and at least two backups of your data files at any one time. The backups should be on separate media (two different drives) and in different physical locations. These precautions are in case one backup drive fails, at least there is another backup to cover you while you go to the shop to buy a new drive.


Different Locations
Store backups in different physical locations. Imagine your house burnt down, do you have a backup of your data somewhere safe? Maybe take a backup drive to work or use a Cloud backup service.


Unplug
At least one of your backups should be disconnected/unplugged from your computer. In other words, don't backup and leave the drive connected all the time. If a virus hits your computer it might infect your connected devices including your backup. 


Versions
Imagine you delete a file today. Then later you run your backup, that deleted file is also deleted from your backup. The next day you decide deleting that file was a mistake, you want to recover it. You can't because it isn't in your backup as your backup reflects what's on your computer! OK, what to do? If you had a backup at every stage or that were made on a daily basis, you could go back to the point in the backup where the file exists and restore it. The downside is that your backup could be very large when storing multiple versions of files or multiple backups over time. In other words, you'll need plenty of spare disk space.


Frequency
How often should you backup? This depends on you and your data. If you update your data files every day I would recommend backing up every day. If you only update files once in a few days perhaps a once or twice a week backup is enough. Also think about the data you are backing up, do you really need to back all of it up each time. For example, if you are storing photos from five years ago and you are not changing them now, they are static, they do not need to be backed up every day. You could make a backup once and store that somewhere. Your more frequent backup could then be used to backup only the latest data, saving time and storage space needed.


Archives
As mentioned above, often you have data files you don't use often or that don't change or perhaps there are software programs (setup.exe) you have downloaded and you want to keep. In this case you can archive these files. Archive means to put aside in a safe place but they don't need to be so accessible as a backup would be. For example, do you have photos from five years ago on your computer? Maybe you just need to keep a copy somewhere but you don't need to back them up every day because they don't change. Archiving can be useful if you don't have a lot of storage space on your computer. After archiving you could delete the original files from your computer. I recommend making at least two copies of any data, especially archived files. Store your archived backups in a very safe place away from humidity or extreme heat (don't leave them on a shelf that is hit by sunlight for example).

As you will not be accessing archived data often you could store the files on DVD-R discs. DVD-Rs are cheap and durable but there are some drawbacks to using them. Typically they can only contain 4.7GB per disc. They are being used less and less - think about the future, in years to come, to read your DVD archives you should keep an external USB DVD drive in a safe place. For the same reason, have at least two copies, one on DVD and one on another media.

USB flash drives have had a reputation for failing so you may think they are not the best for archives. However, the real problem with USB flash drives is that the more you write to them (save data on them), the higher the possibility of failure. If you buy a USB flash drive, save data to it and store it a dry cool place, then it should last many years. Of course, as I've said before, always keep at least one more copy of your data on other media to be safe.


File Format
What format are the files you back up stored in? This is very important for archives because if you backup using a commercial software tool that uses a preparatory file format, in five or ten years from now will you still have that software, if not can you restore the files? In this case consider storing at least your archived files just as files or perhaps in a common format. For example, if you use zip or even 7z, because they are commonly used, you should have no trouble in accessing those files in years to come.

If you are interested in writing your own backup solution I have a few articles on this subject, mostly using the Robocopy and 7za command line tools.


Hardware
External USB hard disk drives are relatively cheap these days. I recommend the ones that are powered by USB (the ones you do not have to plug into the mains electricity). They are a little more expensive than 'desktop' external drives but they are smaller and only have one cable (USB), that's one less thing to go wrong. I use Western Digital Elements Basic Storage but other manufacturers are selling similar products at reasonable prices. Buy two drives and use them alternately, that will give you a good level of protection. Hard disk drives do have moving parts and therefore they can fail, take care of them.

USB flash drives are cheap, less storage capacity but even so they can form part of your strategy, for daily file backups they are ideal as they are convenient. For the best speed use USB 3, not USB 2 flash drives. But of course when you plug it into your computer make sure you plug it into the USB 3 port (sometimes computers come with a mixture of USB 2 and 3 ports, plugging a USB 3 device into a USB 2 port will mean it will run at USB 2 speed).

Don't buy the cheapest as they may not last long but on the other hand there's no need to spend a lot of money. Many brands such as SanDisk make high quality products for a reasonable price. In the past there was much told of USB flash drives wearing out after thousands of writes (the number of time files are saved to the drive). At the time of writing, April 2017, this is much less of a concern than it was, the quality of the USB drives is much better. However, don't put all your eggs in one basket! Use multiple USB flash drives and have multiple backups. 

Network Attached Storage (NAS) drives are a great idea but they are more expensive, especially if you only want to use it for backup. 


Test it!

I've seen many people have a very nice backup solution but they have never tested it, never actually restored files from it. When disaster does strike they are very surprised to learn that their backup is useless. It is important that you check your backup did really work, check the log file and most importantly, from time to time restore some sample files. That's the best way to be sure.


Conclusion
I've had a hard disk drive failure, it is hell. Once you've realise what a mess you are in, you reach for your backups. In my case at that time I had a problem with one of my backups, I couldn't restore everything. I had to use a data recovery program to pull the files off the crashed hard disk drive! It took hours and hours. Don't put yourself through this pain, follow at least the 321 backup rule and keep three backup copies, you will not regret it if that fateful day comes knocking. Be organised, think ahead and imagine the worst, then when you are hit with something just shy of 'the worst' you'll have a very nice smug feeling that you do everything possible.


References

A very good article explaining all of the Windows backup tools:
https://www.howtogeek.com/220986/how-to-use-all-of-windows-10%E2%80%99s-backup-and-recovery-tools/

Carbonite Cloud Backup Service
https://www.carbonite.com/

Western Digital Hard Disk Drives

The images used in this article are from Public Domain Vectors

Disclaimer
My advice is purely given as-is with no warranty or guarantee. I take no responsibility for any data loss.

24 Nov 2016

System Protection (Shadow Copy) - recover deleted files

On your Windows PC have you ever deleted a file and emptied it from the Recycle Bin, then realised that was a mistake? Unfortunately we've all been there! There is a feature built into Windows (from XP to 10) that is called System Protection or often it is known as Shadow Copy. In this article I'll explain what it is and how you can use it to recover your accidentally deleted files.


How it works
Periodically Windows will create a 'Restore Point', it is like a snapshot in time. If you install an application that creates a problem or maybe a virus destroys some of your system files, you can revert to the last good Restore Point, it is like going back in time to when your computer was functioning normally. This is the main purpose of System Protection.

NOTE: You should have local Administrator rights for the following.

Press the Windows key and
Enter: sysdm.cpl
The System Properties window will appear
Click the System Protection tab




System Restore
In the situation where system files have been damaged you can click the System Restore button and revert to a previous restore point. Your data files (photos, documents, music, etc) are not restored when you use this option. Only system files are restored.

Protection Settings
In the above example the computer has two local hard disk drives (or partitions), C: and D:. The C: drive is the system partition where Windows is installed. Because it is the system partition the C: drive is protected. However, System Protection is turned Off for the D: drive. This is an important consideration if you store files on a second hard drive or a second partition (a D: drive). You should consider turning the System Protection on for that second drive.

To change the settings for a particular drive, click on it and click Configure:


In the above example we're looking at the configuration for C:.

Turn on/off system protection
For this drive you can turn the system protection on or off. Normally it's a good idea to switch it on for all drives. As explained above, you might want to switch on protection for D: if you have a second partition as I do.

Disk Space
The System Protection is keeping copies of all the system and your files. That's a lot and there can of course be several versions. When it runs out of space it will replace the oldest restore point - it recycles the space. The more space you allocate to System Protection, the more restore points can be saved and the more files versions can be stored.

Delete
Normally of course do not use delete! If you do then all your restore points will be deleted. But there are situations where this is a very important option. Imagine your computer files were infected with a virus. After cleaning the virus and restoring all your data files, you should consider deleting your restore points. Why? Because you may have infected files in your System Protection restore points! Anti-virus software will not be able to scan inside the System Protection space so all kinds of nasties might be lurking there. Also, if you are about to sell your computer, make sure you delete your restore points before handing it over to the new owner.


The frequency that Restore Points are created
System protection is running all the time. It periodically creates Restore Points. In Windows 7 the default is once a week, for other operating systems I've not read anything definitive but as an example, the below is a screen shot of restore points from a Windows 8.1 computer:


In the Type column where it says Manual that is where I created a restore point manually (we'll look at how you can do that in a moment). For the others you can see that an automatic restore point was created by the system when I uninstalled Java 8. This is great, if that process of uninstalling had failed, I could've used the restore point to put the system back to how it was before.

Create a Restore Point manually
Despite the above that shows how Windows appears to be very clever, I would recommend that before installing new software or adding a new driver, you first create a restore point manually, just to be sure. It's easy to do, again do the following:

Press the Windows key and 
Enter: sysdm.cpl
The System Properties window will appear
Click the System Protection tab


Click Create
Enter the name of the Restore Point and click Create
It'll take a few seconds to make it, click Close when it has finished.


Task Scheduler
There is a task already in the Windows Task Scheduler. You could also change this to run it more often if you wish.

Search for "schedule tasks" in the Control Panel or launch it as follows:
Press the Windows Key and R
Enter: taskschd.msc


In the left hand navigation pane click Task Scheduler Library, Microsoft, Windows
Click on Windows Restore

Your screen should look similar to the above screen shot. From here you can double click the SR task to edit it. Click the Triggers tab and decide when you would like to run the task. Maybe once a week?


Previous Versions
In Windows 7 right click on a file, click Properties, click Previous Versions - wait a few seconds and a list of restore points for that file will appear.


In the above example you can see I have right clicked on a file called 'My Test File.txt' and one previous version is available. To recover it, click the Restore button.

This works very well for when you want to revert to a previous version of a file. If you delete a file and empty the Recycle Bin, then this is not so useful. The Previous Versions tab does not appear in Windows 8 and 8.1. For these reasons, although this is a nice feature to have and excellent for anyone to restore a previous version of a file, it is not ideal. This is where ShadowExplorer is the best option...


ShadowExplorer
If you have deleted a file and you need to get it back, no matter whether you are using Windows 7, 8 or 10, ShadowExplorer can do the job. It provides the best view of your Restore Points and all the files stored within them. ShadowExplorer is a free utility that you can download from
www.shadowexplorer.com

You can browse the different Restore Points and restore (export) the files from there.


When you first start ShadowExplorer it appears as above. Just click the C: to change drives. The different restore points and drop-down list next to the drive letter. In the above I have a restore point of 27/10/2016 selected.

Once you select a restore point you can navigate through the files on the drive just as you would in Explorer. When you want to restore a file select it, right click, click Export.

TIP: Download the portable version from www.shadowexplorer.com - you can copy it to a USB flash drive. In the event that your computer is infected with a virus or ransomeware, you could copy (export) files from your restore point to the USB drive to reduce the possibility of infection. ShadowExplorer should be in every IT technician's toolkit!

To discover more about ShadowExplorer there website has lots of information and there's also many Youtube videos to help.


Do NOT rely upon System Protection alone!
The System Protection copy of your files is stored on the same drive where your files exist (C: drive for example). This means that System Protection does not help you in the event of a drive failure. Also, ransomeware often deletes restore points.

You should not rely upon System Protection for your file backups. However, you can think of System Protection as your last line of defence.

For backups, if you have Windows 8, 8.1 or 10 please use the File History option - it is excellent and backs up your files as you make changes to them. Click the following link for an explanation:
http://www.pcworld.com/article/2974385/windows/how-to-use-windows-10s-file-history-backup-feature.html

For Windows 7 you can use the classic Windows Backup.
http://www.pcworld.com/article/186997/win7_backup.html


Conclusion
System Protection (Shadow Copy) can be a life saver. It's primary use is to protect your Windows system files. But keep it in mind the next time you accidentally delete a file, just don't rely upon it. System Protection should be just one part of your backup strategy. You should have multiple backups and different tools to cover the different 'disaster' scenarios.


Reference

ShadowExplorer
http://www.shadowexplorer.com/

A full explanation of the Shadow Copy technology:
https://en.wikipedia.org/wiki/Shadow_Copy

What are shadow copies - a further explanation:
http://www.howtogeek.com/129188/htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files/

Shadow Copy for advanced users:
http://www.howtogeek.com/129188/htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files/


3 Oct 2016

Command Window Here

When using File Explorer (Windows Explorer) for Windows 10, 8 or 7, have you ever wanted to open a command prompt (cmd)? It can be especially useful if the folder name is long, typing a long CD command is never much fun!

To open a command window on any folder, while in Explorer press Shift and right click:


Click Open command window here



16 Sept 2016

Breathe new life into an old computer


Do you have an old computer that is just sat around doing nothing? Maybe it still has Windows XP on it. Perhaps you really liked that computer and can't bring yourself to throw it out, besides, it still works, why not find a use for it?


Why?
The most common use of an old computer might be just for casual browsing the web. After all, you don't need a powerful computer to do that and often you just want to browse on a reasonably sized screen with a good old mouse pointer. If you use cloud services like Google Drive or OneDrive then you can access your files from anywhere. You might consider buying a Chromebook because it offers this kind of functionality but why not use that old computer you no longer use...


Consider
But before you blow the cobwebs off your old Windows XP computer and start browsing away... stop and consider a few things:
  • Windows XP, Vista and similar operating systems are not updated any more, there are no security patches. Using such a computer will leave you, your home network and your files vulnerable to attack by malware (malicious software such as viruses). 
  • Your old Windows XP or Vista computer is probably very slow due to lots of programs installed on it over time. Maybe it even has spyware or other nasties lurking on it, perhaps this is why you bought a new computer?
  • Older operating systems take a long time to start up. Windows XP would certainly take a couple of minutes or so and in that time you might just reach for your smartphone or tablet. To make your old computer truly useful it does need to be fast and accessible.

Recommendation
Because of the above points I have a recommendation, install a new operating system. In doing so everything on the computer is wiped clean. It will wipe off the old Windows XP or whatever you are using. Any previous malware will be removed. In software terms you will completely clean the computer from top to bottom. The advantage is that it'll run faster and maybe even just as smooth as it did when you first purchased it all those years ago.

IMPORTANT: Backup before you begin!
In the above paragraph I did say that installing a new operating system will wipe off all the existing software. That means your data files will be wiped too!!! So be careful, maybe check your old computer first, see if there are any old photos, documents, etc, that you might want to copy onto a USB flash drive before you install a new operating system on the computer.


New Operating System
Your old computer from five years ago wasn't designed to run Windows 10 and in any case it is likely you'd have to pay to buy it and it may not even work very well on your old computer. But fear not, to have an up-to-date operating system that costs nothing is easy, there are many available for download. Of course they are often based on the Linux operating system so the programs you are used to on Windows may not be available. However, on Linux you can get Chrome and Firefox. At least you are probably already familiar with those browsers and if all you'd like to do is some casual web browsing, all you need is a good browser.

Linux comes in different flavours called "distributions". Each distribution looks a bit different and has its own ecosystem. One of the most popular is Ubuntu. Ubuntu rivals Windows 10 for features and comes bundled with a lot of useful software such as a word processor, spreadsheet, etc. Ubuntu is also very well supported, with lots of software available in easy to install 'packages'. This is also true of driver support which means that typically it'll run on your old computer without a lot of fiddling.

However, I've found that Ubuntu can be sluggish on older computers. This made me look for alternatives. But I still like the simplicity of installing and support there is in the world of Ubuntu.


Lubuntu
Lubuntu is a 'lite' version of Ubuntu. The interface is different but the underlying operating system is the same. This means it's easy to install and use. You'll get all the support and security updates as Ubuntu but Lubuntu will run faster on your old computer hardware. That's the theory, I tried it out for myself.

Lubuntu running Firefox
The above shows Lubuntu running Mozilla Firefox. Chromium is installed as standard but Firefox can easily be downloaded and installed - use the package available for Ubuntu.

I have a Lenovo Thinkpad X300 dating from around 2008. It has 2GB RAM and it's a 32-bit computer only. It's still working well, a very nice computer, good keyboard, well built and a good size. It is from the era of Windows Vista although originally I ran Windows XP on it. I first tried Ubuntu on the X300 and it worked well. The most important thing is that Ubuntu recognised the audio, the screen, the WiFi adapter, etc. This is important because I didn't want the hassle of looking for the drivers and installing them - that kind of thing can take time and with Linux can sometimes be a bit of a pain. With Ubuntu everything just worked immediately! But my X300 was a bit slow with Ubuntu.

I replaced Ubuntu with Lubuntu and my X300 works faster. I still have the compatibility and updates of Ubuntu (anything marked as compatible with Ubunbtu is compatible with Lubuntu). I've not really lost anything. Right now I am writing this blog article on the X300 with Lubuntu and Firefox. There's no lag in general or with connecting to WiFi. It all works rather well! The interface is similar to Windows, there's a Start Menu for example. It's a very clean interface and there are lots of software applications pre-installed.


From the above screen shots you can see how Lubuntu has a nice clean interface. I think it's easy to use and not a huge leap for a Windows user new to Linux. There's a Trash can that acts like the Recycle Bin. The main menu is like the Start Menu and the Home is like Windows Explorer or My Computer.

To download and learn more about Lubuntu please visit website here:
http://lubuntu.net/


Installation
Here are a few tips on installing Lubuntu:

  • Download from http://lubuntu.net/ and click Download
  • I would recommend you use the 32-bit version as it is less heavy on resources and in most cases your computer will only support 32-bit anyway. For me with my X300, it's 32-bit.
  • You can install using a DVD or USB flash drive. I would recommend the USB flash drive as it is faster and sometimes with old computers the DVD drive doesn't work or is unreliable.
  • For USB a 4GB USB flash drive is recommended. Before you begin make sure the USB flash drive is empty - everything on it will be deleted so make sure you don't have any files on the USB flash drive before you start, copy them somewhere safe first!
  • You'll need to download a small utility called UNetbootin available from http://unetbootin.github.io/
  • With UNetbootin on a Windows computer you can write the Lubuntu installation ISO file to the USB flash drive.
  • When you start the installation I recommend you choose to replace the entire contents of the C: drive with Lubuntu. Select the default partition options. Of course, as mentioned before, this does destroy everything you currently have on your old computer, make sure you first backup any files you want to keep. 
Full instructions on installing Lubuntu can be found here:
https://help.ubuntu.com/community/Lubuntu/InstallingLubuntu

Follow the steps on the above page and you'll be fine. It is much less complicated than it may first appear.


Alternatives to Lubuntu
Ubuntu of course but there are many others such as Puppy Linux, MintOS, etc. If you have a NetBook like an ASUS Eee PC, consider EasyPeasy.

If you don't mind having to tinker a little, I recommend Crunchbang. It's not as user friendly or as polished as Ubuntu/Lubuntu. But it does work on very old hardware, here's an article I wrote explaining how I installed it on an old IBM T42 and an ASUS Eee PC:
http://mgxp.blogspot.com/2013/03/crunchbang-linux.html

I wrote a number of articles about how to set it up, share files and work with Crunchbang, you can find them here:
http://mgxp.blogspot.com/search/label/Crunchbang

In recent times Crunchbang almost died but it was rescued by a new team of developers and you can find out all about the new Crunchbang++ here: https://crunchbangplusplus.org/
I've not tried this new version yet but when I do, I'll be sure to write something here on my blog.


Conclusion
If you do have an old computer, installing Linux on it makes a lot of sense. You can use it for some basic browsing, writing letters, etc. If you use Lubuntu the process of installing, using and maintaining the old computer is relatively easy. Lubuntu is a very polished professional operating system, it's fast and has a clean modern look. It's close enough to Windows for it to be a good place to start if you are new to Linux. Have a go and I'm sure you'll be happy surfing with some speed on that ancient computer you had previously written off.


Disclaimer
I do not accept any liability for any loss of data or problems you may face. Proceed at your own risk! Of course if it's an old computer then the risk is not high but please don't blame me for anything that goes wrong, I am just here writing about my own experience and opinion. I hope I've been able to help and inform, that is all. Good luck and feel free to write you own experiences in the comments below :-)

6 Jun 2016

RoboBackup7z - an AutoIt script to backup files using Robocopy and 7za


Previously I wrote an AutoIt script called RoboBackup. That script used Robocopy to automate backing up files into three (or more) folders. It cycled through those folders synchronising files each time.

In this article I am going to explain a slightly more advanced script that also backs up files but does so by using both the Robocopy command and also the 7-Zip 7za.exe command line program. I've called this backup script 'RoboBackup7z'.

The idea behind RoboBackup7z is that the latest backup is a synchronised folder managed by Robocopy. But previous Robocopy backups are archived in 7z files for safe-keeping. This means the latest data is easy to recover and the previous backups are still available but are smaller compressed files you could copy elsewhere - to DVD or cloud storage perhaps.

First let's have a look at how this script works and after how it is put together. I hope you'll find this interesting.


Setup
The idea is that you create a folder on a removable drive or USB flash drive and run the script from there. In the following screen shot you can see my example:


In the above example I have an external USB hard disk drive that is drive G: on my computer. I am backing up files from my D: drive (source) and so I've created a folder called "D" (I could've called it anything but this makes sense to me).

Inside the "D" folder I have the following files:

  • 7za.exe
  • RoboBackup7z.au3
  • RoboBackup7z.exe
  • RoboBackup7z.ini


Edit RoboBackup7z.ini


Add a folder to backup. This can also be a drive letter, in our example we'll use D:. This backs up all folders and files found on drive D:.


Run
Double click RoboBackup7z.exe

The first time it runs the following will be created:

  • A folder called Backup where a copy of the folders and files will be made.
  • A log file named yyyymmdd_hhmmss_LOG.txt (the RoboCopy log showing what was backed up).

The second time it runs the following happens:

  • A folder called Archive is created
  • 7-Zip runs, it adds all the folders/files from the Backup folder to a 7z archive file in the Archive folder.
  • It names the 7z with the name of the last backup log file (it gets this from the ini).
  • It splits the 7z file into 300MB separate files.
  • The log file is moved to the Archive folder.
  • RoboCopy runs again, the Backup folder is updated with new files, a new log file appears in the script folder.

The third time it runs:

  • The same as the second time, a new 7z is created and stored in the Archive folder with the log file. RoboCopy runs again to update the Backup folder and create a new log file.


In the above example I have run the script more than twice. The Backup folder contains the files of the latest copy and the Archive folder contains the 7z files. The log is the latest log file.

Here's what it looks like inside the Archive folder:


In the above screen shot you can see the txt files are the logs. You can open these in Notepad. They are the original log files produced by Robocopy when it originally ran.

The other files are the 7z files. They are in 300 MB chunks. To view and extract files open the first one (001) with 7-Zip for Windows.

IMPORTANT: There is no control over how much disk space is used or how many backups can be made. You must manage the disk space yourself. Move files from the Archive folder to another location as needed.


Source Code
In the following screen shot you'll see the code as I see it when I writing it. On the left hand side you can see the line numbers. Below the image I'll explain line by line what the script does but first a few basics, here's how the colour coding works:

Green - comments, text to explain what the script is doing. Therefore lines 1 to 11 is just for information.
Black - variables, they also start with a dollar sign $
Blue - functions like IF.
Orange - operators like <>=
Red - text



--- Line 15
This defines the $ini variable that identifies the RoboBackup7z.ini file. It's a configuration file containing the drive/folder to backup and the name of the last log file.

--- Line 17 to 25
These are the variables and what their initial values are. This includes reading data from the ini file.

--- Line 27 to 39
First this checks if the 7za.exe exists. If it does not, it'll skip this part.
If 7za.exe does exist then it'll check for the destination folder (Backup), if this exists then it'll run the 7za program to archive the files from the destination (Backup) folder.

--- Line 32
This is the 7za line. It compresses the files from the Backup folder into one or more 7z compressed (zipped) files. The 7za.exe has a number of parameters:

-r = recurse, meaning to archive sub-folders/files

-v300m = this splits the 7z archive file into smaller files (volumes). In this case we're splitting to 300MB files. You can change this to any size that fits your needs. If you do not use this parameter then the archive will be one large 7z file. Such a file might be very big, depending on what files you have to backup, larger than 2GB, therefore it makes sense to split to smaller files to make them easier to copy. Many services do not support files larger than 2GB.

--- Line 36 and 37
These copy the log file to the Archive folder. This is so the log is stored along with the backup it was made from.

--- Line 42
Save the date (name of the log file) to the ini file. This so it can be used the next time the backup runs to identify the 'last' backup.

--- Line 45
Runs ROBOCOPY to synchronise files from the source to the backup (destination) folder.

--- Line 57
Open Notepad and display the log file. This will happen at the end and shows you what has happened during this backup. It's the usual output from Robocopy.

--- Line 59
Exit just closes the script. You don't really need this but usually put it just to show where it ends.


My RoboBackup7z Script Source Code for Copy/Paste
Here's the same script as shown above in the screen shot. But this time it's text so you can copy/paste it and use it. Feel free you change it :-)

#cs ----------------------------------------------------------------------------

RoboBackup using 7-Zip

 AutoIt Version: 3.3.10.2
 Author:         Michael Gerrard / http://mgxp.blogspot.com

 Script Function:
 Create a backup using Robocopy and archives using 7-zip

#ce ----------------------------------------------------------------------------


; Set variables
$ini   = @ScriptDir & "\RoboBackup7z.ini"

$FolderToBackup = IniRead($ini, "Settings", "FolderToBackup", @MyDocumentsDir)
$source     = '"' & $FolderToBackup & '"'
$dest   = @ScriptDir & "\Backup"
$archive  = @ScriptDir & "\Archive"
$today   = @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC
$log      = @ScriptDir & "\" & $today & "_LOG.txt"
$7za   = @ScriptDir & "\7za.exe"
$last   = IniRead($ini, "Settings", "LastBackup", "00000000_000000")
$7zBackup  = $archive & "\" & $last

; Check if a backup was done before, if so, archive it to a 7z file
If FileExists($7za) Then
 If FileExists($dest) Then
  DirCreate($archive) ;make sure the archive folder exists

  RunWait(@ComSpec & " /c " & $7za & " a -r -v300m -w -y " & $7zBackup & " " & _
  $dest & "\*.*", @ScriptDir, @SW_MINIMIZE) ; add to 7z archive file

  ; Move the log to the archive folder
  FileCopy(@ScriptDir & "\" & $last & "_LOG.txt", $archive)
  FileDelete(@ScriptDir & "\" & $last & "_LOG.txt")
 EndIf
EndIf

; Write today's date and time to the ini
IniWrite($ini, "Settings", "LastBackup", $today)

; Run RoboCopy
RunWait(@ComSpec & " /c ROBOCOPY " & $source & " " & $dest & _
" /MIR /R:2 /LOG:" & $log & " /TEE" & " /XF desktop.ini ", @ScriptDir, @SW_MINIMIZE)

; /MIR = mirror
; /R:2 = retry twice
; /LOG: = record to a log file
; /TEE = output to the screen too
; /XF desktop.ini = don't copy the desktop.ini file (avoids getting the My Documents folder name)

; Display the log file
If FileExists($log) Then
 Run("notepad " & $log)
EndIf
Exit


Other required files
For the script to work you'll need Robocopy, this command is included with Windows as standard. Also you'll need the 7za.exe file, you can download it free of charge from http://www.7-zip.org/
For more detailed information please see the following article:
https://mgxp.blogspot.ch/2016/04/7-zip-7za-command-line-zip-tool.html


Conclusion
It's amazing what you can do with free tools! AutoIt is of course the easiest way to make a script that's compact and simple. Just look at how few lines of code I used. Robocopy and 7za too, excellent. This script works very nicely and I've been using it for several months now. But it has some shortcomings. For instance, I have to manage the disk space myself. Also it only backs up from one location (drive or folder location and sub-folders). But this is fine, it means I have more work to do in the future!


Disclaimer
The script here is just an example. I do not provide it with any guarantee. I'm not advocating this script be used for anything specific, this article is just to demonstrate what can be done. Use at your own risk! 


Reference

AutoIt
https://www.autoitscript.com

Robocopy at Wikipedia
https://en.wikipedia.org/wiki/Robocopy

Various articles about Robocopy
https://mgxp.blogspot.ch/search/label/Robocopy
7za, the 7-zip command line program

If you are looking for some help with creating self-extracting archives, please see my previous articles specifically on this more advanced subject:
PART 1 - http://mgxp.blogspot.com/2010/07/create-self-extracting-archive-exe.html
PART 2 - http://mgxp.blogspot.com/2013/01/create-self-extracting-archive-exe-part.html

27 Apr 2016

7-Zip 7za command line zip tool

7-zip is an alternative to the native Windows zip function, WinZip or similar program for compressing files. 7-zip is free of charge, reliable and supports many formats. I wrote an article about it back in 2010, here's the link: https://mgxp.blogspot.ch/2010/06/review-7-zip.html

7-zip is primarily a Windows application, with a graphical user interface. Normally that's fine and often it's enough to manage your compressed files. However, sometimes it would be nice to automate the compressing of files. Maybe you want to backup files by just double clicking a file? In this case you can use 7za.exe, a command line program.

This article is an introduction to the 7za.exe command line tool. We'll have a look at how to download it and as an example we'll see how we can use it to backup files to a removable drive.


Download
Browse to https://www.7-zip.org/
Download and install the 7-zip Windows program.

On the same web page, on the Downloads page look for '7z Library, SFXs for installers, Plugin for FAR Manager' - click to download the 7zXXX_extra.7z file.

7z is the native compressed format of 7-zip, you can open it using the 7-zip Windows program you just installed. Extract the files to a folder. In the folder you'll find a file called 7za.exe. You don't need all the other files, you can just copy this one 7za.exe file and use this for your command line projects.


Example: Simple Backup
In this example I have a local D: drive with a folder called 'source' where I have some important files I want to backup. I have a USB flash drive that is drive E.
  1. Insert a USB flash drive
  2. Copy the 7za.exe file to the USB flash drive (for example)
  3. Open a command window (press Win-R, type CMD and press Enter)
  4. At the command prompt change to the USB drive where you put the 7za.exe file (in our example I will type E: [Enter] because my USB drive is drive E)
7za u -r "backup" "d:\source\*.*"       [Enter]


Example: backing up files from the local D: drive to a file called "backup" on the E: (USB drive)

The above command will take all the files in D:\source, compress and copy those files to a called backup.7z on my USB flash drive (drive G: in my case). Later if I update files in D:\source I can use the same command to update the backup.7z file. 

Let's have a closer look at the commnad line parameters we used: 

This means to update, only those files that have changed will be added/updated in the 7z file. 

-r
This means to be recursive, it will copy all files from the source folder and sub-folders. 

"backup" 
In our example this will create a compressed archive file. All the files from the source folder will go inside this one compressed file. By default 7za will use its native 7za format, which is recommended. 

"d:\source\*.*" 
The files to backup, combined with the -r parameter it means that any folders/files below this folder will also be included. 


Command File (batch file) 
To make your life easier you can put the command line into a file and save it with the 7za.exe file on your USB drive. Whenever you need to backup those files just double click the command file. 

Open Notepad and enter the following two lines: 
7za u -r "backup" "d:\source\*.*" 
pause 

Save the file as 7zaBackup.cmd 


At any time you can double click 7zaBackup.cmd to run your backup. 


Help 
At the command prompt you can type:
7za -h   [Enter]
...to get a list of parameters. More help is available at https://www.7-zip.org


Reference 
If you are looking for some help with creating self-extracting archives, please see my previous articles specifically on this more advanced subject: 

An alternative for backing up files using the command line is RoboCopy. Click the following link to find many articles about this powerful tool: https://mgxp.blogspot.com/search/label/Robocopy