Visual Basic Code of the Week (COTW)
http://www.codeoftheweek.com
Issue #85
Online Version at http://www.codeoftheweek.com/membersonly/bi/0085.html (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp. Word, Excel and Visual Basic are trademarks of Microsoft Corp.

Product Information

Check out http://www.codeoftheweek.com/powerfindpro for a great time-saving add-in for Visual Basic.

In this Issue

This issue was designed for VB 4.0 32-bit and up. Questions? Email us at questions@codeoftheweek.com.

The complete source code appears near the end of this issue. Be sure not to miss it!

This issue is an enhancement to issue number 64. This issue enhances the cRegistryUtils class by adding the ability to get and retrieve information about the items that Windows will startup upon login.

cRegistryUtils

The property added to cRegistryUtils is called Run. All the rest of the functions included in the cRegistryUtils class are documented in Issue #24 - http://www.codeoftheweek.com/issues/0024.html or #64 - http://www.codeoftheweek.com/issues/0064.html

Windows stores some information in the registry that it uses to determine which applications to start upon login to Windows. This behaves much like putting an application in the Startup folder. This biggest difference is that it is harder for the end user to remove an item from the registry than the Startup folder.

This class works by adding an additional key to the HKLM\Software\Microsoft\Windows\CurrentVersion\Run folder in the registry. There is another key in the registry called RunOnce that behaves just like the Run except that the application will only be started on the next invocation of Windows or re-login to Windows. Once the application starts the key will be removed from the RunOnce folder and never started again. This is useful for installation programs and other situations where you need to update something in Windows only once. You can add a RunOnce property to this class to implement this feature if you need it.

Property

There is one new property called Run.

Public Property Get Run(sAppName As String) As String
Public Property Let Run(sAppName As String, sCommandLine As String)

Parameters

Returns

Returns an error if the retrieval or assignment of the application was not succesful. Otherwise the Run property will return the command line of the key specified by sAppName.

Sample Usage

Below is an example of how this function works.

    Dim Reg As New cRegistryUtils

    Debug.Print Reg.Run("DU Meter")
    ' on my system this prints out: C:\PROGRAM FILES\DU METER\DUMETER.EXE

    Reg.Run("TestKey") = "c:\windows\notepad.exe"
    Debug.Print Reg.Run("TestKey")
    ' this will print out c:\windows\notepad.exe

Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0085.html


This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945
Email: info@codeoftheweek.com
Web: http://www.codeoftheweek.com