Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting startup programs information 1

Status
Not open for further replies.

JohnVogel

Programmer
Apr 19, 1999
117
US
Hi, I am trying to write a program, where there are two listboxes. I would like the first listbox to be populated with the shortcuts of the startup folder, and the second to be populated with programs and services that are set to run at startup in the registry key. What I would like to know is if there is possibly some API function that would allow me to grab this information, or if someone might have a program snippet that does something along these lines. To be quite honest, I hardly even know where to start in the registry startup portion. The other part should be fairly easy, though.
 
Here is some code that will list all of the startup programs in the registry (you need to create a listbox and a commandbutton
name them Command1 and List1
then past the code below into your forms code section

I don't have the time to get the services or the startup folder entries - hope this helps you get started
you need to remember that on XP & 2000(and probly on the other NT systems) that there is more than one startup folder

Each user on an NT system have their own startup folder located here \/
C:\Documents and Settings\Usersname\Start Menu\Programs\Startup


Code:
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const KEY_QUERY_VALUE = &H1
Private Const REG_SZ = 1
Private Const REG_BINARY = 3
Private Const HKEY_CURRENT_USER = &H8000000

Private Sub Command1_Click()

Dim valuename As String, valuelen As Long, datatype As Long, data(0 To 254) As Byte
Dim datalen As Long, datastring As String, hkey As Long, index As Long, c As Long
Dim retval As Long

retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_QUERY_VALUE, hkey)

If retval <> 0 Then
List1.AddItem "Registry key could not be opened -- aborting."
Exit Sub
End If


index = 0
While retval = 0

valuename = Space(255)
valuelen = 255
datalen = 255

retval = RegEnumValue(hkey, index, valuename, valuelen, 0, datatype, data(0), datalen)
If retval = 0 Then

valuename = Left(valuename, valuelen)


Select Case datatype

Case REG_SZ
datastring = Space(datalen - 1)
CopyMemory ByVal datastring, data(0), datalen - 1
List1.AddItem valuename & "=" & datastring

Case Else
'Do Nothing Yet
End Select
End If
index = index + 1
Wend


retval = RegCloseKey(hkey)
End Sub

%, 2004
 
Wow, that's perfect, thanks %!

I was almost about ready to scrap this project (I don't have much time myself), but you just saved me a major portion of the programming. The individual user startup folders (and all users startup folders)are actually pretty easy to get to using the SHGetSpecialFolderPath API, The hard part was figuring out the registry startup programs, which you've provided... thanx a million!

John Vogel
john@thecompuwizard.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top