The following code was all published as part of articles and columns in VBPJ/VSM, and can also be found at the VBPJ web site.
To find a project where a particular API is used, look at the API Lookup.
NT+ has an extremely flexible set of API calls which you can use to get information on and about the network. However, most of these don't work on Win9x. There are 20 WNet* API functions, and 12 Net* API functions that work on both operating systems. The class (NetCalls_32.dll) detects the operating system it is running on, and makes the appropriate calls. Note that for the Net* functions, even though the same calls may work on NT and 9x, the parameter declarations are different (and aren't as simple as integer vs. long)
06/09/2002 -- Thanks to Chris Smith, some minor bug fixes
This is an update of the 1996, VB 4.0 version of reading from the NT Event logs. It offers greatly improved performance, almost totally refactored code, and increased flexibility in filtering events. Events can be filtered either on the "server" (the DLL) or the "client" (the UI). Each method has advantages and disadvantages -- use the one that is best for your situation.
I'm not quite sure why I left out the code to retrieve the name, not just the SID of the user. But the latest code below does this task.
Download: Read NT Event Logs 6.0
w/User Name (2002 -- VB 6.0 version)
Download: Read NT Event Logs 6.0 (2001 -- VB 6.0 version)
Download: Read NT Event Logs (1996 -- VB 4.0 version)
Finally, a new version of the program! I have almost totally refactored the code, and moved it fully into VB 6.0. In addition, I've included a utility which allows you to *easily* create and compile Message and Category files
In addition, the code allows you to read from all the event logs (useful if you have a W2K domain controller). It is significantly faster than the original version. And finally, the filtering procedures are vastly improved. You can either "pre-filter" (which skips some of the more expensive operations if the log item doesn't match the filter) or "post-filter" (bring back all the event log items to UI, then filter there).
06/09/2002 -- Thanks to Chris Heywood, minor fix for the CreateMC program. If you have more than 9 categories or messages, it included the decimal number instead of the needed hex number.
Download: Write NT Event Logs
6.0 (2001 -- VB 6.0 version)
Download: Write NT Event Logs (1996 -- VB 4.0 version)
And now for something completely different... Doing builds on a major VB project can be a severe pain in various body parts, particularly when compatibility is broken fairly regularly on some of the components. The included code gives you:
Please read the Readme.txt first before trying any of the code. The idea is simple, but the devil really is in the details for this one. The code is completely data-driven for ease of change. Based on 3 *.DAT files (text), the programs will do a Get on all the files in the various projects from Visual Source Safe, then checkout the ones you need to compile. The program will then do the compiles, in the order listed in the *.DAT file, and if it can't find the version of the dependent VB files in the project needed (due to broken compatibility), it will get the new GUID and version number (using tlbinf32.dll), and try to compile the component again. Finally, after all the various projects are successfully compiled, it will check in all the files to VSS.
Due to the wide variation of ways that projects are set up, and the large number of source control systems (and how they are used), this code will not work unmodified with many projects. If you don't use VSS, for example, you must code a different method to do the checkout and checkin (even if it's batch processing from the command line). Even in these cases, the code should give you a good start on creating your own build automation. I was able to cut the time for a build from several hours down to 10 minutes at a company I worked for, and this was with 80+ VB components over 3 tiers. If you are doing multiple builds a week, this can be a real time saver.
Download: Code for Build Cycle
This project has a COM DLL which allows an administrator to manage disk quotas on NTFS volumes, and a UI to exercise the DLL.
Download: Code for Disk Quotas
The download includes 3 files: an EXE which is essentially just a file-picker, a DLL (FilePermissions) which present the various dialogs you see, and a second DLL (NT_Security) which consists of objects that encapsulate the Security API's. I've tried to comment the code as much as possible, but the code is still complex (due to the API's themselves), so be warned. This code only allows you to set security on files, not directories, but that would be a fairly easy modification. It also does not cover setting security on other NT objects (such as named pipes or registry objects), but that would also be possible with extensions to the current code.
Well, I *finally* got around to updating the code for W2K. I got over 7 requests for this in the last two weeks, so I decided it needed to be done. Thanks to Ola Strandberg for some of the code modifications -- basically, anytime you see a '#If W2K Then', then the code following comes from Ola.
8/5/2001. Sheesh, *another* bug. 'IsDupeAce' does not get the correct user name, since I forgot to update it to work under W2K. Sorry 'bout that, folks, and hopefully the bugs are now sufficiently stomped on.
06/09/2002 -- Thanks to Sarah Shoup for a minor bug fix for the colGroupMembers.Get_GlobalsGroupMembers function. There was an error if the number of entries read was equal to zero.
Download: Code for NT
Download: W2K Version of NT File Security
Creating headers for your various procedures (functions, subs, and properties) is a non-rewarding experience, but a necessary evil. This simple add-in will create a button on your toolbar which allows you to add the information with just one button click while the cursor is located anywhere within the procedure. Enjoy...
Download: Code for Add-In
Thanks to Richard Ober for finding a bug in my Reboot NT program. If you selected both EWX_REBOOT and EWX_FORCE flags, I should have Or'd the two constants together instead of ANDing them. This is the corrected version.
Download: Code for Rebooting NT
All the calls you need to emulate the functionality of the Server Applet from the NT Control Panel (except for Alerts and Replication), all built into a nice COM (ActiveX dll) wrapper. It also includes a standard EXE to exercise the DLL. Enjoy...
Download: Code for Server Applet
Update to the Access database for the BaseDLLAddress article.
Download: Updated Access database (as of 12/22/98) (BaseAddressesDB.zip)
Setting the DLL base address to the default value of &H11000000 has terrible implications for both load times and virtual memory usage for your DLLs and OCXs. Code is included to analyze your \System or \System32 directory for current base memory addresses of your DLLs and OCXs and export those addresses to a tab-delimited file (for export into an Access97 database). The other code included is a GUI which allows you to display the base addresses in that Access database, and to add new items to it, and optionally to write that address to your *.VBP file. Note that the included database file has most of Microsoft's development tools up thru Visual Studio 6.0.
Download: Code for OCX/DLL analysis (GetDLLs.ZIP)
Download: Code for GUI (BaseAddress.ZIP)
32-bit Console apps have always been considered impossible to produce with VB. But with VB 5.0 and a little effort, you can create your own console applications, including the ability to use re-direction (i.e., ">", "<", and "|"). Yes, it's harder to do than with 16-bit console apps (where you could use Quick Basic 4.5 or PDS 7.1), and it's not something you need to do all the time, but it can be a critical component of your programming repertoire.
Download: Code for Console App (All.ZIP)
Example to show how to make return data self-describing, easing the need for UI programmers to understand the implementation details of the business objects. Uses multiple variant array as return data, and the code from "Create Your Own ToolHelp for NT" as an example. However, while the details are NT specific, the overall design is equally applicable to Win95.
Download: Code for ToolHelp NT
Controlling NT Services (as per the NT Control Panel
applet) isn't rocket science. This code shows you how to do this via API calls.
It is included with the code for creating an NT Service, but several people have
requested a separate download for just the control program.
Note that you can also control NT services via ADSI (see ADSI/WMI Code, "ADSI (and WMI) (VBits 2000, Feb 2000)", on this website). If you have Windows 2000, ADSI is installed natively, but you can use it on NT 4.0 (and it works well) by downloading the ADSI install from www.microsoft.com/technet/winnt/winntas/adsi25.asp. If this address changes (and it will), you will have to search for it on the MS site.
You can also control NT services via WMI (code coming soon...)
Download: Code for Controlling NT Services
Yes, Virginia, you can write NT services with VB. It isn't easy, or even recommended by Microsoft, but it can be done. The code presents 2 ways to do this -- one via an OCX from Microsoft, and one in pure VB. Enjoy, but be careful out there....
Download: Code for NT Services
Windows 3.x has ToolHelp.DLL, Win95 has ToolHelp32.DLL, and NT has, well, Performance Data. It also has PSAPI.DLL, which makes gathering process and module information from NT almost easy. The sample project has a ActiveX DLL to encapsulate the PSAPI functionality, and a test form to display the data returned.
Download: Code for ToolHelp NT
What constitutes re-usable code? This sample has 4 levels of reusable code, starting with copy-and-paste and moving up to enterprise reusable. It also gives you a neat OLE server that fulfills the following requirement:
From either a 16- or 32-bit client, pass a fully qualified drive-based path to a file and return a UNC path for that file
Download: Reusable Code
Sometimes you need to programmatically determine what kind of executable a file is *before* running that file. It could not only be a 16-bit or a 32-bit program for Windows, but it could be an OS-2 or POSIX binary. Even for 32-bit programs, you might want to know if it is a 32-bit console application. This code is old-style bit-twiddling, and while written in 32-bit VB, could easily be converted to 16-bit, even for VB 3.0.
Download: All Seasons
Memory-mapped files (MMFs) are not only way cool, but they have some practical uses as well. For many uses, MMFs are overkill, but for transferring large amounts of data between 32-bit applications, the overhead and complexity of MMFs are offset by their efficiencies.
Download: Memory-Mapped Files
If you are still forced into supporting 16-bit applications, this code will allow you to access the long file names of the files on a machine with a 32-bit OS (Win95, NT), and the create, write and access dates of those files. It will also allow you to get the volume information on all the volumes on your network. It uses the Call32.DLL thunking layer (included) to enable these manipulations from a 16-bit programming language.
Download: Let Us Thunk Together
Last modified on: Tuesday, 08 March 2005 07:08:46 PM