Windows

TOPICS


July 2019

  Clean recycle bin for all users
July 20   |   Windows

The Emergency 🔔

Notification, there is an emergency, you need to connect to a remote desktop to run some transact SQL queries, you do it, press F5 and … 💥


An error occurred while executing batch. Error message is: There is not enough space on the disk....

You realize that there isn't enough space on C - nothing, zero, nada - It turns out that SSMS needs space to write some temp files on C:\Users\...\AppData\Local\Temp so it can process the results of your query.


Your first reaction, of course, is to clean temp files, your recycle bin, old documents, maybe execute the cleanup wizard in windows but if you are lucky you'll get only a few megabytes

WinDirStat

Suddenly you remember this amazing app WinDirStat, so you install it and let it do its work. Thanks to this, you'll find two issues:

Clean Recycle Bin for Everybody


Issue 1. Your partners aren't careful with their recycle bins

Open your terminal as administrator and run :

 Clean recycle bin

            

rd /s c:\$Recycle.Bin
            
            
        

If somebody complains you could tell: Don't blame me, it was in the recycle bin for a reason

Windows Installer Folder


Issue 2. Windows is messy with the cleanup of \Windows\Installer folder

This should be addressed more carefully, it's a known issue that Windows Installer folder gets big especially when you install a lot of applications and share your machine with more users In short, the issue is that when you uninstall an app, their update / installation package is not always deleted It is supposed that you shouldn't touch this folder because could lead to update or install issues, but as always is a trade off, you should proceed carefully.

So the fix is to find orphaned installation/update files that belong to apps that are not installed anymore in the system.

Manually run the next VBA Script that shows the files that we should KEEP in the system, everything that is not in the output file could be deleted

 VBA Script

            

'' Identify which patches are registered on the system, and to which
'' products those patches are installed.
''
'' Copyright (C) Microsoft Corporation. All rights reserved.
''
'' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
'' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'' PARTICULAR PURPOSE.

'Option Explicit

Dim msi : Set msi = CreateObject("WindowsInstaller.Installer")

'Output CSV header
WScript.Echo "The data format is ProductCode, PatchCode, PatchLocation"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("output.txt", True)
objFile.WriteLine "ProductCode, PatchCode, PatchLocation"
objFile.WriteLine ""
' Enumerate all products
Dim products : Set products = msi.Products
Dim productCode

For Each productCode in products
' For each product, enumerate its applied patches
Dim patches : Set patches = msi.Patches(productCode)
Dim patchCode

    For Each patchCode in patches
    	' Get the local patch location
    	Dim location : location = msi.PatchInfo(patchCode, "LocalPackage")
        objFile.WriteLine productCode & ", " & patchCode & ", " & location

    Next

Next
WScript.Echo "Data written to output.txt, these are the registered objects and SHOULD be kept!"
            
            
        

Thanks to Raymond.cc for the article, you could explore the article to find other ways to clean up the windows installer folder.


Hopefully, with these two tips you could claim precious space for your computer

April 2019

  Use cmder as your default terminal in vscode
April 4   |   Vs

Cmder is a powerful console emulator that has a lot of features and brings some of the joy of working in terminal from macos/linux to windows. I've been using it for a while and always forget how to configure in visual studio code, so, follow these two steps to configure as default terminal:

  1. Create a bat file in your Cmder folder

     vscode.bat

                
    
    @echo off
    SET CurrentWorkingDirectory=%CD%
    SET CMDER_ROOT=C:\cmder
    CALL "%CMDER_ROOT%\vendor\init.bat"
    CD /D %CurrentWorkingDirectory%
                
                
            

  2. In VSCode open configurations and setup the next json values | Use Ctrl + , to open settings.json

     settings.json

                
    
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vscode.bat"],
    "terminal.integrated.fontFamily": "Fira Mono for Powerline", /_ Font is optional _/
                
                
            

March 2019

  Map a folder to a drive in Windows
March 18   |   Windows

An old DOS command will allow us to map a directory to a drive in windows. This could be useful in many scenarios (). There are two commands that we can use:

subts

 subts

            

REM to create
subst X: "C:\Users\LuckyDeveloper\MyFolderToMap"
REM to delete
subst X: /D
            
            
        
  • Drive name must be followed by a whitespace
  • If the target folder has whitespace in its name, use quotes “\directory withe white spaces"
  • Notice that at the end of the command we don't use the character “\

✍️ This command expects that the folder is always present, be aware of this so you don't impair the performance of your machine

✍️ The map will reset with every restart, to keep it between restarts add it to windows start folder C:\Program Data\Microsoft\Windows\Start Menu\Programs\Startup

🔗 (WindowsKey + R, type: shell:common startup)

net use

net use D: \\SomeNetHost\c$\Users\LuckyDeveloper\MyFolderToMap

✍️ net use is more fault-tolerant about folder availability, so is better to use with network shared resources.