|
List all COM components on local machine
|
Total Hit (2905) |
The following routine parses the registry and lists all the installed COM components:
«Code LangId=2»
' this code assumes that you have used this Imports statement
' Imports Microsoft.Win32
' Print ProgID, CLSID, and path of all the COM components
' installed on this computer.
Sub DisplayC
....Read More |
Rating
|
|
|
List all running Windows processes
|
Total Hit (2830) |
The System.Diagnostics.Process class exposes the GetProcesses static method, that returns a list of all running processes. It is quite easy to leverage this feature to display all running processes in a ListBox or ComboBox control:
«Code LangId=2»
' This code assume that you've used the followin
....Read More |
Rating
|
|
|
Prevent a second process instance from running
|
Total Hit (3059) |
VB6 developers can use the App.PrevInstance property to check whether there is another instance of the same process already running on the current machine. This property isn't available any longer in VB.NET, so you must retrieve this information by using the properties of the Process object.
The
....Read More |
Rating
|
|
|
Retrieve information about the current user
|
Total Hit (2592) |
You can easily retrieve information about the current user by means of a few properties of the Environment class. The Environment.UserName returns the name of the user; the Environment.UserInteractive property returns True if the user is an interactive user; the UserDomainName returns the user's dom
....Read More |
Rating
|
|
|
Retrieve Windows and System directories
|
Total Hit (3249) |
In VB.NET you don't need to call the GetWindowsDirectory and GetSystemDirectory API functions to retrieve the path the Windows and System directories. Retrieving the System directory is as simple as calling the Environment.SystemDirectory property:
«Code LangId=2»
Dim sysDir As String = Environm
....Read More |
Rating
|
|
|
Get the exit code of a process
|
Total Hit (4184) |
In a few cases, in particular when running MsDos batch files from within a VB application, you may want to determine the ERRORLEVEL set by an external application. You can't do it with a plain Shell statement, but the job becomes easy with the support of the GetProcessExitCode API function:
«Code
....Read More |
Rating
|
|
|
Get the Windows main directories (without any API call)
|
Total Hit (3242) |
The usual way to determine the Windows' main directory is based on the GetWindowsDirectory API function, which requires that you set up a buffer for the result, and then extract the null-terminated result. However, there is a much simpler approach, that works equally well under Windows 95, 98 and NT
....Read More |
Rating
|
|
|
Get the Windows temporary directory (without any API call)
|
Total Hit (3156) |
The usual way to determine the Windows' main directory is based on the GetTempPath API function, which requires that you set up a buffer for the result, and then extract the null-terminated result. However, there is a much simpler approach, that works equally well under Windows 95, 98 and NT. It is
....Read More |
Rating
|
|
|
Hide or disable the desktop icons
|
Total Hit (3613) |
The Desktop is a window like any other window in the system, so you can hide/show and enable/disable it. The only details you need to know is how to retrieve the handle to the Desktop window. It turns out that this window is the first child window of the "Program Manager" window, so all you need is
....Read More |
Rating
|
|
|
Hide or disable the Windows' application bar
|
Total Hit (3231) |
The Windows' application bar (or Startbar) is a window like any other window in the system, so you can hide/show and enable/disable it. The only thing you need to know is that that the class name of the Start bar window is "Shell_TrayWnd" and that its window name is a null string. Here is the code t
....Read More |
Rating
|
|
|
Hide the application in the Task List dialog
|
Total Hit (3367) |
As you know, when you press CTRL+ALT+CANC the Task List window appears. This dialog allows you to see all the running processes and also to terminate them. If you don't want that your application be closed, you can prevent the application from being displayed in the Task List dialog, by using the Re
....Read More |
Rating
|
|
|
How did Windows start?
|
Total Hit (3066) |
If you need to know how Windows was started you have just to call an API function: GetSystemMetrics. Passing the SM_CLEANBOOT constant as parameter, the function returns a Long value with this meaning:
«Code LangId=1»
0 = Normal boot
1 = Fail-safe boot
2 = Fail-safe with network boot
«/Code»
....Read More |
Rating
|
|
|
Implement password-protected TextBox that are really secure
|
Total Hit (2990) |
As explained in another tip in this TipBank, users can peek at the contents of password-protected TextBox controls with a simple Spy-like program, or even with a VB program plus some API functions. The problem is that such TextBox controls react to the WM_GETTEXT message and the GetWindowText API fu
....Read More |
Rating
|
|
|
Open a Control Panel dialog or wizard
|
Total Hit (2754) |
Have you ever needed to open a Windows dialog such as Internet Properties, New Hardware, Modem Properties or any other dialog you can find in the Control Panel? Well, it's very simple, onve you know the trick.
All these dialogs are implemented in files with the CPL extension. (They're actually D
....Read More |
Rating
|
|
|
Open MS-DOS prompt from any directory in Explorer
|
Total Hit (2698) |
By adding a couple Registry keys you can add a commond to the context menu that appear when you right-click a directory when inside Windows Explorer. The new command lets you open the MS-DOS prompt and navigate to that directory with just one mouse click:
«Code LangId=1»
---------------------
....Read More |
Rating
|
|
|
Open Windows's Start menu
|
Total Hit (2094) |
By simulating the pressing of the "Windows" menu - or better yet, of the Ctrl-Escape key combination, which also works on older keyboards - you can programmatically bring up the Start menu. You can't use the SendKeys function to do so, though, and you have to resort to the keybd_event API function:
....Read More |
Rating
|
|
|
Provide a free preview of Office Documents
|
Total Hit (1729) |
NOTE that this tip requires Windows 98, Windows 2000, Windows 95/NT 4.0 + Active Desktop. If your application must do a lot of work with Office documents, then chances are that you might need to provide a quick preview of them. I'm not talking about scrolling pages up and down as in Word or Excel bu
....Read More |
Rating
|
|
|
Retrieve CPU information the simple way (NT/2000 only)
|
Total Hit (1583) |
The Windows API includes all the functions you need to retrieve and display information about the CPU the machine is equipped with. However, if you're running under Windows NT or Windows 2000, you don't need to make complicated API calls, because this information is already available in several envi
....Read More |
Rating
|
|
|
Return a Dos error code on exit
|
Total Hit (2227) |
At times you may want to return a Dos ErrorLevel when closing your VB application. This can be necessary, for example, if the EXE is meant to be called from a batch file. Exiting the program with an error code is really simple, and requires only a call to the ExitProcess API function:
«Code Lang
....Read More |
Rating
|
|
|
Show the contents of the Recycle Bin folder
|
Total Hit (2005) |
You can use the ShellExecute API function to programmatically open a window of Explorer and display the contents of the Recycle Bin. This is the function's declare:
«Code LangId=1»
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpO
....Read More |
Rating
|
|
|
Track changes in system time and display resolution
|
Total Hit (3510) |
Whenever the system time or the display resolution changes, Windows sends all the top-level windows (forms, in VB jargon) the WM_TIMECHANGE or WM_DISPLAYCHANGE message, respectively. Therefore, you can easily determine when these system-wide settings change by subclassing any form in your applicatio
....Read More |
Rating
|
|
|
Undocumented dialog box to change screen saver's password
|
Total Hit (2059) |
When you write a screen saver in C and SDK you can use a static library (SCRNSAVE.LIB) that allows you to create custom dialogs to change and request the password. In VB you can't access this library, but if you don't want to create your forms to replace the custom dialogs, you can use a couple of u
....Read More |
Rating
|
|
|
Wait for the termination of a program using Windows Scripting Host
|
Total Hit (2761) |
If you want to execute an application and waiting for its termination, you can follow two approaches. The "classic" approach is based on API functions such as OpenProcess, WaitForSingleObject and CloseHandle. However, there is a simpler technique based on the Windows Scripting Host object model.
....Read More |
Rating
|
|
|
Change the application priority
|
Total Hit (3012) |
The application's priority - and more in general the thread's priority - indicates how the application is "important" for the CPU. The more the priority is hight the more the CPU will dedicate his time to execute it.
In .NET the priority of a thread is indicated to the Thread.Priority property. B
....Read More |
Rating
|
|
|
Check whether Microsoft Word is installed
|
Total Hit (3146) |
The .NET frameworks provides a set of classes that let you work with the Registry, so it is quite easy to create routine that looks for specific keys to determine whether a program is installed or not. For example, the following code checks whether Microsoft Word is installed on the local computer:
....Read More |
Rating
|
|
|
Create a command-line filter utility
|
Total Hit (2861) |
The Console class exposes two properties that make it very simple to create command-line utilities that work as filters, exactly like the FIND and MORE utilities that are provided with the operating system. The Console.In property returns a TextReader object that reads from the standard input channe
....Read More |
Rating
|
|
|
Determine the Windows version
|
Total Hit (3183) |
You don't need to call any Windows API function in VB.NET to determine which version of Windows your application is running on, because this information is exposed by the Environment.OSVersion property. For example, if you run this code under Windows 2000:
«Code LangId=2»
Console.WriteLine(Envir
....Read More |
Rating
|
|
|
Determine type and number of CPUs
|
Total Hit (4548) |
There is no method call that directly retuns information about the number and type of installed CPU(s). However, this information is stored in a few environment variables, so it's just a matter of extracting it with the Environment.GetEnvironmentVariable method:
«Code LangId=2»
' this code is me
....Read More |
Rating
|
|
|
Duplicate the SET operating system command
|
Total Hit (2662) |
The Environment.GetEnvironmentVariables property returns the list of all the environment variables, as an IDictionary object. If you want to display them sorted by their name, as the SET command does at the prompt, you need the following tricky code:
«Code LangId=2»
' Get all the variables, as a
....Read More |
Rating
|
|
|
Launch another process in a specified directory
|
Total Hit (2772) |
The System.Diagnostics.Process class provides several methods to launch and controls other Windows processes. For example, the following code sample shows how to run Notepad, pass arguments to it, and run it from inside a given intial directory:
«Code LangId=2»
' this code assumes that you have
....Read More |
Rating
|
|