Windows

From TheBeard Science Project Wiki
Revision as of 14:53, 20 May 2019 by Beard (talk | contribs) (Saving Disk Space)

Jump to: navigation, search

Batch Scripts

Ping Test a List of Hosts

This crap gave me such a headache because you need ENABLEDELAYEDEXPANSION to increment the counter, but you then can't get errorLevel from a command. I hate batch. This script takes a line-delimited list of hostnames or IPs, pings them, gives an UP/DOWN status for each, then reports the total number of down hosts.

Sample file:

server1
w101.mynet.local
127.0.0.1

Batch script:

@echo off

rem -- Location of line-delimited list of hostnames
set "HOSTLIST=C:\Users\username\Desktop\hostlist.txt"

rem -- Prevent evaluating the entire loop before it's executed
setlocal ENABLEDELAYEDEXPANSION

rem -- Loop through the list of hosts
for /f "tokens=*" %%H in (%HOSTLIST%) do (
	echo Pinging %%H ...
	set ERRLVL=0
	ping -n 3 %%H >nul || set ERRLVL=1
	if /i "!ERRLVL!" equ "1" set /a HOSTSDOWN+=1 & echo DOWN
	if /i "!ERRLVL!" equ "0" echo UP
)

rem -- Print a report 
echo.
if "%HOSTSDOWN%" gtr "0" (
	echo Ping results^: There are %HOSTSDOWN% hosts DOWN.
) else (
	echo Ping result^: All hosts are up.
)

endlocal

pause

CMD Tips and Tricks

Fullscreen CMD Window

To fullscreen cmd on Windows 7/8/10:

  1. Open cmd
  2. type "wmic"
  3. Fullscreen the window
  4. type "exit"

Active Directory

A few commands:

netdom query fsmo - list FSMO roles
netdom query dc - list domain controllers
nslookup -type=srv _gc._tcp.domain.local - find global catalog server
dcdiag /q - query and test domain functions
dcdiag /fix - attempt to repair errors
gpresult - query group policy (2003)
gpresult /r - query group policy (2008)
repadmin /showrepl - show replication history
repadmin /syncall /d /e /a - force replication from current DC
repadmin /replicate dc2 dc1 dc=domain,dc=com - replicate from dc1 to dc2 (they are in reverse order on the command line)
repadmin /replsummary - summary of replication. can be used to verify

Disable UAC in Windows 7

The user interface of User Account Control (UAC) settings in Windows 7 has changed to reflect the move to make UAC less annoying, more user control and more user friendlier approach. In Windows 7, the UAC has a slider bar which allows users to configure and select which level of notification (and hence protection against unauthorized and malicious access) they want. With the fine-tuning of UAC, the wording 'disable' or 'turn off' is no longer available. So how can you disable UAC? Or at least, how can you turn off the notification prompt or pop-up so that they appear less regularly?

In fact, the steps to disable UAC is Windows 7 is similar to steps to disable UAC in Windows Vista, only with slight user interface change, and there is plenty of methods to turn off UAC too.

Method 1: Disable or Turn Off UAC (User Account Control) in Control Panel

To user Control Panel to disable UAC in Windows 7, there are several methods to access the User Account Control settings page:

  1. Go to Start Menu -> Control Panel -> User Accounts and Family Safety -> User Account.
  2. Go to Start Menu -> Control Panel -> System and Security -> Action Center.
  3. Click or right click on Flag icon in notification area (system tray), and then Open Action Center.
  4. Type 'MsConfig' in Start Search to start System Configuration, then go to Tools tab, select Change UAC Settings, then click on Launch button.
  5. Click on User Account Control settings link.
  6. Slide the slider bar to the lowest value (towards Never Notify), with description showing Never notify me.

Windows Optimization

Rough list of things to consider disabling/re-configuring for optimization. I did not write these, I only compiled this list:

  • Application Experience
  • Computer Browser (do not change if computer is on a network)
  • Desktop Windows Manager Session Manager (only needed for Aero display themes)
  • Diagnostic Policy Service
  • Distributed Link Tracking Client
  • IP Helper
  • Offline Files
  • Portable Device Enumerator Service
  • Print Spooler (do not change if you use a printer)
  • Secondary Logon
  • Server (do not change if computer is on a network)
  • Tablet PC Input Service
  • Themes (only change if you use Windows classic theme)
  • Windows Error Reporting Service
  • Windows Media Center Service Launcher
  • Windows Search (only change if you don't/rarely use the search feature)
  • Windows Time (this service checks your clock's accuracy with the time online)
  • ActiveX Installer Service
  • Games
  • Indexing Service (This is the old indexing service that is no longer needed in Vista.)
  • Internet Information Service (Used for hosting websites on your computer.)
  • Microsoft .NET Framework 3.0 (Used for the new .NET 3.0 components, but only really needed for programmers.)
  • Microsoft Message Queue (MSMQ) Server (Used by programmers as a way to reliably queue messages.)
  • Print Services (You only need this if you use internet printers)
  • Remote Differential Compression (This is likely required for utilities that use the network to download files. If it is enabled, don’t mess with it.)
  • Removable Storage Management (The only reason you’d need this is if you are restoring from old NTBACKUP files.)
  • RIP Listener (You won’t need this, it’s a routing protocol.)
  • Services for NFS (This can be used to map a drive to a linux NFS server. Unlikely you’d need it since Samba works so well.)
  • SNMP Feature (This is used for management systems in workplace networks. You don’t need it.)
  • Subsystem for UNIX-based Applications (This is used for compatibility with certain applications based on UNIX… you don’t need it.)
  • Tablet PC Optional Components (If you have a Tablet PC, you should enable this. If you don’t, you may still want to because this includes the Snipping Tool.)
  • Telnet Client (You should never use telnet. Ever.)
  • Telnet Server (You should never use telnet. Ever.)
  • TFTP Client (TFTP was used by many of the early internet worms… there’s a reason it’s disabled by default.)
  • Windows DFS Replication Service (This is only really used in work environments. Don’t bother with this if you are a home user.)
  • Windows Fax and Scan (Why anybody still faxes anything is beyond me.)
  • Windows Meeting Space (If you don’t use Windows Meeting Space or the “People Near Me” feature, don’t bother with this.)
  • Windows PowerShell (PowerShell is a more advanced command line geared towards programmers and system administrators.)
  • Windows Process Activation Service (This is likely required to support some .NET applications, so I wouldn’t change whatever it’s currently set to.)
  • Windows Ultimate Extras (If you like the extras, then enable them. (Ultimate Only))


  • power settings


remove desktop cleanup:

  • right-click>properties>desktop>customize desktop

REGISTGRY FILES

The location of these registry hives are as follows:

HKEY_LOCAL_MACHINE \SYSTEM : \system32\config\system HKEY_LOCAL_MACHINE \SAM : \system32\config\sam HKEY_LOCAL_MACHINE \SECURITY : \system32\config\security HKEY_LOCAL_MACHINE \SOFTWARE : \system32\config\software HKEY_USERS \UserProfile : \winnt\profiles\username HKEY_USERS.DEFAULT : \system32\config\default

Some hives are volatile and don’t have associated files. The system creates and manages these hives entirely in memory; the hives are therefore temporary in nature. The system creates volatile hives every time the system boots. Examples are:

HKEY_LOCAL_MACHINE \HARDWARE : Volatile hive HKEY_LOCAL_MACHINE \SYSTEM \Clone : Volatile hive

These files are database files, and only RegEdit, Regedit32 and the Kernel32 can read them. The primary tool in Windows 7 for working directly with the registry is Registry Editor. To access it, simply type Regedit in Start Menu Search Bar and hit Enter !

DISK CACHE

What is the disk cache?

The disk cache is used to store disk information in RAM. Access to RAM is faster than the hard disk, so the information will be available more rapidly. Getting Started

First and foremost, and as with any registry modification, it is advisable to backup the entire contents of the registry, or at least the key(s) you want to edit. Open the Start menu, click Run and type the command: regedit. Find the following key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management. In the right column find the "LargeSystemCache" value and double click on it If the value does not exist you will need to create it: Click on an empty part of the window and click "New" Select New > 32-bit DWORD value and name it "LargeSystemCache". Double click on the value and select "Edit" Change the value of LargeSystemCache from 0 to 1, making sure the Hexadecimal option is checked Restart your PC to apply the changes.

ENABLE WRITE CACHE

Go to 'computer management', 'disk management', right-click on the disk and clicl 'properties'. Click the 'policies' tab and check 'enable write cache'.

SUPERFETCH AND DEFRAG ON SSD

i keep superfetch and prefetch enabled, but disable the automatic boot file defrag part of the prefetcher.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters] "EnableBootTrace"=dword:00000000 "EnablePrefetcher"=dword:00000003 "EnableSuperfetch"=dword:00000003

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\BootOptimizeFunction] "Enable"="N"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OptimalLayout] "EnableAutoLayout"=dword:00000000

p.s. defragging, while not very useful for an ssd, won't ruin ssd wear leveling. a file that is defragged and occupies one contiguous block of lba's will still be split across multiple nand devices.

BOOT USING ALL CPU CORES

to improve bootup speed:

goto start- type msconfig- open BOOT tab- goto Advanced options- Check Number of processors- select the BIGGEST number on the list (EG. 3,4,6) What it does is makes windows boot using all the cores!

DISABLE GUI BOOT

Run 'msconfig', go to Boot tab, check 'no GUI boot', save, restart.

Screensaver on Hotkey

Run screensaver on hotkey without locking screen

create a shortcut to C:\Windows\System32\[SCREENSAVERNAME].scr and put the shortcut somewhere like in your user folder.

right-click on the shortcut > properties > shortcut > shortcut key

Assign the desired hotkey

Automatically Login to Windows 7

  1. Click Start, type netplwiz, and then press Enter.
  2. In the User Accounts dialog box, click the account you want to automatically log on to.If it is available, clear the Users Must Enter A User Name And Password To Use This Computer check box.
  3. Click OK.
  4. In the Automatically Log On dialog box, enter the user’s password twice and click OK.

Saving Disk Space

Hiberfile

The C:\hiberfile.sys can be several gigs in size. You can remove it by disabling hibernate.

Open cmd as administrator:

powercfg.exe -h off

Paging File

The paging file can be quite large. You can either disable paging (not recommended) and move the location of the paging file to another drive. This can be done in Advanced System Settings (from This PC > Properties), then Advanced > Performance (Settings...) > Advanced > Virtual Memory (Change...).

Junctions (Low-Level Filesystem Shortcut)

You can move files to another drive and create a "junction" which is a low-level shortcut that should work on almost and files and folders, even some system file.

Open cmd as administrator:

mklink /J <link-destination> <path-source>

Example:

move "C:\ProgramData\Package Cache" "D:\"
mlink /J "C:\ProgramData\Package Cache" "D:\Package Cache"

Restore Points

You can delete old system restore points in Advanced System Settings (from This PC > Properties).

Custom Context Menu

Add Cygwin

add reg key: [HKEY_CLASSES_ROOT\Directory\Background\shell\bash (Default) REG_SZ bash NoWorkingDirectory REG_SZ

add reg key: [HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command (Default) REG_SZ D:\Program Files\cygwin64\bin\mintty.exe /bin/bash -l -c '/transpath.sh "%V"'

Open Cygwin and create file "/transpath.sh" with contents: drive=`echo -n "$1"|/usr/bin/grep -Po "^.:"|/usr/bin/tr ':' '\0'|/usr/bin/tr '[:upper:]' '[:lower:]'` path=`echo -n "$1"|/usr/bin/sed 's/^.://g'|/usr/bin/sed 's/\\\/\//g'` cd "/cygdrive/$drive$path" /bin/bash -i

CUSTOM BASHRC

PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]$(basename "$(pwd)")\[\e[0m\] \$ '

h=$HOME

alias cdc='cd /cygdrive/c/Users/$USER/Desktop'
alias cdh='cd /cygdrive/c/Users/$USER/Desktop'
alias c='/bin/clear'
alias h='history'

You can now right-click in Explorer and a Bash terminal will open in that directory.

Add Cmd.exe

edit reg key: [HKEY_CLASSES_ROOT\Directory\Background\shell\cmd (Default) REG_SZ cmd NoWorkingDirectory REG_SZ

(delete the "Extended" string value)

edit reg key: [HKEY_CLASSES_ROOT\Directory\Background\shell\cmd\command (Default) REG_SZ cmd.exe /s /k pushd "%V"

(Original value for Default is @shell32.dll,-8506)

You can now right-click in Explorer and a Cmd terminal will open in that directory.