Skip to content

CategoryWindows

Send A File Path from the Windows Context Menu to App

Here’s an easy way to pass the file path to a console app. I needed a way to right click on a folder or a file, and send the path to a console app, where the app does its thing with the file(s).

To show you what I mean:

When I right-click on “coolbeans” it runs the following console app, which simply displays the path:

The C# app is pretty straightforward. Basically, once you have the file path, you can apply any operations on the file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dan_rocks
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(args[0]);
      Console.ReadLine();
    }
  }
}

So there’s nothing crazy going on in the above sample. You basically just have to add a few entries to the Registry.

If you want to pass a folder path when you right-click on it, and select the option in the context menu, create a new entry:

HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell

If you want to pass in a file, do the following:

HKEY_CLASSES_ROOT\*\shell

Let’s pass in the filepath to note.exe:

Do that and you’ll see the following:

Compress and Move Log Files

Sometimes log files bog a system down. For one of our servers, I made this little Python script that compresses (via WinRAR) the log files in a directory, and then moves them to a backup location. The only little catch is that I wanted to leave the latest log files for in that directory. Log files are created daily, so the the latest log files have a datestamp of today. Here’s how I did it.

First Create the Python Script:

import os
import datetime

dateStamp  = datetime.datetime.now().strftime("%Y-%m-%d") 
imsLogPath = 'd:\\LogFiles\\'                     
# Don't use a mapped drive but use UNC for network drives. Task Schedule seems to choke when it calls Python.
newRARPath = '"\\\\192.168.1.2\\Root\\backups\\' + dateStamp + '.rar"'
rarPath    = '"C:\\Program Files\\WinRAR\\rar.exe" a -m5 ' + newRARPath 

# Get Latest Files
smtpLatest   = os.popen(r"dir /od /a-d /b " + imsLogPath + "SMTP*.log").read().splitlines()[-1]
postLatest   = os.popen(r"dir /od /a-d /b " + imsLogPath + "POST*.log").read().splitlines()[-1]
ischedLatest = os.popen(r"dir /od /a-d /b " + imsLogPath + "iSched*.log").read().splitlines()[-1]
relayLatest  = os.popen(r"dir /od /a-d /b " + imsLogPath + "Relay*.log").read().splitlines()[-1]
qengLatest   = os.popen(r"dir /od /a-d /b " + imsLogPath + "Qeng*.log").read().splitlines()[-1]

# Get List of All Files
allFiles     = os.popen(r"dir /od /a-d /b " + imsLogPath + "*.log").read().splitlines()

# Remove Latest Files from All Files List
allFiles.remove( smtpLatest )
allFiles.remove( postLatest )
allFiles.remove( ischedLatest )
allFiles.remove( relayLatest )
allFiles.remove( qengLatest )

# allFiles Array Has the list of files

# Flatten Array allFiles to be used as a parameter in system command
flatLogPathList = ""
for filenameWithPath in allFiles:
  flatLogPathList = flatLogPathList + imsLogPath + filenameWithPath + " "


# Execute WinRar
path = rarPath + " " + flatLogPathList.rstrip()
os.system( '"' + path + '"' )

# Delete all log files
os.system( '"del ' + flatLogPathList.rstrip() + '"' )

Then I set up the Scheduled Task:

With these Settings:

Console2 Alternative to CMD

You know what, I tried PowerShell and I guess I never got used to it. I’ve been using DOS for the longest time that I prefer its simplicity when navigating through files. As far as scripting with it – forget it – it’s very cryptic and limiting, not to mention awkward. That’s why for scripting now I’m using Python. Nonetheless though, I sometimes need a playing field to run the scripts for, or running console utilities. That’s where Console2 comes in.

Console2 is a great tool that provides tabbing (you can tab through multiple consoles) and several ways to customize the UI. Here’s an example:



I prefer this configuration:


How I Have It Setup



Download Console2:

I have the Console2 open up when I hit CTR+\ via AutoHotkey. Here’s the snippet for this to happen in AutoHotkey. I have this run when Window starts (it must stay in memory).

^\::Run C:\dan-local\dos-win\Console.exe

Change the CMD prompt by creating a PROMPT system variable:




Download the Console2 Config File

Other Tips


Autocomplete
Good tip about command console = CTRL+I
can select files in the current directory, kinda like autofill-in
you can also put in parts of the file and it autoputs it for you

Rename tab
CTRL+R

New Tab with default transparency
CTRL+F1

New Tab with lighter transparency
CTRL+F2

Switch to NEXT adjacent tab
CTRL+TAB

Switch to Previous adjacent tab
CTRL+SHIFT+TAB

CTRL+[NUMBER]
Goes to the tab instance. To make it easier, it’s best if you rename your tabs,

[INSTANCE NAME].[NAME OF TAB]

So for example,

1.Batch File
2.wget list
3.ftp the files

Search As You Type

Just upgraded recently from WindowsXP to Windows7. One feature I used a lot forever (since Win95 I think), was the search as you type (this is what I call it anyways). It’s when you have an Explorer window open (let’s say in this case c:\ ) and you type “W” – it moves the cursor to directory that starts with the letter “W.” You can type “Win” quickly and it will go to the first directory that starts with those keywords in case you have directories that start with “Win.”

So after I configured the UI settings on Win7 to the way I saw fit, I realized that this feature was gone. It would automatically start searching for text in all files recursively – very annoying. I asked how to turn this feature off in many forums and do what I wanted to do and no one knew.

I finally figured it out. It was a setting that I turned on accidentally. (D’oh!)

Explorer Window -> Organize -> Folder Options -> View Tab -> When typing
into list view -> Select the typed item in the view

That wasn’t checked. I suppose I did it instinctively without thinking. In WindowsXP, the area is used to trigger Advanced File Sharing, and I guess I didn’t realize this in Windows7. Also, I don’t think in XP this is an option you can control because it just works.

Windows7 Options

WindowsXP Options

Computer Tools for the Power User

Here’s a list several tools I use both at home and work. I usually carry these on my USB keychain for easy access. They’re mostly lightweight, fast, and some don’t even require a installation. These are free and NOT Shareware! They are for Windows/Windows XP.

Windows

WinMerge
Used for file comparisons. You can compare text files and see, line by line where these files are different.

Notepad++
Great editor for HTML. This integrates nicely into Internet Explorer to “view source.” It can collapse HTML tags.

Notepad2
Microsoft Notepad on steroids. It uses color coding for files of various extensions. Uses transparency so that you can see through the editor window what’s behind it.

Agent Ransack
Search for text in files. The results show you the file and what line your keyword search is in.

Password Manager
It saves your passwords. You can create categories for what kind of passwords they are. Once you save it, you hit CTRL+U to save the user name, and CTRL+C to save the password to the clipboard. It uses a secure 448 bit Blowfish algorithm to ensure the data are not crackable. The password used for securing access to stored data is not saved anywhere.

JR Screen Ruler
A visual ruler you can use to measure pixels on the screen.

WinMacro
Record whatever you do at your Windows Desktop, and can replay them exactly. This is great to record tasks and save them for later.

STRIFE
Get a checksum for a file using hashes: crc16, crc32, xsum, md5.

PuTTY
Telnet/SSH Client

Process Explorer
See information about processes: what files or directories they have open. Kill processes, etc.

StartupRun
Know exactly what’s running when you start windows and turn those annoying programs off.

Simple File Schredder
Simple File Shredder is a utility that securely deletes your files so they can’t be restored.

Restore Deleted Files
This restores files that have been deleted. Use this as a last line of defense. The great thing about this program is that it does not require to install – unlike other applications, where you need to install first.

Angry IP Scanner
Angry IP scanner is a very fast IP scanner and port scanner. It can scan IP addresses in any range as well as any their ports. Its binary file size is very small compared to other IP or port scanners.

SetFileDate
Change the date stamp for any file you want.

PopupManager
Great popup blocker.

ZoneAlarm
Good firewall software.

System Spec
System Information Utility. Get a report for practically everything you wanted to know about your computer.

SyncBack
Synchronize files from different folders. I use this to synchronize files from my computer and USB keychain and USB drive. Lots of features.

Microsoft PowerToys for Windows XP
PowerToys add fun and functionality to the Windows experience. What are they? PowerToys are additional programs that developers work on after a product has been released. These tools include: Synchronize file tool, Image resizer to resize a batch of files, power calculator, multiple desktops, tweak UI settings, and more productivity tools.

Windows Internet Browser Plugins

Web Developer Plugin for Firefox
Provides a variety of tools for quickly creating, understanding, and troubleshooting Web pages. This feature is added to the menu when you right click on a page.

Internet Explorer Developer Toolbar
Provides a variety of tools for quickly creating, understanding, and troubleshooting Web pages. This feature is added to the menu when you right click on a page.

IE Context Menu Toolset
This is a set of tools which extend the right-click context menu of Internet Explorer. By simply installing these tools, your browser will have added functionality which can greatly help in debugging pages, designing sites, diagnosing form problems, tweaking design, etc.

Fiddler
Fiddler is a HTTP Debugging Proxy which logs all HTTP traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP Traffic, set breakpoints, and “fiddle” with incoming or outgoing data. Fiddler is designed to be much simpler than using NetMon or Achilles, and includes a simple but powerful JScript.NET event-based scripting subsystem.

Command Console Tools

MaxDIR
Like the dir command but displays files/directories with color and in columns.
Way much better! The drawback is if your OS is not using FAT12 or FAT16 type disks, the Bytes Consumed will be wrong.

HexEdit
Great Hexeditor. The only Hexeditor I use.

FastSum
Get md5 hashes of files or text you type in. Useful if you need to find the md5 hash of a word.

Other Great Sites for Small Tools

These two sites have great little apps for networks, programming, graphics, etc. These are also free.

Systinternals Freeware
TinyApps

Log Parser Lizard

Log Parser Lizard is a great free tool if you use Log Parser to parse IIS logs using SQL. It’s a visual tool to query the logs. It also comes with pre-made queries. Let’s take a look at one, “Requests and Full Status by Number of Hits” in IIS logs:

-- Let's query the IIS W3SVC80086301 Log file c:\temp\logs\ex080918.log
SELECT  STRCAT( cs-uri-stem, 
    REPLACE_IF_NOT_NULL(cs-uri-query, STRCAT('?',cs-uri-query))
    ) AS Request, 
  STRCAT( TO_STRING(sc-status),     
    STRCAT( '.',
      COALESCE(TO_STRING(sc-substatus), '?' )
      )
    ) AS Status, 
  COUNT(*) AS Total 
FROM c:\temp\logs\ex080918.log 
WHERE (sc-status >= 400) 
GROUP BY Request, Status 
ORDER BY Total DESC

Which gives you the following result (depending, of course, what’s in your logs):

2

Also, I could’ve queried all the log files put together, such as:

select * from c:\temp\logs\*log

Also, you can create global variables and use them in your queries so that you don’t always have to put the full path to a file. For example:

3

I’m setting the variable IISW3C equal to c:\temp\logs\ex*.log . The queries that come with this tool use these variables (keys) as a shortcut. For your IIS logs dir, you may want to set it up to point to C:\WINDOWS\system32\LogFiles\W3SVC80086301 . Once you’ve done this, you can do (HIT F5 to run query):

-- Get the top 10 from all IIS logs
select top 10 * from #IISW3C# 

You can also view LogParser graphs from this tool. Let’s try the query to show all extension with total hits:

SELECT  TO_UPPERCASE(EXTRACT_EXTENSION( cs-uri-stem )) AS Extension, 
  COUNT(*) AS [Total Hits]
FROM #IISW3C# 
GROUP BY Extension 
-- Ignore .CFM extension
HAVING TO_UPPERCASE(EXTRACT_EXTENSION( cs-uri-stem ))  'CFM'
ORDER BY [Total Hits] DESC

4s

Running a 32bit or 64bit CPU?

Sometimes Windows alone might not be able to tell you what your machine has. To be absolutely sure, if you at least know you have an Intel CPU, try their Processor Identification Utility.

3

You can also save a text file report summary of your machine. Here’s my machine at work:

Intel(R) Processor Identification Utility
Version: 4.21.20091215
Time Stamp: 2010/01/27 19:53:40
Operating System: 6.1-7600-
Number of processors in system: 1
Current processor: #1
Active cores per processor: 2
Disabled cores per processor: 0
Processor Name: Intel(R) Pentium(R) D CPU 830   3.00GHz
Type: 0
Family: F
Model: 4
Stepping: 4
Revision: 6
Maximum CPUID Level: 5
L1 Instruction Cache: 2 x 12 Kµops
L1 Data Cache: 2 x 16 KB
L2 Cache: 2 x 1 MB
Packaging: LGA775
Platform Compatibility Guide: 05B
Enhanced Intel SpeedStep(R) Technology: Yes
MMX(TM): Yes
Intel(R) SSE: Yes
Intel(R) SSE2: Yes
Intel(R) SSE3: Yes
Intel(R) SSE4: No
Enhanced Halt State: Yes
Execute Disable Bit: Yes
Intel(R) Hyper-Threading Technology: No
Intel(R) 64 Architecture: Yes
Intel(R) Virtualization Technology: No
Expected Processor Frequency: 3.0 GHz
Reported Processor Frequency: 3.0 GHz
Expected System Bus Frequency: 800 MHz
Reported System Bus Frequency: 800 MHz
*************************************************************

FYI, this is from Intel:

Certain advanced Intel(R) processor technologies require system support features be present to be fully enabled. Please see the notifications below for system features required to enable the listed technologies.

Intel(R) Hyper-Threading Technology
Intel(R) Hyper-Threading Technology requires a computer system with a processor supporting Intel(R) HT Technology and an Intel(R) HT Technology-enabled chipset, BIOS and operating system. Performance will vary depending on the specific hardware and software you use. For more information including details on which processors support Intel(R) HT Technology, see http://www.intel.com/info/hyperthreading

To verify your system for Intel(R) Hyper-Threading Technology, download the Intel(R) Hyper-Threading Technology Test Utility from http://downloadfinder.intel.com/scripts-df/Product_Filter.asp?ProductID=1687

Intel(R) 64 Architecture
64-bit computing on Intel architecture requires a computer system with a processor, chipset, BIOS, operating system, device drivers and applications enabled for Intel(R) 64 architecture. Performance will vary depending on your hardware and software configurations. Consult with your system vendor for more information.

Intel(R) Virtualization Technology
Intel(R) Virtualization Technology requires a computer system with a processor, chipset, BIOS, enabling software and/or operating system, device drivers and applications designed for this feature. Performance will vary depending on your configuration. Contact your vendor for more information.

Intel, Intel Atom, Intel Core, Pentium, Xeon, Celeron, OverDrive, SpeedStep and MMX are trademarks of Intel Corporation in the United States and other countries. Copyright(C) 2010, Intel Corporation. All rights reserved.

Executable Extension

Want to run a script in the command console that is not of type EXE, COM, BAT by just typing in the name of the script? Have a script in Perl or Python that you have that you want to run without typing the name of the interpreter with switches? It’s pretty easy to do in Windows.

  1. Open up System Properties and click on Environment Variables:

  2. Select the PATHEXT System variable and click on the Edit button.

  3. Add the extension you want. In this case, let’s add the extension for .PL so we can run Perl scripts without typing in the name of the Perl interpreter:

  4. Hit OK on the Windows.
  5. In an Explorer Window, Go to Tools -> Folders

  6. In the Folder Options Window, click on the File Types tab, and then click New:

  7. Type .PL for the File Extension

  8. Click OK then Click on the Advanced button to open up the Edit File Type and click on New…

  9. Enter the name of the interpreter:

  10. Hit OK for all Windows.
  11. You’re set and good to go.

Now let’s test it. Make a .pl file under c:\ called "add.pl". Make add.pl be:

$sum = $ARGV[0] + $ARGV[1];
print "\nSum of the numbers is: $sum\n\n";

 

Now let’s call it via the console by typing:

add 5 5

9

Unlock System Files

Ever had such an annoying message given by Windows?

It has many other flavors:

Cannot delete file: Access is denied
There has been a sharing violation.
The source or destination file may be in use.
The file is in use by another program or user.
Make sure the disk is not full or write-protected and that the file is not currently in use.

Now you have an option to unlock it using Unlocker. Now, sometimes it’s theoretically impossible to unlock all files, especially some DLLs that are burned into Windows, but for most applications that you run that are not part of Windows, you either have the choice of unlock, rename, and move. This program is free too and it tries to do it without actually killing processes.

Here are some reviews for Unlocker.

Automate FTP Uploads

I thought this might be useful for those who are constantly uploading the same files. Whether you need to deploy a project live or constantly upload the same group of files, you can do this by creating a batch file in Windows using ftp.exe.

First of all, if you’re not familiar with FTP.exe, it’s just a command console way to upload/download files from an FTP server. You can run this program and start typing away…. OR, you can load a text file filled with FTP commands in FTP.exe. For example, the following are commands in a file called upload.bs:

open western.dreamhost.com
username
password
binary
hash
send index.htm
send frame.htm
send car.jpg
bye

The above should be straightforward. The “open” command is used to connect to the FTP server. The “username” should be your usename and “password” should be your actual password. “binary” is how your data should be handled on transfer – if it’s not text, it’s binary data, and should be “binary.” “hash” makes the console display pound signs (#) to serve as a progress bar as it’s uploading to the server. The “send” commands are used to upload the files. “bye” is exits the FTP session.

That was just a FTP script session file. You now need to call that file from FTP.exe on WindowsXP. You do that as follows:

@%windir%\system32\ftp.exe -s:upload.bs

You can include that call in a file called “upload.bat” – To learn more about FTP scripting and how to merge the two files into just one batch file, you can check out this site. Also, there’s more information about this found here: tinyapps.org.

Outlook Emails/Contacts in “To” Dropdown

Needed to backup my contacts in Outlook, but it would not save the emails in the email “To” dropdown field, when autocomplete triggers. This is because it’s stored in Outlook’s NK2 cache file. This file is not in readable form, but you if you have the patience, you can view the emails if you don’t mind looking through funky ASCII characters of binary data. In the process of looking for and trying various tools, I realized that not all tools were able to extract all contacts. Keep this in mind.

There’s a few tools out there that you can use to extract a list of emails saved in the NK2 file. Here they are.

Ingressor – is the best program, I was able to extract the most amount of emails/contacts, but you have to pay for it. I think it extracts everything, but you can’t save anything or copy anything. Use OCR software?

Debunk2– It’s free, but it missed 1 (could possibly miss more on different NK2 files) contact.

NK2.info– It’s free, but it missed 2 contacts, and it doesn’t show the names accurately, like Debung2 and Ingressor.

Reprogram Your Keyboard Keys

I recently got a new Microsoft keyboard without the Right-Windows-Key. I use this all the time ’cause I’m a shortcut fanatic, and I couldn’t get used to using the one on the left. Not only that, but I use a CTRL/SHIFT + INSERT a lot to copy/paste and the keys were way different from my past keyboard…

along comes AutoHotKey….

This program rocks. With it, you can create a script that runs and stays in memory. Remap keys and buttons on your keyboard, joystick, and mouse. In any case, with this tool, I was able to remap the menu key (the one usually between the Right-Windows-Key and CTRL key) that I never use to a windows key. That was close enough to me. Once installed, I was able to create a script with this command:

AppsKey::RWin

And that’s it! That mapped the menu key to the windows key! I’ll be experimenting with this program a little more and trying to get more shortcuts. You can also compile your scripts into a program that runs without an installation – in case you want your shortcuts / remapping run on a different machine.

The URL is: http://www.autohotkey.com/