The following code snippets are presented as-is. They are not complete components, but are designed for copy-and-paste into your code.
This is a specialization of the "Use PDH Interface to capture NT Performance data" code (below). The code with automatically bring back all the processes running, and allow you to select one of those processes. If you then hit the <Start> button, you will see the percentage of CPU time in the listview control for that process.
These two simple add-ins for VB will allow you to add a comment block (in a modified "flower box") format) or add you initials to the end of a line of code.
To install either of the add-ins, just run the compiled EXE and answer any questions it asks (like end column, or your initials).
The comment block consists of the following:
Note that as supplied, the comment will start on the nearest column to your cursor that is a multiple of three (i.e., you have the tabs set to 3 instead of the VB default of 4), and it will extend to column 48. You can change the "extend" column when you install the add-in, but to change the starting column you must change the code.
The add-in to add your initials is based on code by Chris Barlow in Visual Basic Programmer's Journal (VBPJ), but adds your initials to the *end* of the line your cursor is on instead of adding your initials in a new line immediately above your current line (as in original article).
Now you've created a really neat TypeLib to contain all your app's enums. But there isn't a command-line utility to register or un-register that TypeLib. This small applet will allow you to register and un-register that TypeLib from either the command line or from a GUI interface.
Enums can be created in VB 4.0 or 5.0 classes. But suppose you want to share those enums between multiple components. Or if you want to actually document both the enum and the elements in the enum (so that the documentation is visible in the Object Browser)? Well, this little text file will show you how. Note that you will need MKTYPLIB.EXE (comes with C++) or equivalent to compile the ODL file into a TypeLib (TLB) file. But after compiling, all you have to do is add a reference to the TypeLib in your program.
Download: TypeLib Text
Performance data is crucial to monitoring an NT machine. In the September 1997 issue of VBPJ (Code for ToolHelp NT) I demonstrated how to use PSAPI.DLL to return a subset of the performance-data from NT and get the ToolHelp32 type of data programmatically. But to generically retrieve performance data, you need to use PDH.DLL.
There are only 11 functions in the PDH.DLL specifically designed to be used by Visual Basic. In the demo program below, I use 6 of those functions to produce a simple but functional demonstration of retrieving performance data.
Download: PDH Demo
Ever get tired of opening a group project and having 20 code windows pop up? This little add-in automatically closes all code windows (but not forms) in the current project.
Download: Clear Code Windows
Very simple demo of how to get the drive type of an attached drive.
Download: Get Drive Type
Sometimes programs, particularly 16-bit programs, mis-behave and must be terminated. This is a very simple example on how to kill such a program. There is no UI, and currently will only try to kill a program with a caption in the main window of "xxx-xxx", but it should give you enough to start on to create a more robust implementation.
Download: Terminate Process
Last modified on: Tuesday March 08, 2005 07:08:40 PM