BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Conversion Utility
 Rock Paper Scissors Game
 Random Number Generator
 DayLightTime
 BlogRoll
 Purchase Shareware
 Support
 Privacy

 


Thursday, November 22, 2007
A little System.Diagnostics

I am not going to get overly verbose here; however the importance of application logging is immeasurable. When applications are deployed, obtaining ‘real life’ application can assist in diagnostic and overall application health situations. Excessive logging can be ineffective (too much to analyze) and burdensome (logging to a text file that grows forever) if not implemented appropriately.

When developing and deploying an application having the flexibility of what, when and how to log can alleviate the burden and ineffectiveness of logging. The System.Diagnostics namespace has a number of classes available that allow for this type of flexible logging. The applied use of these classes allows a developer to specify what to log in an application at various levels of detail within one application without the need to deploy diagnostic builds. Depending on diagnostic needs, the application’s config file can specify the level of diagnostic information to write and where. A simple Logging class (this is the class I created to use this functionality) can be developed as follows:


1namespace BPSoftware
2{
3 public class Logging
4 {
5 /// <summary>
6 /// strNameSpace is the base namespace for use in the logging message.
7 /// </summary>

8 public static string strNameSpace;
9
10 /// <summary>
11 /// GeneralTraceSwitch is a traceswitch object for logging. Switch level is set through
12 /// the application config switches section. The destination listener is also set through
13 /// the application config file.
14 /// </summary>

15 public static TraceSwitch GeneralTraceSwitch = new TraceSwitch( "General", "General Trace Switch" );
16
17 Methods
86 }

87}

Throughout the application logging messages can be added:
1 catch ( Exception ex)
2 {
3 Logging.WriteLineTraceError( "ClassName", "Method", "Exception: " + ex.Message );
4 }

5
6 Logging.WriteLineTraceInfo( "ClassName", "Method",,
7 String.Format( "{0}: {1}", e.ActionType.ToString(), e.Message )
8 );


The application’s config file can then be altered to determine the appropriate level and location of the logging based upon certain diagnostic needs. The switches node specifies what level of logging should occur. The switches operate in a hierarchial fashion (3 includes 3, 2 and 1; 2 includes 2 and 1):
1 <system.diagnostics>
2 <trace autoflush="true" indentsize="4">
3 <!-- Specify listener output -->
4 <listeners>
5 <remove name="Default" />
6 <!-- Write to a log file -->
7 <add name="Default"
8 type="System.Diagnostics.TextWriterTraceListener"
9 initializeData="AFileSync.log" />
10 <!-- Write to the Event Log-->
11 <!-- <add name="Default"
12 type="System.Diagnostics.EventLogTraceListener"
13 initializeData="Application" /> -->
14 </listeners>
15 </trace>
16 <switches>
17 <!-- Off = 0, Error = 1, Warning = 2, Info = 3, Verbose = 4 -->
18 <add name="General" value="3" />
19 </switches>
20 </system.diagnostics>


Using the application’s config file to specify the level of logging allows for the capture of diagnostic information of a stable build to capture ‘real world’ information. The flexibility of the listener to write to (you can create customer listeners) is an added bonus!

Labels: , , ,

posted by Brad Prendergast at 8:49:00 AM (0 comments)
Links to this post
Permalink
Sunday, September 30, 2007
Compact that Virtual PC

I have long been a fan of Virtualization. Ever since the early days of Virtual PC, I have been spinning off virtual machines to test and install software applications and code. It has even gotten to the point where I do very little on my host machine. I even do most of my web browsing within a Virtual PC (you can't always be certain what sites will do to your host machine). The flexibility of being able to install, test and uninstall applications without affecting the host offers many benefits. There is also a bonus with the Undo Disk option within Virtual PC. With an Undo Disk you can start up a Virtual PC and do “your thing” and then have the option of committing or deleting the session changes upon shut down. Take the benefits of virtualization and the fact that Microsoft Virtual PC 2007 is free and it is no wonder why Virtualization is now mainstream.

One thing that I had noticed using Virtual PCs is the disk size of the virtual hard disks. The virtual hard disks can be of fixed or variable size. If you opt for a variable sized hard disk, the disk will grow as you use it. The installation of application, copying of files and general processing use will cause the amount of space the virtual disk uses on the host machine to grow. As files are removed, applications are uninstalled and processing decreases I noticed that the virtual hard disk size doesn't decrease. In the help file there is a section that explains how to "Compact a virtual hard disk". The steps are pretty straight forward as they explain how to use the Virtual Disk Compaction option through the Virtual Disk Wizard. I did this on a number of virtual hard disks and really wasn't impressed with the results. To be honest, I didn't notice any change in the size of the virtual hard disk after running this process.

After a little confusion I noticed one important note that is in the help file, "Before compacting the disk, we recommend that you use a disk utility to zero out blank space, which should result in a smaller compacted virtual hard disk". After I thought about it, it did make a lot of sense. Now, where do I get one of these little utilities?

In the Virtual Machine Additions folder (under the Microsoft Virtual PC program folder) there is a Virtual Disk Precompactor.iso file (I found the "Using Virtual Disk Precompactor" section of the help file afterwards). It didn’t take much for me to figure out that this utility probably should be used prior to compacting a Virtual Hard Disk. It was a simple enough test; after all I was only trying it within a virtual PC. If you capture this iso file from within the Virtual PC and autoplay it, this utility will "prepare the virtual hard disk for compacting". After you run this utility, close down the Virutal PC and follow the steps for compacting a virtual hard disk found in the help file (you'll need to commit the changes if you are using an Undo disk). Take a look at the size of your vhd's before and after, the difference will be shocking. I know I reclaimed many many gigabytes of space on my hard disk.

Another great feature that is worth looking into is a Differencing disk….

Labels: , ,

posted by Brad Prendergast at 8:53:00 AM (3 comments)
Links to this post
Permalink
Monday, January 01, 2007
Running a .NET Framework application from a network location

If you're anything like me, when deploying certain applications in a corporate environment you like to run your applications from a network resource. This often allows for the easy application maintenance of updates and changes. When deploying a dotNET application it isn't always as easy as placing a shortcut on the workstation or running the application from a network drive. With the additional security found in the .NET Framework it is often necessary to configure your application to run from a network location. This MSDN article explains how. The Grant permission to the application section is the part of interest.

Labels: , ,

posted by Brad Prendergast at 11:47:00 AM (0 comments)
Links to this post
Permalink
Saturday, May 27, 2006
Custom Word Fields

The use of Field information in Microsoft® Word allows for easier maintenance of your documents. Using fields, you can include references to document property information within your document. This avoids the need to update changing property information that is referenced within a document (title, author, etc...). Using fields with templates makes format standardization a bit more exciting. Besides the standard fields, you can also reference your custom document properties. Personally, I often reference custom document revision information.


To reference custom properties in your document you first need to set them up. In my case, I use MAJ_REV and MIN_REV, both of these are of type Number. In your Word document move the cursor to the location where you would like to insert your custom property and press CTRL+F9. This will insert a Word field denoted by brackets (note that you cannot type these in yourself, you must press CTRL+F9 to indicate it is a field). Between the brackets type DOCPROPERTY followed by the property name you would like to reference. While the cursor is still on the field, press F9 to update it and there you go….

Labels: , , ,

posted by Brad Prendergast at 8:09:00 AM (0 comments)
Links to this post
Permalink
Saturday, March 18, 2006
ARP! ARP!

(Sound like a seal?)

The Address Resolution Protocol (ARP) is used by the Internet Protocol (IP), specifically to map IP network addresses to the hardware addresses. Each Network Interface Card (NIC)/adapter has a unique Media Access Control (MAC) address. The MAC address is one way a computer can be identified.

It is easy enough to get the MAC address for a local machine by entering the command ipconfig /all in a console window. This command shows detailed information for each adapter installed on a computer. The MAC address of an adapter is identified as the Physical Address. Easy enough, but how do you get this information for a remote machine?



Included with Windows® is a program by the name of arp.exe. Without getting too involved, keeping it simple, and assuming a basic understanding of networking, ARP.exe (console window) is used to display and modify the IP-to-Physical address translation tables. This command has a number of parameters, in particular the –a parameter displays the current resolution table entries. Basically, when you type arp –a each machine that an adapter ‘communicated’ with is listed in this table. Both the IP address and Physical Address are listed for each.




If there is an adapter that you are capable of connecting to and you do not see it the resolution table, initiate some ‘communication’ with it and check the resolution table again (arp – a). Generally, I PING (Packet INternet Groper) the machines/adapters I want to get the information of before I look at the table.

If you haven’t done so yet take a look at AddrMon.

Labels: , ,

posted by Brad Prendergast at 11:20:00 AM (0 comments)
Links to this post
Permalink
Tuesday, January 03, 2006
FTP Batch

File Transfer Protcol (FTP) is a quick way to transfer files between two computers. There are many FTP software programs, both the pay and free varieties, available. Windows® also includes a command line FTP program (ftp.exe).
In this GUI world many shutter at the thought of a command line application, however this one does have its advantages. For starters it is already included in the OS and doesn’t need to be installed. I attempt to not over complicate things and keep them clean and uncluttered. IMHO, the main advantage is the ability to process a text file that contains FTP commands. The parameter option to specify the text file to process is -s (to see the other parameter options at the command prompt type FTP -?).

This feature is advantageous because you can set up FTP batch files that perform various transfer actions without the need to click a number of buttons or type a number of commands. Login information can be included in the text file allowing access to those FTP locations that require user authentication. I have a number of batch files that I frequently use to transfer data. I have also set some up with the Windows® task scheduler for unattended processing.

A batch file could look something like this:
ftp -s:somefile.txt

In the somefile.txt file:
open 192.168.100.1
username
password

cd images
lcd images
send *.gif


The text file commands are passed a line at a time for processing. As displayed in the above example a username and password can also be passed, as those are typically the first two prompts after an FTP server connection is opened. The text file can contain any of the valid FTP commands (type ? at the ftp> prompt for a list of valid commands). I tend to be brief in my postings but hopefully you can see the value in the ability to do this. If you have any additional input I’d love to hear it.

Labels: , , , , ,

posted by Brad Prendergast at 6:32:00 PM (1 comments)
Links to this post
Permalink
Saturday, November 26, 2005
Ode to Backup

Backing up your files is probably one of the most important things you could do. There is nothing worse than the feeling of loosing everything once your computer is on the fritz (I have received dozens of frantic phone calls asking how to, or if I can restore files). There are many commercial, shareware and freeware backup programs that are capable of accomplishing appropriate backups.

XCOPY has been included in the Microsoft® OS family since the DOS days. This little command prompt program copies file and folder information based upon the selection of a number of parameter options. This utility is lightweight and consists of a simple executable file. This is actually what I use for incremental backups of my personal system.

Open a command prompt and type xcopy /?. This displays a list of the xcopy.exe parameter options and their meaning. From the command prompt you can easily type in your xcopy command with the necessary parameters and you’ll be on your way. Personally I have a small batch file called backup.bat. This eliminates a lot of typing and the need to remember the options. This batch file is simple but extremely effective in giving me copies of the files I need. It consists of one line:

xcopy *.* c:\wutemp /S /C /I /M /F /R /H /K /Y /EXCLUDE:exclude.txt

My backup.bat file is located in the root of my profile directory, for this example we’ll say C:\Documents and Settings\BP. If you follow the parameters you’ll notice that I copy all the changed (archive bit set) files to C:\wutemp. This batch file will process the current folder and with the appropriate parameter set (/S) all subfolders as well. Once the backup batch is complete I them manually copy the files to DVD. If you are running a ‘full’ backup you would remove the /M parameter option.
I am fairly structured and organized when it comes to my files. I try to get everything that I need somewhere within the tree of my profile directory. Most applications these days store personal information in the Application Data of your profile directory or allow you to specify a ‘storage’ location. A lot of applications also store temporary or unimportant (unimportant in the sense of need to restore files in the event of a need to recover files) files in your profile directory as well. This is where the /EXCLUDE parameter comes into play. After all, it is really wasteful both time and space wise to back up all those temporary files.
My exclude.txt file looks something like this:

\DOCUME~1\BP\Templates
\DOCUME~1\BP\Start Menu
\DOCUME~1\BP\Recent
\DOCUME~1\BP\SENDTO
\DOCUME~1\BP\PrintHood
\DOCUME~1\BP\NetHood
\DOCUME~1\BP\Windows
\DOCUME~1\BP\Cookies
\DOCUME~1\BP\MY DOCUMENTS\MY MUSIC
\DOCUME~1\BP\LOCAL SETTINGS\TEMPORARY INTERNET FILES
\DOCUME~1\BP\LOCAL SETTINGS\TEMP
\DOCUME~1\BP\LOCAL SETTINGS\HISTORY

This is just an example on how I use XCOPY to back up my important files on my personal computer. In my opinion this is fast, lightweight and effective when it comes to storing those must have files. I hope this gives you some ideas on how you could possibly implement a simple backup solution.

Labels: , , , ,

posted by Brad Prendergast at 5:53:00 AM (0 comments)
Links to this post
Permalink
Tuesday, November 01, 2005
Conditional Format

Spreadsheets are a great tool for analyzing, manipulating and 'testing' data. Over the years there have been significant advances in spreadsheets that allow for a lot more functionality. Based upon my interactions, I feel comfortable in saying that most people are unaware of and/or greatly underutilize many of the functions and features found in most popular spreadsheet applications.

I often find myself importing thousands of records from databases into a Microsoft Excel spreadsheet for some random ‘quick and dirty’ analysis or output. Once in Excel the possibilities are almost limitless when it comes to the representation of this data, whether it’s via pivot table, charts or just a plain old on the fly filtered list.

When viewing thousands of records it is more often palatable and easier on the eyes with some sort of visual record cues. For example, let’s say we’re looking at a list of customer invoice records, which are sorted by customer. Ata quick glance, by default, all the rows generally look the same. Without intense scrutiny the data sort of, blends all together. What about some sort of visual separation by customer? Excel does have Grouping and AutoFormat, however sometimes the grouping can be overkill. All those '+' and '-' can become overwhelming. Don’t get me wrong grouping is great for adding fast subtotals. The AutoFormat is nice for shading; however it shades on alternating records. What if you wanted to shade groups of records? One answer.. Conditional Formatting.

Conditional Formatting allows you to specify cell properties based upon certain value or formula information. After playing with it a bit, one can see that it is really quite useful. For my scenario:


  1. Sort your list
  2. Insert what I call tend to call a 'Helper Column'. This column is typically hidden, and used to indicate when there is a change in a specific value, i.e. Customer. I prefer to put this column as the first or last column in the data set. For this example we will use column A.

  3. Type the following formula in the first data row. We’ll start on row 2 because row 1 is our 'header': '=MOD(OFFSET($A2,-1,0)+ OR($B2<>OFFSET($B2,-1,0),0),2)'. Basically what this formula is saying is alternate 1 or 0 in this cell A2, based upon B2 being different than B1. (The $ before a cell RC value indicates that value is constant (will not change) when it is copied to another cell.)

  4. Copy (or use Fill Down; Ctrl + D) the formula down the entire length of the data set. There are a number of shortcuts that make this easier (Mental note: discuss some quick keyboard navigation another time).

  5. Select the entire data set including the 'Helper Column', making sure you have the upper rightmost column active, A2 in this example.

  6. Select Conditional Formatting… from the Format menu item.

  7. Change condition 1 to ‘Formula is’ and enter ‘=$A2=1’. We’re only going to apply the format if the cell value is 1. The 'Helper Column' should be alternating 0 and 1 on a change in Customer.

  8. Click the Format button

  9. Select the Pattern Tab

  10. Choose which color to fill the cell with when the condition is met

  11. Click Ok to close the Format dialog

  12. Click Ok to close the Conditional Format dialog.



Your spreadsheet should now be shaded by Customer.
This is just a simple sample of using the Conditional Formatting feature of Micrsoft Excel. There are a number of other properties that can be set based upon value or calculated formula that greatly enhances the representation of a data set in Excel.

Labels: , , ,

posted by Brad Prendergast at 6:51:00 PM (1 comments)
Links to this post
Permalink
Thursday, October 06, 2005
My Send To

I think this will start off with a small digression. Delphi is a wonderful software development language. As time gets closer to another release, the usual ‘future of Delphi’ chatter starts to surface. My personal take on Delphi is that it is one of the most powerful development environments/languages out there. I think it just suffers from a lack of and poor exposure. A lack of knowledge and understanding leads to fear and hostility (or negativity). After all it is easier to criticize and 'bash' something rather than admit you don’t fully understand it or are wrong. On to the original though that got me here ….

The ability to right clicking on a file or folder in Windows Explorer and selecting ‘Send To' to perform some action is a great time saver. What better way to quickly e-mail a file to a colleague There is a downfall to the limit the default options leave you. There are often times when I want to copy a file or folder to another location for backup or distribution purposes. There are also times that I’d like to quickly print and unopened text documents.
Under Windows you can add your own choices to the ‘Send To’ menu option. This is surprisingly easier than one would expect. In order to do this you first need to make sure that you have explorer set to show hidden program or system files. Next, browse to C:\Documents and Settings\<youraccountname>\SendTo. Once you open the Send To folder you will notice that the other send to shortcuts. Place a shortcut to your favorite folders or printers (I find it easier to just drag and drop printers into this folder) in the SendTo folder to have it appear in the list.

Labels: , , ,

posted by Brad Prendergast at 8:33:00 PM (0 comments)
Links to this post
Permalink
Wednesday, October 05, 2005
Straight to the Prompt

Even in the world of Windows it is often necessary to perform tasks via the command prompt. Along with the console applications that I have created, there are many other command line utilities that I use. Often, these utilities need to be run within a specific directory (a.k.a. folder). Instead of opening up the command window and changing to the desired directory, I find it much easier to open up Windows Explorer, right click on a folder select a menu option and have a command window open, already changed to a selected directory (similar to New Date Folder). This option is not a standard part of Windows Explorer but can be added rather easily.


1. Open Windows Explorer
2. Select Tools --> Folder Options
3. Select the File Types Tab
4. Select Folder from the list of Registered file types
5. Click on Advanced
6. Click the New… button
7. Type Prompt in the Action field
8. In the application field you can type one of two lines:
command.com /k cd %1
or
cmd.exe /k cd "%1"
The difference between the two is that the first option will browse with short file name and the second with long file names.
9. Keep clicking the OK button until you are back to Windows Explorer


You can now right click on a folder and easily get to a command prompt in a selected directory.

As always, proceed with caution when changing file types or any system setting. Basically, if you are uncomfortable doing this type of stuff then it might be best if you consult someone that has a high comfort level in making these types of changes.

Labels: , , ,

posted by Brad Prendergast at 3:34:00 PM (0 comments)
Links to this post
Permalink
Monday, October 03, 2005
New Date Folder

I constantly backup and keep revisions of documents stored on my computer. For sorting and identification purposes typically create a folder with name conjured up using the current date and time. I usually create a folder name with the following format: ‘yyyymmdd hhmmss’. This allows me to see exactly when a ‘snapshot’ was taken and they pretty easy to sort in the correct order.

Opening Windows Explorer, browsing to the desired folder, selecting File--> New -->Folder and then renaming the folder, IMHO, takes way too much effort. I find it a lot easier to just open Windows Explorer, right clicking on a folder and then selecting ‘New Date Folder’ from the context menu . This speeds things up significantly and requires a lot less thought.

The ‘New Date Folder’ option can easily be added to your context menu as well. First open up notepad (or your favorite text editor) and enter the following text:

@echo off
SET MONTH=
SET DAY=
SET YEAR=
SET HOUR=
SET MIN=
SET SEC=

SET MONTH=%DATE:~4,2%
SET DAY=%DATE:~7,2%
SET YEAR=%DATE:~10,4%

SET HOUR=%TIME:~0,2%
IF "%HOUR:~0,1%" == " " SET HOUR=0%TIME:~1,1%

SET MIN=%TIME:~3,2%
SET SEC=%TIME:~6,2%

md "%1\%YEAR%%MONTH%%DAY% %HOUR%%MIN%%SEC%"

Save that document some place on your local hard drive as a batch file. The batch ‘datetime.bat’ in the folder C:\Batch is what I will use for this example. Next, open up Windows Explorer and select Tools --> Folder Options from the menu bar. This will open the Folder Options Dialog. Select the File Types tab. Scroll to Folder in the Registered file types list and click the Advanced button. In the Edit File Type dialog click on New. Type New Date Folder in the Action field and cmd.exe /c c:\batch\datetime.bat "%1" in the application field. Click OK on each of the open dialogs until you get back to Windows explorer. You should now be able to right click on a folder and be able to select New Date Folder to create a new subfolder with the current date and time.

One thing to note is that this will not work on network folders unless they are accessed via a mapped drive. Also, you may have to work with the precision on the SET lines in the batch file to work with your system's regional settings.

If you are uncomfortable or unfamiliar with any of the concepts discussed here you should probably refrain from doing this yourself and consulting someone who has a greater comfort level. I am sure you don’t want to inadvertently change anything that could potentially lead you to some computer headaches.

Labels: , ,

posted by Brad Prendergast at 2:22:00 PM (0 comments)
Links to this post
Permalink
Recent Posts
 My Shared RSS Items
 Edit those XML files
 A little System.Diagnostics
 Wi-Fi Detector Shirt
 Control and List Windows Services
 Let's Synchronize Some Files
 Compact that Virtual PC
 Is it Hammer Time?
 DSOFile and Summary Properties
 ShellExecuteEX and ShellExecuteInfo Revisited
Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
Powered by Blogger