Windows Tricks

From Hobowiki
Revision as of 20:45, 7 February 2020 by Brendan (talk | contribs) (→‎How to Automatically Archive Log Files)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Registry Tricks

Adding a Context Menu Item in Windows Explorer

First of all, you must edit the registry to do this, if you are not comfortable doing this, please ignore the rest of this. If you have ever used a command line program to execute a command on files on your computer, you can use this tip to help make your life easier. This will let you add a command on directories, or specific file-types. Below are some instructions on how to add a context menu item that lets you open .txt files with your favorite editor.

  1. Run regedit
  2. Open HKEY_CLASSES_ROOT
  3. Open .txt
  4. Create a new Key under this section called "shell"
  5. Create a new Key inside "shell" section called "Open with (insert editor name here)"
  6. Create a new Key inside "Open with (insert editor name here)" called "command"
  7. Edit the "default" string inside "command" key to write '(insert full pathname editor, including editor filename) "%1"' (notice the " are needed here)

Viola! Now you've got your own editor invoked from the context menu in Windows Explorer. As a note, this concept can also be applied to add context menus to the "Directory" key under HKEY_CLASSES_ROOT.


Where Are Those Windows Settings?

Windows has thousands of settings that are stored in a place called the "Registry" the windows registry is a huge centralized location for software and hardware settings. More Registry Info

Before making any changes to your registry, please read the following guidelines:

  1. The registry is divided into 5 main (also called root) sections: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG
  2. Each root registry location is abbreviated accordingly: HKEY_CLASSES_ROOT becomes HKCR, etc.
  3. Changing the registry is dangerous and can cause your computer to stop working, do not do it unless you are absolutely positive you know what you are doing and have a good reason for changing it.
  4. These settings are specific to WindowsXP only, other windows versions usually have variations on the WindowsXP registry model.
  5. All text in bold is specific to my machine only, you will find specific text on your own machine.

On to the list, here is the list of useful registry locations:

  • All entries in the following locations will be executed when windows first starts up.
    • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    • HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    • HKU\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Run
    • HKU\S-1-5-21-34578990-1457893563-4578790352-42342\Software\Microsoft\Windows\CurrentVersion\Run
  • HKLM\SYSTEM\CurrentControlSet\Services – Windows services are stored here.
  • HKCR – All file associations are stored here. (* references all files and folders.)
  • HKLM\SOFTWARE\Microsoft\Internet Explorer\Search – IE search locations are defined here.

I want to modify the CD auto-task list that pops up when I insert a CD

Before doing this, keep in mind this involves changing the registry, which is rather complex; if you don't feel comfortable with this, stop now. So, you have a new CD ripping/playing program, but it doesn't show up in the windows task menu when you right click the drive. Is this a problem we should even bother fixing? Well, if you don't care about the windows task thing that pops up, then stop reading this now. This is more of a convenience thing. The best way to show you how this works, is to show you the exact registry file exported from the registry after this trick has been applied.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CDex.File]

[HKEY_CLASSES_ROOT\CDex.File\shell]
@="Open"

[HKEY_CLASSES_ROOT\CDex.File\shell\Open]

[HKEY_CLASSES_ROOT\CDex.File\shell\Open\command]
@="\"C:\\Program Files\\CDex_170b2\\CDex.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers\CDexRipMediaOnArrival]
"Action"="Open"
"DefaultIcon"="C:\\Program Files\\CDex_170b2\\CDex.exe,0"
"InvokeProgid"="CDex.File"
"InvokeVerb"="Open"
"Provider"="CDex"
  1. Simply change the two lines listed below to the path to the Audio CD program you want to add to the auto-run task menu.
    • @="\"C:\\Program Files\\CDex_170b2\\CDex.exe\""
    • "DefaultIcon"="C:\\Program Files\\CDex_170b2\\CDex.exe,0"
  2. Then save the text above in a file with your changed lines, something like cdautorun.reg
  3. Double click the file you just saved in Windows Explorer.
  4. Say yes to import, and that should be it.

Now put in an audio CD, and your new CD task will be there.


Making Windows Run One Program When Another Program is Started

Sometimes you might want to circumvent a certain program from running, or making sure that one program is run before another is run. This little trick can be accomplished by exploiting the "Image File Execution Options" registry setting in windows. What this means is that whenever a specific program is supposed to run, Windows checks this registry setting first, then executes whatever is set there and simply trusts that your program is going to run the program in question. This functionality is there to facilitate debugging programs on windows.

I'm going to use a common example to walk you through how this works. Replacing the windows default task manager with the Sysinternals task manager. We are going to use the Image File Execution Options registry hack to facilitate this.

  1. Download Process Explorer
  2. Save it to a directory, we're going to use C:\Utils\Process Explorer\ to make things simple.
  3. Save the code at the bottom to a .reg file.
  4. Double click the reg file you just saved in windows.
  5. Right click the task bar and select Task Manager, and you should see Process Explorer.

Registry Code

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\'''taskmgr.exe''']
"Debugger"="C:\\Utils\\Process Explorer\\procexp.exe"

Sharing a USB Drive on a Windows Machine on the Network

Every now and then you might want to share a USB drive on the network from your PC. This seems like a simple enough problem, simply right click the folder, select Sharing and Security, and setup the network share like normal, right? Well this isn't the whole story, for some technical reason, this isn't possible without changing a couple settings here and there. So let me guide you through it:

First, take the code listed below, save it as IRPStackSize.reg, and double click it. This should set the special setting that allows USB drives to be shared via the network without any problems.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters]
"IRPStackSize"=dword:00000014

If you are interested to know more about this little trick, there is plenty of info about it here.

How to Automatically Archive Log Files

In order to ensure you get all associated log files with a service, you should stop the service first, archive the logs, then start the service again. For this example I am going to use WinRar as my command line archival tool, an apache service as the service, and the good old built in windows task scheduler to repeat this task every month. Here is how it works.

  1. Download the Windows Resource Kit from Microsoft [1]
  2. Create a batch file (preferably named something like "archive-logs.cmd")
  3. Put a command on the first line of the batch file to stop each service that uses and creates the log files. Below is an example of how to stop the apache process.
sc stop apache2
  1. Add a goto label and a sleep command (part of the Windows Resource Kit)
:servicecheck
sleep 1
  1. Add a line to check if the service has stopped or not to continue on, pipe this command into find.
sc query apache2|find "STOPPED"
  1. Add a line to check the errorlevel of find, if the errorlevel of find is 1 then the search was unsuccessful, so the goto statement will send the batch file execution back to the servicecheck label so the batch file can continue checking to see if the service has stopped yet.
if errorlevel 1 goto apachetest
  1. Add a line to create the archive. Since I'm using Winrar I have at my disposal plenty of options. The options I like to use in Winrar for my own archival are as follows:
  • m (command) - moves files to archive, this deletes the files after they have been archived, saves the extra step of having to delete the files after they have been archived.
  • -m5 (switch) - sets maximum compression level, as most log files are text only, setting this option saves a great deal of space.
  • -ep (switch) - excludes paths from names in archive, since I already know what these log files are, there is no need in storing excess path info on each log file.
  • -agYYYY{-}MM{-}DD (switch) - appends the current year month and day to the file name, the {-} add dashes between them, this is a must have option for log files.
  • @"C:\backup\list-of-files-to-backup.txt" (file list) - lets you add a text file with a list of files to archive, so you don't have to fiddle with the batch file after you've created it; great because the text file can also contain wildcards such as * and ? to help include more files.
C:\Program Files\Apache2\logs\*.log
C:\Program Files\Apache2\logs\errors
C:\Program Files\Apache2\logs\httpd.pid

Here is the final command:

rar m -m5 -ep -agYYYY{-}MM{-}DD "C:\backup\webserver logs up until" @"C:\backup\list-of-files-to-backup.txt"
  • After the archive is done, you will want to start that service up again.
    sc start apache2
  • After adding all necessary log archival commands to the file and saving it, open Control Panel then click Scheduled Tasks.
  • Click "Add Scheduled Task", click "Next", click "Browse" then find and select your batch file you just created.
  • After you configure how often you want the log archiving to take place you are done and the rest is taken care of by windows, automatically.

That wasn't so bad now was it?

How to Run Control Panel Applications from the Command Line

  1. Run Command Prompt (Start > Run > cmd)
  2. Type in control panel application short name from this list:
    • Accessibility Options – “control access.cpl”
    • Add/Remove Programs – “control appwiz.cpl”
    • Add Hardware Wizard – “control hdwwiz.cpl”
    • Automatic Updates – “control wuaucpl.cpl”
    • Bluetooth Properties – “control bthprops.cpl”
    • Display Properties – “control desk.cpl”
    • Firewall Properties – “control firewall.cpl”
    • Game Controllers – “control joy.cpl”
    • Internet Options – “control inetcpl.cpl”
    • iSCSI Initiator – “control iscsicpl.cpl”
    • Java Control Panel – “control jpicpl32.cpl”
    • Licensing Mode – “control liccpa.cpl”
    • Mouse Properties – “control main.cpl”
    • Network Connections – “control ncpa.cpl”
    • Network Setup Wizard – “control netsetup.cpl”
    • ODBC Properties – “control odbccp32.cpl”
    • Power Options – “control powercfg.cpl”
    • Regional and Language Options – “control intl.cpl”
    • Sound and Audio Devices – “control mmsys.cpl”
    • Stored Passwords – “control keymgr.cpl” (stored network drive credentials, stored web credentials)
    • System Information – “control msinfo32.exe”
    • System Properties – “control sysdm.cpl”
    • Telephone and Modem Properties –  “control telephon.cpl”
    • Time and Date Settings – “control timedate.cpl”
    • User Accounts – “control nusrmgr.cpl”
    • Windows Security Center – “control wscui.cpl”
    • Wireless Link – “control irprops.cpl”

Where Are Those Special Windows Files?

Windows has hundreds if not thousands of special files that it draws upon to configure the environment you use it in. Most all of those files are in places that aren't readily obvious, which make it very difficult to make changes to them. First, here is a list of special directories that contain files of note.

These lists make a few assumptions:

  1. Windows is installed on the C: drive
  2. The windows folder is named WINDOWS
  3. You didn't use any utilities like TweakUI and change the default directories already.
  4. The bolded sections are specific to your computer, make sure to take that into account.

Here is a list of special directories:

  • C:\Documents and Settings\JoeUser\Application Data\Microsoft\Signatures – Outlook Signature Files
  • C:\Documents and Settings\JoeUser\Application Data\Microsoft\Internet Explorer\Quick Launch – Quicklaunch Folder
  • C:\Documents and Settings\JoeUser\Local Settings\Application Data\Microsoft\Outlook – Outlook Mail Files
  • C:\WINDOWS\system32\config – System Event Logs
  • C:\Documents and Settings\JoeUser\Application Data\Microsoft\MSDN\8.0\VS Help Data – Configuration options for Visual Studio Help (including search engines it uses)
  • C:\Documents and Settings\All Users\Start Menu\Programs\Startup – All executables or shortcuts listed here will be executed on system startup.

Here is a list of special individual files

  • C:\WINDOWS\system32\drivers\etc\hosts – Hosts_file
  • C:\Documents and Settings\JoeUser\Application Data\Microsoft\Proof\CUSTOM.DIC – Outlook Custom Dictionary
  • C:\Documents and Settings\JoeUser\Application Data\Microsoft\VisualStudio\8.0\DataBindingSetting\WinFormControls.xml – Visual Studio Data Binding Defaults

How do you Reference a Page Inside a Windows Help File?

Windows help files typically have a .CHM extension. If you've used any of these files you'll know how annoying it is that they look and feel like a web page, yet without the flexibility of a web page. Well with a little clicking you can bookmark a page inside one of these help files without breaking a sweat.

In Internet Explorer:

  1. Open up the windows help file you want to bookmark a page in.
  2. Find the page you want to bookmark
  3. Right click the page and select "Properties"
  4. Inside the properties box, click and select the text after 'Address: (URL)'
    • Make sure you've selected the entire block of text:
      1. Click the text
      2. Press "CTRL-A"
  5. Press "CTRL-C" (this should copy all the selected text)
  6. Open Internet Explorer
  7. Click the address bar and press "CTRL-V"
    • This should paste the entire URL starting with MK into the address bar
  8. Press enter
  9. Click the Add to Favorites button

After A Fresh Windows Install, My Already Installed Games Don't Work

It's pretty standard practice for most games these days to use a value in the registry to indicate that they are installed. If you are like me however, you might wipe your windows drive every now and then just to give windows that "just installed" feeling. Obviously, there are many reasons for doing a fresh install of windows; some people even have a special partition or entire hard drive dedicated to the OS. If you do, then you probably install your programs and games on a separate drive.

In the case where your games and programs are on another drive however, all of your games you previously installed on your other drive might ask you to re-install them to replace that little piece of the registry that is now missing. This is a pain in the butt for some of those rather large games. So, here is a little trick that can save you the time of re-installing and doesn't take "too long" (most of the time).

  1. Download Process Monitor: [2]
  2. Open the directory of the game you want to play (but won't because it asks you to install it again).
  3. Start Process Monitor.
    • Make sure it is set to capture events.
    • Don't worry if the number of events is in the thousands before you can blink there are wonderful filters on it that let you sort through it later.
  4. Start the game you are trying to play.
  5. As soon as the game exits with some variation on the message "Please Reinstall Game" stop Process Monitor from capturing events.
  6. In process monitor click the "Filter" button.
  7. In the window that pops up there are a number of drop downs boxes, these are the ones to select to filter it properly:
    • Path
    • Contains
    • (short name of game, publishers name, or other game related name)
    • Include
  8. Feel free to add as many of the include entries related to the game as you feel is necessary.
    • The more includes the more likely you are to find what you are looking for.
  9. Now add another entry to the filter:
    • Result
    • is not
    • SUCCESS
    • Include
  10. Click the OK button and the list of entries will now be filtered.
  11. Scroll through the list of entries, look for entries that say "NAME NOT FOUND" and make note of the Path listed.
  12. Start regedit.
  13. Navigate to the path listed in process monitor with "NAME NOT FOUND".
    • Chances are, that path simply doesn't exist, so start creating it.
      1. Start by right-clicking the node where the path starts to not exist and select New > Key.
      2. Continue creating new keys inside of keys until you reach the second to last part of the path.
        • e.g. Your path is My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\GameCompany\Game\SerialNumber, so keep creating keys until you reach Game, but don't create a key called SerialNumber.
      3. On the last part of the path, typically you need to create a string or possibly a DWORD of some kind.
      4. In the example above, the last part of the path is the serial number, so create a New > String Value inside the last key you created.
      5. If the value happens to be a serial number, enter it here. (typically taken from the CD case or manual)
      6. Sometimes, if you are lucky, this value simply needs to exist, but doesn't have to be anything special.
  14. After creating the key in the registry, simply try running the game.
    • If the game works, then viola you are done!
    • If the game doesn't work, go back to process monitor and look for other registry values that the program is trying to open but getting an error on, re-create those entries just as above and hopefully you'll be up and running in no time.

Windows Keyboard Shortcuts

Courtesy of reddit

Standard Windows + Windows Apps shortcuts

  • Ctrl + Shift + Esc - Open task manager
  • Windows Key + R - run dialog
  • Winkey + D - toggle show desktop
  • Winkey + L - lock workstation
  • Middle click a link - open in new background tab (useful for google, reddit)
  • Middle click a tab - close tab
  • Middle click back button - open history in new tab (not for IE)
  • Ctrl + F5 - clear cache and refresh webpage (great for page errors/testing)
  • Ctrl + (shift +) tab - switch tab/document forwards (or backwards)
  • Alt + (shift +) tab - switch windows forwards (or backwards)
  • (Shift +) tab button - when filling out a form, skip to next (or previous) form field
  • Hold Shift while inserting removable media - prevents 'autorun']
  • Shift + Delete - permanently deletes files (without going to recycle bin)
  • F2 - 'edit', renames selected file. Also used in spreadsheet cells.
  • Ctrl + Scroll - zoom web page, document, file thumbnails
  • Ctrl + C on any standard error dialog box - copies error report text
  • Alt + PrtScn - Copies an image of the current window to clipboard
  • Ctrl + Shift + Esc: Note: Ctrl + Alt + Del now brings up a 'lock this computer' dialog on Vista/7, so I suggest you learn this one. Another perk is that on a VM or a remote control app, this will open the remote (client) machine's task manager.

New Win7 tricks

  • Shift + drag a file to a dock app - open it with that application. (default behaviour is 'pin')
  • Winkey and + or - , zoom in/out of screen (looks v. cool)
  • Winkey + type "c:/" - browse folders. tap up, down & '\' to browse subdirs, tap enter to open.
  • Winkey + [dos appname] + enter - [Vista/7] Launch app instantly. (Don't wait for search results)
  • Middle click an app on dock - Open a new app instance
  • Middle click a thumbnail from dock - Close that app instance
  • Shift + Right click dock item - Legacy menu
  • Drag up on dock item - Quick jumplist
  • Alt - [IE8, Vista & 7] bring up old-style file menus where they've been removed
  • Winkey + P - multi-display config quick-switch (press twice to switch)
  • Winkey + X - bring up laptop settings control panel
  • Winkey + T - dock keyboard mode (use arrow keys)
  • Winkey + tab - [Vista/7] flip3d
  • Winkey + left, right, up or down key - manage window position
  • Shift + Ctrl + N - new folder (had a few requests for this one!)
  • Drag window to left, right or top edge to 'snap' them.

Oh, and if all your apps disappear, move your mouse away from the lower left corner. If this bugs you like it bugs me, right click the lower left corner & turn off 'peek at desktop'

Right-click key

To the right of your space bar, there's a little 'right click' key. This thing is powerful in any GUI. It's excellent for fixing typos in docs, renaming files, etc.

  • When editing spell-checked documents, this allows you to quickly fix 'red/green wavy line' spelling or grammar errors.
  • When a file is selected, hit the right right click key, then type 'm' for Rename, 'r' for Properties, 'n' for Send to (e.g. USB key) or 'd' for Delete. (Note the underlines in the menus)
  • When on a flash-based site, or a site with right-click disabled - hit the right click key to get 'view source', etc.

Command line utils (Winkey+R)

  • "resmon" - win7 only, awesome resource monitor - bandwidth etc
  • "perfmon" - a pretty decent performance monitor (vista, xp?)
  • "cmd" - command line
  • "control userpasswords2" - set windows to auto-login
  • "dxdiag" - hardware properties (processor, ram, etc)
  • Winkey + pause - system properties
  • "regedit", "msconfig", "services.msc", "compmgmt.msc", "eventvwr", "appwiz.cpl" - manage system stuff
  • "ping bing.com", "ping 192.168.0.1", "ping 10.0.0.1", "netstat", "ipconfig" - network tests
  • (don't use google if your homepage is google)
  • "charmap" - unusual characters (also, note the keyboard shortcuts provided in its status bar only work with the numpad)

"Obvious"

  • Esc - dismiss dialog
  • Double-click window title - maximize
  • Space - fill in a checkbox, press the highlighted button, or scroll down
  • Tab - When filling out forms, skip forwards through inputs
  • Shift + Tab - When filling out forms, skip backwards through inputs
  • Ctrl + Tab - switch windows within an application (e.g. tabs)
  • Alt + Tab - switch between windows
  • Ctrl + F4 - close tab/document
  • Alt + F4 - close window
  • Ctrl + left/right buttons - skip text by word, rather than by letter (hold shift to select)
  • Ctrl + up/down buttons - skip text by paragraph, rather than by letter (hold shift to select)
  • PgUp, PgDn - Scroll up/down 1 page
  • Home - Skip to top of page
  • End - Skip to end of page
  • Print Screen (PrtScn) - Takes a picture of your screen and puts it in the clipboard. You can paste it in paint.
  • F5 - refresh page/folder/dialog
  • Ctrl + Z - undo
  • Ctrl + Y - redo (reverse undo)
  • Ctrl + X - cut
  • Ctrl + C - copy
  • Ctrl + V - paste
  • Ctrl + S - save
  • Ctrl + F - find in page/doc
  • Ctrl + A - select all
  • Shift + click items in a list - select a continuous group of sequential items from a list
  • Ctrl + click items in a list - select multiple individual items from a list
  • Ctrl + [B, I, U] - bold, italic, underline
  • Ctrl + Esc or Windows Key - open start menu
  • Lost a window? Right click the taskbar, click 'cascade windows'.

Probably not worth the bother

  • Middle click a folder of favorites - open all favorites in new tabs
  • Shift + Right click anywhere - usually adds 'experienced user' options (e.g. open cmd from here)
  • Winkey + E - windows explorer
  • Winkey + U - 'usability' (disabled) control panel
  • Winkey + [1,2,3,4,5,6,7,8,9,0] - launches corresponding quicklaunch/win7dock item
  • Winkey + shift + left, right, up, down - [win7], dual screen window management
  • Winkey + space - [win7] peek at desktop
  • Winkey + G - [vista/7] view desktop gadgets
  • Ctrl + W - 'Save As...'
  • Ctrl + alt + [1,2,3,4,5,6,7,8,9,0] - Creates header-level text in word processors. You can use this to auto-generate a document outline or table of contents. In web apps it's just Ctrl + [1,2...]

Taking Control Of Windows 8 System Files (Using Takeown)

It's rare that most people will need to ever change the system files on their windows system, and it's usually because something has gone horribly wrong. Since every now and then this happens to the best of us, I am going to tell you about takeown.

Takeown lets an administrator to add themselves to the permission set on any file or directory. This is necessary when that file might be missing the appropriate ACL's to allow you to access or control that file.

I used this mechanism to restore an important file from a backup so that windows would continue functioning; specifically, the file was wuauctl.exe, which controls windows updates, and is especially crucial to the operating of a secure windows system.

<analytics uacct="UA-868295-1"></analytics>