Category Archives: Operating Systems

How to Copy, Move, Replicate, Augment or Delete Files and Folders using Commands on Windows

Motivation:

  • You have a web application the backup of which needs to be  created daily.
  • You have a web application the content of which needs to be replicated daily.
  • You have data folder the content of which needs to be augmented daily.

Commands:

  • Copying files and folders inside one folder to another:
robocopy E:\inetpub\wwwroot\website.domain.com E:\inetpub\wwwroot\backup.domain.com /e

/e Copies subdirectories. This option includes empty directories. 

robocopy \\192.168.1.49\E\inetpub E:\inetpub /e
  • Moving entire folder to another location:
PS C:\> Move-Item -path \\192.168.1.15\e\inetpub\ -destination E:\ -force

where PS C:\> is PowerShell.
  • Moving new files and folders inside one folder to another:
robocopy E:\inetpub\wwwroot\website.domain.com E:\inetpub\wwwroot\archive.domain.com /move /e

/move Moves files and directories, and deletes them from the source after they are copied.
  • Copying (mirroring) entire data from one drive to another, including file and folder permissions:
robocopy E:\ G:\ /MIR /COPYALL /ZB /W:1 /R:2 /XO

or

robocopy E:\ G:\ /TEE /LOG+:F:\robolog.txt /MIR /COPYALL /ZB /W:1 /R:2 /XO

E:\
 - Source folder. This can be a UNC path.

G:\
 - Destination folder. This can be a UNC path.

/TEE
 - Display the output of the command in the console window and write it to a log file.

/LOG+:F:\robolog.txt
 - Write the logs to F:\robolog.txt. The + sign means appending the content to the log file.

/MIR
 - Copy all files and subfolders, remove files and folders from the destination if they no longer exist on the source.

/COPYALL
 - Copy all of the NTFS permissions and attributes (security permissions, timestamps, owner info, etc.)

/ZB
 - Use restartable mode when copying files. If a file is in use, retry after a set amount of time (see /W:1 and /R:2). If access is denied then try to copy in backup mode.

/W:1
 - Wait for 1 second between retries when copying files.

/R:2
 - The number of retries on failed copies.

/XO
 - eXclude Older files/folders if the destination file or folder exists and has the same date.
If destination file exists and is the same date or newer than the source - don't bother to overwrite it.
  • Augmenting files and folders (making an incremental backup) from one drive to another, including file and folder permissions:
robocopy E:\ G:\ /E /COPYALL /ZB /W:1 /R:2 /XO /XX

or

robocopy E:\ G:\ /TEE /LOG+:F:\robolog2.txt /E /COPYALL /ZB /W:1 /R:2 /XO /XX

/E
 - Copy Subfolders, including Empty Subfolders.

/XX
 - eXclude "eXtra" files and dirs (present in destination but not source). This will prevent any deletions from the destination.
  • Granting Full control to a user or group:
icacls "E:\inetpub\wwwroot\website.domain.com\App_Data" /grant "IUSR":(OI)(CI)F /T

icacls "E:\inetpub\wwwroot\website.domain.com\App_Data" /grant "IIS_IUSRS":(OI)(CI)F /T

CI
 - Container Inherit - This flag indicates that subordinate containers will inherit this ACE (access control entry).

OI
 - Object Inherit - This flag indicates that subordinate files will inherit the ACE.

OI and CI only apply to new files and sub-folders).

F
 - Full Control

/T
 - Apply recursively to existing files and sub-folders.
  • Deleting and creating a folder:
rmdir "E:\inetpub\wwwroot\website.domain.com\Temp\" /S /Q 
mkdir "E:\inetpub\wwwroot\website.domain.com\Temp\
  • Recursively deleting all files in a folder and all files in its sub-folders:
cd C:\inetpub\wwwroot

del /s *.log /s
 - delete all the files in the sub-folders.


del /s /f /q *.* /f
 - force deletion of read-only files.

/q
 - do not ask to confirm when deleting via wildcard.
  • Recursively deleting a folder, its files and its sub-folders:
rmdir .\force-app\main\default\objects /s /q /s
 - delete all the files in the sub-folders.
  • Enabling long paths and file names: For Windows 10, Version 1607, and Later: Open Group Policy (gpedit.msc) and go to Computer Configuration > Administrative Templates > System > Filesystem. Set “Enabling Win32 long paths” to “Enabled“. Restart the machine. Then use command below:
PS C:\> Move-Item -path \\192.168.101.157\e\Files\ -destination E:\ -force
  • Removing a drive letter from a volume:
mountvol F: /D

/D
- remove the drive letter from the selected volume.

Anti-Virus vs. Anti-Malware

What is the difference between anti-virus software and an anti-malware software?

A virus is a piece of code that is capable of copying itself in order to do damage to your computer, including corrupting your system or destroying data.

Malware, on the other hand, is an umbrella term that stands for a variety of malicious software doing damage to your computer or stealing your information, including Trojans, spyware, worms, adware, ransomware, and yes, viruses.

So the logic follows: all viruses are malware. Not all malware are viruses.

Anti-virus software generally scans for infectious malware which includes viruses, worms, Trojans, rootkis and bots.

Anti-malware software generally tends to focus more on adware, spyware, unwanted toolbars, browser hijackers, potentially unwanted programs and potentially unsafe applications.

Therefore, you need both an anti-virus and an anti-malware solution for maximum protection.

Built-in Windows Defender provides both anti-virus and anti-malware protection, and IMO, is enough for non-tech-savvy users.

A comprehensive FREE anti-virus software is AVG.

A comprehensive FREE anti-malware software is Malwarebytes

An ads blocker for Edge browser is uBlock Origin

An ads blocker for Firefox browser is Adblock Plus

How to Remove Microsoft .NET Framework

Problem:

Some applications do not work with the latest Microsoft .NET Framework. You need to remove it and install an older version of Microsoft .NET Framework.

Solution:

1. Use below utility to remove the current Microsoft .NET Framework.

.NET Framework Cleanup Tool

2. Download an appropriate version of Microsoft .NET Framework using one of below links and install it.

3. Use below utility to detect the installed Microsoft .NET Framework versions.

.NET Detector

How to Find and Remove Windows Hot Fix

Motivation:

You have an application that had been working well but it has encountered issues after you applied a Windows hot fix.

You need to list your latest Windows hot fixes and uninstall the one that causes the issue so that your application can work again.

Procedure:

1. Right click Start icon, click on Command Prompt (Admin) or Windows Powershell (Admin).

2. Type below command and press Enter to list the Windows hot fixes.

Get-Hotfix | Sort-object InstalledOn -Descending

3. Type below command and press Enter to uninstall a hot fix. Please note that the hot fix id does not contain KB.

wusa /uninstall /kb:4058702

Some other useful commands:

  • Geting the Windows original install date.
systeminfo | find /I "Install Date"

Alternatively, you can use below command to get the Windows original install date.

([WMI] "").ConvertToDateTime(((Get-WmiObject -class win32_operatingsystem).installdate))
  • Displaying Windows OS information.
systeminfo | findstr OS
  • Detecting Manufacturer name & Model number.
wmic computersystem get model, name, manufacturer, systemtype

 

 

 

How to Install Windows on your MacBook using Boot Camp

Motivation:

You have a MacBook and you want to use an application that only works on Windows.

Prerequisites:

  • Boot Camp requires MacBook model which has an Intel processor. Please ensure that your MacBook model is one of the following models listed here.
  • On your MacBook, click Apple icon, then click About This Mac, and ensure that an item labeled Processor, not Chip, is shown, as described here.

Procedure:

1. Update your MacBook
  • Ensure that your macOS is up-to-date and does not have any issue.
  • If you want to reinstall macOS then you can hold down Command+R after powering your machine on.
2. Install Windows on your MacBook using Boot Camp

On macOS:

  • Finder > Shift+Command+u > Boot Camp Assistant
  • Select 350Gb (or another appropriate size) for Windows. Use Windows 10 version 1909, April 2020 or Windows 10 version 1709, November 2017.
  • Remove unnecessary macOS applications (e.g. Numbers, Pages, Garage Band) if you want to use as much as possible storage for Windows.
  • Install Windows 10.
    – DO NOT USE Disk Management to create new partitions during Windows installation. Only use Disk Management to format an existing partition when installing Windows.
    – During the next boot into OS X, the OSXRESERVED partition is removed and put back into the Core Storage container of the OS X partition.

On Windows:

  • Install Boot Camp drivers.
  • Click Boot Camp icon. Click Boot Camp Control Panel… > TrackPad > Tap to Click > Apply > OK.
  • Change Computer Name, disable System Protection, enable Remote Desktop, activate Windows.
  • Optionally press Win + R and type “msconfig” then click OK. Then Select the Boot tab and delete unnecessary OS boot item.
  • Turn on Automatic Logon
    Command Prompt (Run as Administrator) >> netplwiz
  • Disable Hibernate
    Command Prompt (Run as Administrator) >> powercfg.exe /hibernate off
  • Power management > Change plan settings > Change advanced power settings
    >> Hard disk > Turn of hard disk after > Never
    >> Sleep > Sleep after > Never
  • Adjust System > Display > Brightness and color.
  • Uninstall unnecessary apps.
  • Use Disk Management to shrink the BOOTCAMP partition and create a new DATA partition. Use 150Gb (153600MB) as the amount of space to shrink.
  • Check and install Windows updates.
  • Copy portable apps.
Installing developer’s tools:
  • Turn the following Windows features on: ASP.NET 3.5, 4.7, Internet Information Service, Telnet Client
  • Install Hyper-V, create an external Virtual Switch for Internet access
  • Install Total Commander, Remote Desktop Connection Manager
  • Install Firefox
  • Install MS SQL Server 2008 R2, MS Office 2007 SP3 (Display >> Scale and layout: 175%), MS Project 2016, MS Visio 2016, Visual Studio 2010, Visual Studio 2015, Adobe Acrobat Pro DC v15.8, Adobe Photoshop CC 2015, TortoiseSVN 1.11.1
  • Install Python 3.6.8, TensorFlow, Keras
3. Remove Windows from your MacBook using Boot Camp

On Windows:

  • Delete all Windows Data partitions, then Extend the Boot Camp volume (C:\) using Windows Disk Management.

On macOS:

  • Finder > Shift+Command+u > Boot Camp Assistant > Continue > Restore
  • If you get any problem with Boot Camp Assistant then delete Windows Boot Camp partition using Disk Utility: Finder > Shift+Command+u > Disk Utility > Partition.
  • If you get a “Ghost” partition after deleting Windows Boot Camp partition using Disk Utility then please use the following procedure to remove it:

Execute below command:

diskutil list

Find EFI IDENTIFIER (e.g. disk0s1).

Execute 2 below commands:

sudo mkdir /Volumes/efi
sudo mount -t msdos /dev/disk0s1 /Volumes/efi

Navigate to /Volumes/efi/EFI. Delete all directories (i.e. Microsoft and Boot) except the APPLE directory.

Execute below command:

diskutil unmount /Volumes/efi
4. Repair or update Boot Camp drivers on Windows
  • Download and install 7-Zip.
  • Download Brigadier 0.2.4.
  • Run Brigadier to automatically detect your Mac model and download the right Boot Camp drivers for Windows 10, and extract them (using 7-Zip) to the same location where Brigadier executable is located.
  • Find and double-click on Setup.exe to run it.

 

How to Force Uninstall a Program That Won’t Uninstall

Issue:

You installed a program. Now you want to uninstall it. You open up the Apps & Features (in Windows 10), click on the program name, click Uninstall button and you get an error. The program cannot be uninstalled.

Solution:

Method 1:

Use Windows Installer CleanUp Utility (given by Microsoft) to uninstall the program.

Method 2:
  1. Type regedit in Cortana and click on the program.
  2. Find the program name. For example JetBrains.
  3. Continue finding the program by pressing F3 until you find it under the sub-folder HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall or the sub-folder Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall (you verify this path by looking at the path under the top menu and looking at the DisplayName in the right panel).
  4. Copy the value of the key UninstallString.
  5. Type run in Cortana and click on Run application.
  6. Paste the value of the key UninstallString and click OK.
  7. If you still get the error then just delete the sub-folder under the sub-folder HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall or the sub-folder Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall.
  8. Restart your computer.

How to delete the Windows.old folder

Motivation:

After a major update Windows 10 leaves a folder named Windows.old in the system drive. You may remove it to save disk space and prevent potential harmful exploits.

Solution

Method 1:

  1. Click in Windows’ search field, type Cleanup, then click Disk Cleanup.
  2. Click the “Clean up system files” button.
  3. Wait a bit while Windows scans for files, then scroll down the list until you see “Previous Windows installation(s)“.
  4. Check the box next to the entry.
  5. Click OK.

Method 2:

  1. Open a command prompt (cmd.exe) as Admin
  2. Execute 3 below commands:
takeown /f C:\Windows.old /r /d y
icacls C:\Windows.old /grant administrators:F /t
rmdir C:\Windows.old /s /q

takeown: takes ownership of a folder.

icacls: grants permissions to a user against a folder

rmdir: deletes a folder

3. If some files still cannot be deleted then please restart your computer and re-excecute the above 3 commands.

4. If some files still cannot be deleted after the restart then please execute 3 below commands:

icacls C:\Windows.old /T /Q /C /RESET
icacls C:\Windows.old /grant admin:F /t
rmdir C:\Windows.old /s /q

admin: your current logged in username.

5. If some files still cannot be deleted then please click Cortona icon, type msconfig, click on System Configuration link, click Boot tab, select Safe boot check box,  select Minimal option, click OK, restart your computer and then execute the 3 commands in the 2nd step and the 3 commands in the 4th step.

How to find a string in files

Motivation:

Find a string in all files in a directory without having to install an external program that may decrease system security.

Method 1:

  1. Open a command prompt (cmd.exe)
  2. Go to the directory and
  3. Execute below command:
find /i "search string" *.*

/i: ignores the case of your search string.

Examples:

find /i "app files were copied" *.*
find /i "were copied" *.log

Method 2:

  1. Open a command prompt (cmd.exe)
  2. Go to the directory and
  3. Execute below command:
findstr /s "search string" *.*

/s: searches for each word in your search string.

or execute below command:

findstr /C:"search string" *.*

/C: searches for exact match of your search string .

Examples:

findstr /s "Integrated Security=true" *.cs
findstr /C:"app files were copied" *.log