Add Control Panel Directly To StartMenu
By Ramprasad K Epram Technologies, India
Create a new folder in "C:\Windows\StartMenu" and name it:
Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}
You can change the Text "Control Panel" to any text if you like. For example:
MyProgram.{21EC2020-3AEA-1069-A2DD-08002B30309D}
When you restart your computer, you will see a new Control Panel entry in the Start menu. Select that entry to see the Control Panel applets.
Display A Legal Notice
By Ramprasad K Epram Technologies, India
In Windows 95/98, open the following key in the Registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Winlogon
Create a New string value LegalNoticeCaption. This is the caption to be displayed on the dialog's titlebar.
Create another string value LegalNoticeText. This is the text to displayed by the dialog.
Restart your computer. You will see the legal notice dialog before the login dialog.
Hide Your Desktop
By Ramprasad K Epram Technologies, India
To Hide your desktop and all the folders it contains, open the following key in the Registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Add a new key NoDesktop, set its value to 1, and restart your computer.
To restore the desktop, remove the NoDesktop key.
Manual Unstall
By Ariel Canievsky
Suppose you install a program and then delete it manually. The Control Panel's
Add/Remove Program applet will still list the program.
To delete the program from this list, open the Registry with regedit and remove its
entry from the key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
The next time you need to remove a program, using the Add/Remove Programs applet.
Monitor System Performance
By Rod Stephens
Use the System Monitor to view system performance (CPU usage).
Start/Programs/Accessories/System Tools/System Monitor
Use the Resource Meter to view system resources (memory usage).
Start/Programs/Accessories/System Tools/Resource Meter
Shutting Down the System With a Right Click
By Jeebu Karthikeyan
- Start/Run/regedit
- Go to HKEY_CLASSES_ROOT\Folder\shell
- Right click the shell and take New\Key. Name it with any name (eg. shut). On
the right side panel there is an entry called Default. Make it the name to
appear in the right click menu (eg. Shut down).
- Right click on entry shut and select New\Key. Name it
"command" (no other name than command). On its default pane (on the right
panel) double click it and type:
C:\Windows\rundll.exe,user.exe,exitwindows
Right click on any folder and you will find an entry called Shut down.
Clicking it will shut down the machine.
Warning: regedit can be dangerous. If you mess up your registry, you can make your system unbootable. Don't do anything with regedit unless you know what you are doing!
Visual Basic Scripting for System Management
By Chris Wagg
I love VBS (Visual Basic Scripting): it's handy and convenient for the
administration of the Desktop, other workstations, and networks too. It's
certainly better than relying totally on batch files and batch scripting.
Plus it works with web pages.
Some people seem to think VBS is primitive and doesn't do the standard
ActiveX objects. Of course it does! By using CreateObject or GetObject,
you can instantiate most objects and work with them. Referencing the
objects is the difficult part since some object browsers don't show internal
names. If you can't find the internal name, one trick is to add the objects
you want to a VB project, save it, then open it with a text editor: all the
internal object names are shown! Another trick is to run REGEDIT and hit
<F3> (Search): type in the filename of the object, like "Comdlg32.ocx", and
keep searching (<F3>) until you find a key called ProgID or
VersionIndependentProgID (preferred). For this object, I found
"MSComDlg.CommonDialog" (the internal name of ComDlg32.ocx).
Here's a VBS code snippet for using the Common Dialog Open file dialog (much
better than "hard-coding" file names into the script):
' VB Script File (*.VBS) by Chris
'---------------------
' Get file to manipulate
On Error Resume Next
Dim CDObj
Set CDObj = CreateObject("MSComDlg.CommonDialog")
If Err Then
MsgBox "Can't create Dialog Object!?"
WScript.Quit
End If
CDObj.MaxFileSize = 260 ' Init buffer (NECESSARY!)
CDObj.Flags = &H1004 ' File Must Exist + no ReadOnly checkbox
CDObj.ShowOpen
Dim fname
fname = CDObj.filename
' Cancel or no file name?
If fname <> vbNullString Then
Msgbox "The file you choose is " & fname
End if
Set CDObj = Nothing
|
Caveats:
- Only Win98 or greater, or NT4 or greater support VB Scripting. Supposedly you can upgrade Win95 or NT3x with VBS, but I haven't tried it yet.
- The objects you are referencing must exist on the computer where the script is being run; also the objects must be properly registered.
By the way, I pasted this code into VB4, VB6, and VBA (on Win98) and it worked without modifications! I didn't even add any references or objects!
Here's an example that makes all workstations Y2K
compliant. I know, the year 2000 has come and gone, but we're still getting
NEW machines from vendors that are NOT Y2K ready. This script is important
- it sorts dates properly within the Explorer, Access, Excel, etc; any
VB-defined controls that emulate the objects within these applications, like
the FlexGrid and ListView, need this patch to effectively sort dates too.
' Visual Basic Script Name: Y2K.VBS
':Y2K compliance - Desktop setting
'(same as using control panel)
'
'update only HKCU (system) and (user) will be
'updated automatically -CW
'
'HKEY_CURRENT_USER\Control Panel\International
'HKEY_USERS\(user)\Control Panel\International
'
'key name = sShortDate
'value data = MM/dd/yyyy
'--------------------------------------------------
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
' --> NOTE: for English/US locales only!!
(tweak it for your own locale)
WSHShell.Popup "Updating to 4 digit years"
WSHShell.RegWrite _
"HKCU\Control Panel\International\sShortDate", _
"MM/dd/yyyy"
|
This script seems to work fine for Win98 and NT4. Haven't tested it on
other machines. The only glitch is the change doesn't take effect until
AFTER a reboot. If somebody has the code to make it take effect
immediately, send it to me.
Useful Environment Variables
By Jason Hatt
Here are some useful environnment variables that may be available on your system. You can use the Environ statement to get their values.
Value | Meaning |
NUMBER_OF_PROCESSORS | Number of processors running on the computer. |
PROCESSOR_ARCHITECTURE | Processor type of the user's workstation. |
PROCESSOR_IDENTIFIER | Processor ID of the user's workstation. |
PROCESSOR_LEVEL | Processor level of the user's workstation. |
PROCESSOR_REVISION | Processor version of the user's workstation. |
OS | Operating system on the user's workstation. |
COMSPEC | Executable for command Command Prompt (typically cmd.exe). |
HOMEDRIVE | Primary local drive (typically the C drive). |
HOMEPATH | Default directory for users (on Windows NT this is typically \users\default. |
PATH | PATH environment variable. |
PATHEXT | Extensions for executable files (typically .com, .exe, .bat, or .cmd). |
PROMPT | Command prompt (typically $P$G). |
SYSTEMDRIVE | Local drive on which system directory resides (for example, c:\). |
SYSTEMROOT | System directory (for example, c:\winnt). This is the same as WINDIR. |
WINDIR | System directory (for example, c:\winnt). This is the same as SYSTEMROOT. |
TEMP | Directory for storing temporary files (for example, c:\temp). User, Volatile |
TMP | Directory for storing temporary files (for example, c:\temp). User, Volatile |
System Management Tips
- Keep all the hardware, software, manuals, etc. for a computer all in one box. This is particularly important when you have several computers. For example, suppose you have two computers with different hardware (disk, tape, etc.) from the same manufacturer. This will help you keep the right manuals with the two computers.
- Make backups of all installation diskettes. Even if you take care of the diskettes, they age and can eventually fail. After a dozen or so attempts at installing NT, I had one driver on one diskette fail.
- If something is poorly labeled, label it again. Believe it or not, I got an installation disk from a network card vendor labeled "Plug and play hardware drivers" when it really contained the driver for their card. With that label, it's hard to tell which plug and play device goes with this diskette.
- As you build the system, carefully write down every step you take. Put the time next to each step where you have to do something so you know how long each step will take if you have to reinstall. Keep this list in the box from 1.
- After you build the system, write down all the IRQs, I/O addresses, etc. for all of your hardware devices. In NT I think you can get this using the Devices applet in the Control Panel. Keep this list in the box from 1.
- Norton sells a software product called Ghost that makes image backups of disks. One nice way to use it is to make an image of your system right after you install everything but before you do any work. Put the image on a CD-ROM. Then if you need to reinstall your system, you can backup all the non-system files, use Ghost to reset the system to the state it had when you saved it, and then restore your non-system files.
Unfortunately my edition of Ghost does not let me save a disk image directly to a CD-ROM. It says I should save it to a disk first and then copy it to the CD-ROM. That's ok, but I only have one disk and I cannot save the image on the disk I'm trying to save. Catch 22.
Dan Taney solves the problem like this:
I have found a way around the issue of making an
image of a hard disk when you only have one disk. If you pop up a command
prompt and use the dos command, SUBST to create a "virtual" drive on the same
physical disk. So, you can trick Norton Ghost into thinking you have two
drives. Once you do this, you can successfully make a disk image of your
current disk and save it to the same physical drive, then burn it to a cd.
- Save old copies of software that you need for upgrade editions. For example, if you have an upgrade edition of Word, you must keep an older fully licensed version of that or some other qualifying product to reinstall the upgrade version.
- Try to keep the files you work with every day separate from the saystem files. For example, do not store Visual Basic projects in the Visual Basic installation directory (Visual Basic will put them there if you do not stop it). Keeping these files separate makes it easier to back them up without backing up all the system files (which you do not need to back up very often).
- Perform regular backups! Everyone says to do this but it's amazing how many people do not. Be sure to back up these files:
- Day-to-day files. The programs you write, data files, etc.
- Email. Find out how to export your mail system's mail and back it up.
- Email addresses. Find out how to export your mail system's address book and back it up.
- Browser links and favorites. I keep forgetting to do this and it's annoying. A few minutes surfing at www.microsoft.com lets me find things like the Visual Basic home page and the MSDN search pages. There are some URLs, however, that are hard to remember. One of my clients has a bug tracking URL that is not linked from anywhere else so it's hard to find.
- Passwords. I have dozens of passwords for my Web site, mailing list, client bug tracking site, favorite search engines, etc. Back these up. I file them in a folder in the my mail system so they get backup up with the mail.
- Probably the best backup strategy is to back up every non-system file every day. Every week, save the latest daily backup for the weekly backup. Every month, save the latest weekly for the monthly. Keep the monthlies forever.
You can use different variations on this strategy depending on how painful it would be to reproduce lost data. If you don't have much data that would be hard to replace, you do not need to back it up as often. If you have critial data for a client, you may want to back up more than once per day and you may want to store backups off site in case a fire burns down your computer and the backups.
Installing Registry Entries for All Users
(By Bob Askey)
I would install on a PC logged on as local admin. Then
the user did not have access. So I would temporarily add the user to the local admin
group. That worked OK until I installed for a group of shift supervisors, five people needed
access to the application.
It turned out the add-in part for Excel was only loaded for the currently logged on user. I
found the registry location for the add-in. Exported it as described in the Knowledgebase
article. What I did next worked really good. I found a routine RunOnce.reg. I edited the file
to point to my ExcelTools.reg file that I saved to C:. At the time I didn't realize that this
would really work great. Every user who logged on the RunOnce key would execute and
add the registry add-in to their account. It only ran one time for each user the first time they
logged on.
I didn't need to know who would be logging on. I could logon as myself load everything.
Add the RunOnce and ExcelTools.reg and I was done and it worked for any user logging
on.
Check Resources
(By Theodore Fattaleh)
When making a program, its important to check and see how much resources it is using.
Use the Resource meter and check it by running the .exe, don't check it from Visual Basic because it will not show resources usage.
To make your program use less resources:
- Use label1 instead of Textboxes if you can.
- Use less graphic.
Pictures, images, ListView and many other controls
drain resources considerably. Use them sparingly.
Textboxes are second in draining resources.
Small programs and always running programs, should use 1% to 3%.
Average program in VB should use between 4% and 5% resources.
Advanced large programs, 6% to 8%.
If your advanced large program uses more than 8% then there is something wrong.
Compare your program to Microsoft Word or Internet Explorer.
See if multiple instances do a major drain on resources.
Run all tasks in your program and see if resource usage has increased.
Check resources before opening your program, then check
resources after you closed your program. Be sure that your
program resources usage has been restored and didn't
do a permanent resources drainage that would require a
reboot to restore.
Use the
Set Form1 = Nothing
in the unload event if it does.
Installing Fonts
Robert Terblanche says you can install a font by simply copying it into the Fonts directory.
He also found some code somewhere on the net that installs a font in a more "official" way (If you recognize it, tell me where it came from originally so I can give credit to the author). To download it exactly as he got it from the net, click here.
Assign Desktop Hotkeys in Windows NT
This is not really a Visual Basic tip, but I have been asked several times so here's the answer.
Use this technique to start your favorite programs when you press some hotkey combination. For example, when you type Ctl-Alt-W, you can start Word.
- Right click on the Start menu. Select the Explore command to explore the Start menu directories.
- If the program is not already in your Start menu or one of its submenus, add it there. You might want to create a new Hotkeys folder so you know where all your hotkeys are defined.
- Locate the program in the explore window. Right click on it and select Properties.
- Click on the Shortcut tab. Click on the Shortcut Key field and press the letter you want associated with the program. For example, if you press N, the shortcut key combination will be Ctl-Alt-N.
- Click the OK button. You can also close the Explorer window started in step 1 if you like.
Creating a DLL
To create an ActiveX DLL, start a new project. Select the ActiveX DLL option from the new project dialog.
The new project comes with a class that will become the DLL's server object. Give it a reasonable name. Also give it public methods that will be available to the client application.
That's all you really need to do, but there is more that can make your ActiveX DLL easier to use. In the Project menu, select the Project1 Properties command at the bottom. In the General tab, give the project a meaningful name and description. On the Make tab, you can also enter the company name, copyright information, etc.
Click Ok and you are ready to build the DLL. In the File menu, select the Make Project_Name.dll command. That's all there is to it.
To use the DLL, create a new Standard EXE project. Select the Project menu's References command. In the dialog, find the new DLL. It will be listed using the description for the project that you entered in the project properties General tab.
Now the program can declare variables of the server class type. If your server class is named MyClass, then the program can say:
Dim obj As MyClass
Set obj = New MyClass
obj.PublicProcedure
Install Programs on Other Computers
Visual Basic is not a compiled language. Even if you create a "compiled" executable using VB5 or VB6, the result is not executable by itself. It needs several DLLs at run time to execute. If you copy the program to another computer and run it, you will probably get some sort of "Missing DLL" error.
The easiest way to ensure that the DLLs are present is to use a setup kit. Run the Setup Kit Wizard (VB5 and earlier) or the Packaging and Deployment Wizard (VB6). It will build a setup kit for the program.
When the Wizard gives you a chance to add and remove files, do not remove any files. While you may not use OLE yourself, the program needs an OLE DLL to run. The Wizard usually knows what is necessary.
Then execute the setup kit on the other computer. It will install the program and the necessary DLLs so you can run it on the other computer.
Shutdown Windows
I think this technique works in Win 3.x, Windows 95, and Windows NT. Let me know if you find that it does not work or if you try it in Windows 98.
Option Explicit
#If Win32 Then
Private Declare Function ShutdownWindows _
Lib "user32" Alias _
"ExitWindowsEx" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
#Else
Private Declare Function ShutdownWindows _
Lib "user" Alias _
"ExitWindows" (ByVal wReturnCode As Integer, _
ByVal dwReserved As Integer) As Integer
#End If
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Sub Command1_Click()
ShutdownWindows EWX_FORCE, 0
End Sub
Change Tooltips Background Color
To change the ToolTips background color, open the Control Panel's Display tool. Click on the Appearance tab. In the Item combo box, select ToolTip. Click on the little color box to change the color.
Send your Tips and Tricks to feedback@vb-helper.com.
|