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.

ANT Script to Deploy

A friend of mine asked me to post a simple script to show the power of ANT. Here it is with comments that show some of the things you can do with it. To read how to set up ANT and run scripts, please read my earlier post on doing so.

This script gets the latest from an SVN repo, deploys using FTP, then sends an email using a Gmail account. Here’s the ant script (deploy.ant), followed by a properties file (i.e. the config file, deploy.properties), which the ANT script pulls from:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?xml version="1.0"?>
<!-- ======================================================== -->
<!-- Sample build file used to retrieve svnant's sources -->
<!-- ======================================================== -->
 
<!-- TODO: Mail if the script failed --> 
 
<project name="STAGING-Deploy" basedir="." default="empty">
 
  <property file="STAGING-Deploy.properties" />            
  <!-- Import SVNAnt tasks from jar files.  -->
  <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />
 
  <target name="Deploy"> 
    <!-- Step 1: Export the latest files from the repo to local machine. -->
    <antcall target="export" />
 
    <!-- Step 2: FTP the files from the local machine to STAGING. -->
    <antcall target="ftp_files" />
 
    <!-- Step 3: Cleanup. -->
    <antcall target="cleanup" />  
  </target>  
 
 
  <!-- SVN Checkout (Latest) -->
  <target name="checkout_latest">
    <svn username="${svnant.repository.user}" password="${svnant.repository.passwd}">
      <checkout url="${svnant.projectrunk.url}" revision="${svnant.checkout.revision}" destPath="${svnant.checkout.destpath}" />
    </svn>    
  </target>   
 
  <!-- SVN Update -->
  <target name="update_latest">
    <svn username="${svnant.repository.user}" password="${svnant.repository.passwd}">
      <update dir="${svnant.update.directory}" recurse="${svnant.update.recurse}" revision="${svnant.update.revision}" />
    </svn>    
  </target>  
 
  <!-- SVN Export  -->
  <target name="export">
    <svn username="${svnant.repository.user}" password="${svnant.repository.passwd}">
      <export srcUrl="${svnant.export.srcurl}" destPath="${svnant.export.destpath}" force="${svnant.export.force}" />
    </svn>    
  </target>
 
  <!-- FTP the export of the latest revision to STAGING. -->  
  <target name="ftp_files">    
    <!-- Import FTP tasks from jar files.  -->
    <taskdef classname="org.apache.tools.ant.taskdefs.optional.net.FTP" name="ftp" />
 
    <ftp server="${ftp.server}" port="${ftp.port}" remotedir="${ftp.destination}" userid="${ftp.userid}" password="${ftp.password}" 
         passive="${ftp.passive}" depends="${ftp.depends}" binary="${ftp.binary}" retriesAllowed="${ftp.retriesallowed}" verbose="${ftp.verbose}">
 
      <fileset dir="${svnant.export.destpath}" />
 
    </ftp>    
  </target>  
 
  <!-- Cleans Up: Remove temp info, etc. -->
  <target name="cleanup">  
    <delete includeEmptyDirs="true">
      <fileset dir="${svnant.export.destpath}"/>      
    </delete>
 
    <!-- Email Notification -->
    <mail mailhost="${mail.host}" mailport="${mail.port}" subject="${mail.subjectalert}" ssl="${mail.ssl}" user="${mail.username}" password="${mail.password}">
      <from address="${mail.from}"/>      
      <to address="${mail.to}"/>
      <message>The nightly build has completed.</message>
    </mail>
 
    <echo>Cleanup complete. </echo>
  </target>
 
  <target name="empty">    
    <echo>Pass in a default target to call </echo>    
  </target>
 
</project>

Now let’s check out the properties file (deploy.properties):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -----------------------------------------------------------------------------
# STAGING-DEPLOY
# Variables are initialized here.
# -----------------------------------------------------------------------------
#
# NOTE: Backslashes have to be escaped with another backslash (on Windows)
#
 
# === INIT =====================================================================
svnant.projectrunk.url=svn://192.168.3.142/TESTING/trunk
svnant.repository.user=YOURUSERNAME
svnant.repository.passwd=YOURPASSWORD
 
# === CHECKOUT (INITIAL) =======================================================
# Check out a working copy of the latest to a local directory.
svnant.checkout.destpath=C:\\testing123
svnant.checkout.revision=HEAD
 
# === UPDATE TO LATEST =========================================================
# Update the working copy of your local directory to latest revision
svnant.update.directory=C:\\Experiments\\Firehawk\\src_latest
svnant.update.revision=HEAD
svnant.update.recurse=true
 
 
# === EXPORT ===================================================================
# Copies From Source Repo:
svnant.export.srcurl=${svnant.projectrunk.url}
 
# Into a temporary directory in your ant home (that will be FTP'd):
svnant.export.destpath=${ant.home}\\export-temp
 
# Overwrite (needs to in case the file changed)? 
svnant.export.force=true
 
PBNStagingFTP
# == FTP INFO ==================================================================
# FTP what was exported (latest version) to this location on staging:
ftp.destination=/testing/
ftp.server=TESTING
ftp.port=21
ftp.userid=USERNAME
ftp.password=PASSWORD
ftp.passive=yes
ftp.depends=yes
ftp.binary=yes
ftp.retriesallowed=5
ftp.verbose=yes
 
# == MAIL INFO ==================================================================
# Currently using GMAIL for now.
mail.host=smtp.gmail.com
mail.port=465
mail.subjectalert=[STAGING ANT Build] Test build
mail.ssl=yes
mail.username=USERNAME
mail.password=PASSWORD
mail.from=someone@somewhere.com
mail.to=someone@somewhere.com

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:

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

 

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

1
add 5 5

9

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.

JavaScript for the Windows Command Console

JSDB is a great JavaScript interpreter based on Mozilla’s Spidermonkey JavaScript engine. If you like working off the command console, I suggest you give it a go. Of course, not everything is supported, as there is no HTML/DOM context in the console. To compensate for it, the author of this tool has added some great features, like being able to connect to databases, use includes ( easily via the load(“file.js”) function ), and other network facilities, like fetching HTML content from other websites.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- 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:

1
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):

1
2
-- 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:

1
2
3
4
5
6
7
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

LogParser to Query IIS logs using SQL

LogParser is a great way to query IIS logs (any text log, actually, that is delimited).

Once you have it installed (default install is to C:\Program Files\Log Parser 2.2), let’s try to query log file ex090915.log from directory C:\WINDOWS\system32\LogFiles\W3SVC1942853941 . The way you would do this, is this:

1
LogParser "select date, s-ip, cs-method from C:\WINDOWS\system32\LogFiles\W3SVC1942853941\ex090915.log" -rtp:-1

As you can probably imagine, “date”, “s-ip”, and “cs-method” are the column headers from the log file. The select statement goes in quotes. Also, rather naming a table, you give the path to the log file. What’s the argument -rtp:-1 ? If you don’t include this argument, every 10 results, it will prompt you to “press a key…,” then will show you the next batch of results. In any case, the select state we just ran will spit out the following in the console:

date       s-ip            cs-method 
---------- --------------- ---------
2009-09-15 192.168.157.128 GET
2009-09-15 192.168.157.128 GET
2009-09-15 192.168.157.128 GET
2009-09-15 192.168.157.128 GET
2009-09-15 192.168.157.128 GET
2009-09-15 192.168.157.128 GET
2009-09-15 192.168.157.128 POST
2009-09-15 192.168.157.128 POST
 
 
Statistics:
-----------
Elements processed: 27
Elements output:    27
Execution time:     0.02 seconds

LogParser will even generate graphs (.gif format) of your results.

If you want to use a GUI for your queries, I suggest you try Log Parser Lizard.

New Eclipse Project with SVN Import

This requires Subclipse. If you want to create a new project and fill it with SVN source code, you can do as follows. This creates a project where you can apply Subclipse operations.

  1. Create a directory where you want to import your files from the SVN server

  2. Right click on any existing project (doesn't matter which one)

  3. Click on import

  4. Select SVN -> Checkout Projects from SVN

  5. "Use existing repository location" radio button

  6. Select a folder (you must select a folder, not just the repo) for the folder to be checked out from SVN

  7. "Check out as a project configured using the New Project Wizard"
    Leave all options as default and click finish.

  8. Select the project type

  9. put in a project name and the location of where the files are going to be
    put in (from step 1).

Setting Up Ant

ant_logo_large

Ant (Another Neat Tool) is a tool to automate tasks needed to run successful builds, deployments, and tests. You can run Ant as a stand-alone tool, or run it from Eclipse.


Needed JAR Files

In Ant, a "task" is a single line of instruction that gets run in the build file, as opposed to a "target" which is a group of tasks. There are a core set of tasks in Ant: copy, delete, echo, and many more (http://ant.apache.org/manual/). Other important tasks (like FTP/SVN/Mail functionality), however, are not included. For that reason, we need to include these "add-ons" into Ant in the form of JAR files into Ant's classpath.

The following is a list of additional tasks we need, that are not part of Ant's core task list (download these before reading on):


Setup to Run Stand-Alone
  1. Install the JRE, if you don't already have it.

  2. Download latest version of ANT: http://ant.apache.org/bindownload.cgi and unzip to c:\Ant

  3. Download the above latest JAR Files in Zip files. Zip files you download may have more than just JAR files, but you need to isolate these JAR files and put the JAR files into Ant's classpath, C:\Ant\lib


  4. Put all the JAR files under C:\Ant\lib

  5. Add the following variables to your SYSTEM Variables
    ANT_HOME=C:\Ant  

     
    Add this to your existing PATH variable:

    C:\Ant\bin;  

     
    Also, make sure there's a CLASSPATH and JAVA_HOME system variables setup for the JRE.
    e.g. 

    CLASSPATH=.;C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip  
    JAVA_HOME=C:\Program Files\Java\jdk1.6.0_07  

  1. That should be it. Try to run, go to the command console and type "ant". To load a build file, type:
    ant \-buildfile build.ant  


Setup to Run From Eclipse

The typical Eclipse setup already comes with the core Ant tasks, so you just have to get the optional ones. Download the attachment and preferably put them here: C:\Ant\lib

  1. Run Eclipse

  2. Go to Run > External Tools > External Tools Configurations

  3. Double click on the Ant Build Icon
    This will open up the "New_Configuration Wizard"

  4. Name the build DeployStaging (there should already be a name in the field, but it's called "New_configuration"

  5. Under the Main tab, put in the Buildfile (in this case, "Browse File System...") - browse to where your buildfile is. (No need to include the .properties file, as the build file will call it.)

  6. Under the Classpath tab, click on User Entries then click on "Add External JARs..." and point it to the directory which has all the JARs you downloaded (C:\Ant\lib).

  7. Select all the JARs.

  8. Click Apply.

  9. Click Close.

  10. Save if prompted.

  11. Select the build file and then Go to Run > Run

  12. To Modify the script you've just setup, go to Run > External Tools > External Tools Configurations

  13. To select another default target (for example, for to get the latest changes), go to the Targets tab, uncheck the default, and select the target you want (in this case, "update_latest").

  14. Click Apply and close.

  15. To see the build progress in detail, open up the console view by Window > Show View >Other > General > Console.