The following code was all published for Ask The NT Pro, and can also be found at Ask The NT Pro.
To find a project where a particular API is used, look at the API Lookup.
As of 10/02/2000, I will no longer be doing the monthly Ask The NT Pro column. DevX is cutting back on their costs, and to quote, "Your solutions have a regular audience, but not a large one." It 's been a fun run, for about 4.5 years (since 3/98), and hopefully some of the solutions have been helpful to you. I have now updated the projects on this page to include all of the columns, but there won't be any more updates.
The final solution is an extension of solution #42, which uses a slightly different technique (reading the NT registry via WMI) to get *all* the installed software (not just the MSI-installed software) and the engineering quick-fixes installed.
Download: Code for Solution #44
This solution is an extension of code I previously did for VBPJ. It allows you to view the data from a saved *.evt file from either a local or remote computer.
Download: Code for Solution #43
This solutions uses VB 6.0 for the UI, and WMI for the core code to give you a side-by-side comparison of information on two different computers on your network. With this code, you can compare operating systems, computer systems, process, logical disks, physical disks, page files, network adapters, video setting, services, and installed software.
Download: Code for Solution #42
The task manager is an extraordinarily useful tool for diagnosing problems on the local computer. So, a remote task manager would be useful diagnosing problems for remote machines, right? With WMI, it really not so hard to construct.
Download: Remote Task Manager
Reusing code is good, even when you are working with scripting languages. By using WSH (Windows Scripting Host), you can call multiple *.VBS files from a WSH file without copying-and-pasting each time. In other words, you can have shared, reusable code.
Download: Using WSH
How much information about the network and attached computers can you retrieve with WMI? Pretty much as much as you want <g>. The VB GUI shows how to get a fairly large subset of computer information from any computer on the network via WMI calls.
Download: Retrieving Computer Info
Shutting down or rebooting remote computers is fairly trivial with WMI, assuming the machines have WMI installed (all W2K+ computers, can install for NT 4.0 or Win9x). The actual WMI call is simple, and could be used in a script, but I've build a GUI around it to make ad hoc calls simpler.
Download: Rebooting with WMI
You can grab global user and group security information by using NetUserModalsGet. In fact, before ADSI/W2K, it was pretty much the only way to get some of this information. It is still useful for a lowest common denominator approach with works with most of the Windows versions (although the utility itself was only tested on W2k, and the code would need some mods if you *run* the utility in Win9x).
Download: Using NetUserModalsGet
The code gives you a quick way to compare (and optionally synchronize) the time on your computer with any other NT computer on your domain.
Download: Time Synchronization
Continuing with scripting with VBS and WMI (see Translate SIDs to Names with VBS), the first VBS script allows you to find all services which are set to automatic, but which aren't running, on either a local or remote machine. This is useful when you get the "one or more services did not start" on bootup. The second script shows all MSI-installed components (again, on either the local or a remote machine), with either a summary or detail levels.
Download: Scripting with WMI, Part 2 (VBS)
A command-line script is sometimes a better solution than a full-fledged GUI applet. This particular script will translate each SID (S-1-5-21-1857152614-3074254827-3089642312-1128) found in HKEY_USERS into a user name. It will work on either a local or remote registry (assuming you have the rights to read this info). If you are working on a machine with many logons, it makes it easy to determine which SID has the user info you are looking for. If you do need to put this functionality into a utility program, it should be trivial to bring it into VB 5.0/6.0.
Download: Translate SIDS to Names (VBS)
This little example program came from a question on the DevX forums -- "How do I tell (programmatically) if a workstation is locked?". Seems simple, but it's really non-obvious how to do this (or, at least, it was to me). The code is the result of a look of reading (and a little guessing), but it does work, and does make sense. It will also detect if a screen-saver is running, with some limitations. Under W2K+, it will always detect the screensaver. If you are running NT 4.0, it will detect the screen saver only if the "Password Protected" box is checked.
Download: Code for Detect Locked Workstation
I can't count the times I've dragged one after another *VBP file into a copy of Notepad to view the data there -- the components, the references, or the project properties. Wouldn't it be nice to right-click on a *.VBP file and view a condensed, easily readable extract from that file? This project is a standard executable that will allow both command-line and drag-and-drop interfaces, but if you modify and run the included *.reg file (ProjectInfo_NT.reg or ProjectInfo_Win9x.reg), then you will get an addition to your right-click context menu (for VBP files only). Be *sure* to modify the path in the *.REG file to the path of the executable *before* you run it.
Download: Code for VBP Viewer
There aren't a lot of examples of programmatically working with DFS (Distributed File System) for W2K, but here's one in VB 6.0. DFS allows admins to setup one or more share points on the network where all the shares are listed -- definitely a win-win situation.
Download: Code for DFS_Demo
Ok, HardLinks (via CreateHardLink API) are a rather esoteric subject, but are useful in certain situations. The included code works only with W2K+, but there is a alternate API to use with prior versions of NT. BTW, Hard Links have been around since NT 3.1, since they were required for POSIX compliance.
Download: Code for HardLinks
Many times I've needed a way to log the environmental information on a remote user's machine. MsInfo32.exe is good, if Office is installed, but it's not OLE-automatable. This project is a DLL (together with simple test frame) that you can add to your VB application to programmatically log this info to a local text file. It doesn't log *all* the parameters, but it does do those that have helped me in the past.
Download: Code for Computer Environmental Information
Download: Sample Text Output
The code included lets you save the NT event logs to either the default binary format or a delimited format (you pick the delimiter) via WMI. A UI is included to exercise the class. The code also shows you how to monitor event log "events" and look for any entries with a specific Event ID.
Note: a minor bug (thanks Earl Damron) has been fixed. If you want to fix it yourself without re-downloading, just go to Form2, and set the option button(0) value to FALSE. Since it was set to TRUE, setting the option value in the Form_Load did not actually do anything, and thus did not initialize the module-level variable.
Download: Code for Administering NT Event Logs
The code includes two ways to reboot local or remote NT machines -- via the API, or via WMI. Each method has positives and negatives, but this selection should give you enough choices to find one that meets your need.
You can also use the utilities included in the NT Resource Kit. See the full solution at Ask the NT Pro.
Download: Code for Local and Remote Rebooting
This is an extension of the "Programmatic File Compression" (below) which allows you to encrypt of decrypt files and directories in Windows 2000. Note that Encryption and Compression are mutually exclusive in W2k, although Encryption does actually compress the file somewhat.
A single reusable class, NtEncrypt.cls, is included, as well as a UI to exercise the class.
Download: Code for Compress and Encrypt
Once you get past a couple of oddities, programmatic file compression on NT NTFS directories is very simple. This short program will show you how to do it..
Download: Code for NT File Compression
Show all the NT-only file attributes: like encrypted, compressed, sparse, off-line, context index, and temporary. Also, show the file size and size on disk (useful when you have compressed files).
Download: Code for NT File Attributes
Some programs, particularly older ones, cannot use long file names or paths (particularly if they contains spaces).
This is a very small utility with allows you to get the short name/path from a long name/path. The most useful way to use this utility is to put a shortcut to the EXE in your SendTo folder (on NT 4.0, at x:\WINNT\Profiles\MyUserName\SendTo -- on W2K, at x:\Documents and Settings\MyUserName\Send To) . In this way, when you right-click on a file (or directory) and select SendTo, you can get the short path/name directly without doing a lot of typing.
Download: Code for Short File Paths
Get a network user's home directory with ADSI.
Download: Code for Get Home Directory
How to enable or disable a NT User's account via the API (as opposed to via ADSI, if you have it available)
Download: Code for Disable Account
Disk quotas are a long asked-for feature in NT. Now,
with W2K, we have them, and a reasonably simple COM interface (callable from
Visual Basic and even script languages) to boot.
The download is a *very* simple interface for setting disk quotas for NTFS volumes on a volume basis. Not a lot of error trapping, and a rather simple-minded UI, but it should be enough to get you started.
Download: Code for Disk Quotas
You might want to download the more complete VBPJ code (I expanded it from the Ask The Pro column at:
Download: VBPJ Code for Disk Quotas
Get NIC information with WMI
Download: Code for WMI: Another Example
A quick example of how to use WMI to get info in hard disks.
Download: Code for WMI Demo
How to save a specified registry (and all it's subkeys) via API calls. It's saved in a binary format -- efficient for large amounts of info, but not human-readable.
Download: Code for Save Keys
Last modified on: Tuesday, 08 March 2005 07:16:15 PM