Results 1 to 9 of 9

Thread: Putting a program into the Startup?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    54

    Putting a program into the Startup?

    How can I put my application into the startup routine so it will load when windows loads up? Also how can you make it be the first one to load? I know in file name if you want to have your file be the first one put an underscore in front of it like this _example.exe.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    54
    How can you also do this at runtime and remove it as well? Sort of like an option if you want it to be in the start up or not.

  3. #3
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    use the registry ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")...

    copy/paste this to a .bas module (with this code you can make or delete keys in the registry)...




    Option Explicit

    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 Const ERROR_SUCCESS = 0&
    '****************************************************
    'Indented because it belongs to the last constant of this batch - it must come before the last one
    Private Const SYNCHRONIZE = &H100000
    Private Const KEY_CREATE_SUB_KEY = &H4
    Private Const KEY_SET_VALUE = &H2
    Private Const READ_CONTROL = &H20000
    Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))

    'Indented because it belongs to the last constant of this batch - it must come before the last one
    'Private Const SYNCHRONIZE = &H100000
    Private Const KEY_CREATE_LINK = &H20
    Private Const KEY_NOTIFY = &H10
    Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    'Private Const KEY_CREATE_SUB_KEY = &H4
    'Private Const KEY_SET_VALUE = &H2
    Private Const KEY_QUERY_VALUE = &H1
    Private Const STANDARD_RIGHTS_ALL = &H1F0000
    Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
    '****************************************************
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Const HKEY_CURRENT_CONFIG = &H80000005
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const HKEY_DYN_DATA = &H80000006
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const HKEY_PERFORMANCE_DATA = &H80000004
    Private Const HKEY_USERS = &H80000003
    '****************************************************
    Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
    Private Const REG_OPTION_NON_VOLATILE = 0
    Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
    End Type

    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Private Const REG_SZ = 1

    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long

    Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    '****************************************************


    Dim str_KeyFolder As String
    Dim str_Value_ProgramName As String
    Dim str_Data_ProgramPath As String
    Dim lng_Handle_To_KeyFolder As Long ' handle to the open or new registry key
    Dim lng_Return As Long

    Sub Main()
    'CONCEPTS: KEY - Folders in Window Explorers
    ' VALUE - Files
    ' DATA - Path

    'PITFALL: Make sure there is no "\" at the end

    str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Testing"
    'str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" 'NOTICE: Uncomment this line will make program start everytime log on
    str_Value_ProgramName = "Project1"
    str_Data_ProgramPath = "C:\Test.exe"


    'Open RegEdit.Exe while step through this code - Refresh(F5) Regedit Screen after each procedure

    'OVERALL: Create a Key - Folder Column in RegEdit.Exe
    Call p_Create_Key

    'OVERALL: Create a Value for a registry Key - Name Column in RegEdit.Exe
    Call p_Create_Value(str_Value_ProgramName, str_Data_ProgramPath)

    'OVERALL: Read Data or File Path from a Value - Data Column in RegEdit.Exe
    Call p_Read_Data_From_Value(str_Value_ProgramName)

    'OVERALL: Delete a Value from a registry Key
    Call p_Delete_Value(str_Value_ProgramName)

    'OVERALL: Delete a Key and all of its Value
    Call p_Delete_Key
    End Sub

    Public Sub p_Create_Key()
    'PURPOSE: Set the name of the new key and the default security settings
    Dim sec_Attri As SECURITY_ATTRIBUTES ' security settings of the key
    sec_Attri.nLength = Len(sec_Attri) ' size of the structure
    sec_Attri.lpSecurityDescriptor = 0 ' default security level
    sec_Attri.bInheritHandle = True ' the default value for this setting

    Dim lng_New_Or_Exist As Long ' "1" if new key - "2" if existing key was opened

    'PURPOSE: Create or open the registry key and assign the handle to lng_Handle_To_KeyFolder
    lng_Return = RegCreateKeyEx(HKEY_LOCAL_MACHINE, str_KeyFolder, 0, vbNullString, _
    REG_OPTION_NON_VOLATILE, KEY_WRITE, sec_Attri, _
    lng_Handle_To_KeyFolder, lng_New_Or_Exist)

    If lng_Return <> ERROR_SUCCESS Then
    MsgBox "Error in p_Create_Key procedure!"
    End
    End If

    'PURPOSE: Close the registry key if it was successfully opened
    Call RegCloseKey(lng_Handle_To_KeyFolder)
    End Sub

    Public Sub p_Create_Value(str_Value_ProgramName As String, str_Data_ProgramPath As String)
    'PURPOSE: Open the registry key (str_KeyFolder) and _
    assign the handle to lng_Handle_To_KeyFolder
    lng_Return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, str_KeyFolder, 0, _
    KEY_ALL_ACCESS, lng_Handle_To_KeyFolder)

    If lng_Return = ERROR_SUCCESS Then
    'PURPOSE: Add the desired value to the key.
    Call RegSetValueEx(lng_Handle_To_KeyFolder, str_Value_ProgramName, _
    0, REG_SZ, ByVal str_Data_ProgramPath, Len(str_Data_ProgramPath))

    'PURPOSE: Close the registry key if it was successfully opened
    Call RegCloseKey(lng_Handle_To_KeyFolder)
    End If
    End Sub

    Public Sub p_Read_Data_From_Value(str_Value_ProgramName As String)
    'PURPOSE: Open the registry key (str_KeyFolder) and _
    assign the handle to lng_Handle_To_KeyFolder
    lng_Return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, str_KeyFolder, 0, _
    KEY_ALL_ACCESS, lng_Handle_To_KeyFolder)

    If lng_Return = ERROR_SUCCESS Then
    'PURPOSE: Read data
    Dim str_Data As String
    str_Data = Space(50)
    Call RegQueryValueEx(lng_Handle_To_KeyFolder, str_Value_ProgramName, _
    0, REG_SZ, ByVal str_Data, Len(str_Data))

    str_Data = Left(str_Data, InStr(1, str_Data, Chr(0)) - 1)
    MsgBox str_Data

    'PURPOSE: Close the registry key if it was successfully opened
    Call RegCloseKey(lng_Handle_To_KeyFolder)
    End If
    End Sub

    Public Sub p_Delete_Value(str_Value_ProgramName As String)
    'PURPOSE: Open the registry key (str_KeyFolder) and _
    assign the handle to lng_Handle_To_KeyFolder
    lng_Return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, str_KeyFolder, 0, _
    KEY_ALL_ACCESS, lng_Handle_To_KeyFolder)

    If lng_Return = ERROR_SUCCESS Then
    'PURPOSE: Delete the desired value from the key.
    Call RegDeleteValue(lng_Handle_To_KeyFolder, str_Value_ProgramName)

    'PURPOSE: Close the registry key if it was successfully opened
    Call RegCloseKey(lng_Handle_To_KeyFolder)
    End If
    End Sub

    Public Sub p_Delete_Key()
    lng_Return = RegDeleteKey(HKEY_LOCAL_MACHINE, str_KeyFolder)

    If lng_Return <> ERROR_SUCCESS Then
    MsgBox "Error in p_Delete_Key procedure!"
    End If
    End Sub
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  4. #4

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    54
    The code seems reel long and I am not sure if I follow it. Is there some simpler way?

  5. #5
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    yes, i agree, its very long, but u only have to edit the following sub:






    Sub Main()
    'CONCEPTS: KEY - Folders in Window Explorers
    ' VALUE - Files
    ' DATA - Path

    'PITFALL: Make sure there is no "\" at the end

    str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Testing"
    'str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" 'NOTICE: Uncomment this line will make program start everytime log on
    str_Value_ProgramName = "Project1"
    str_Data_ProgramPath = "C:\Test.exe"


    'Open RegEdit.Exe while step through this code - Refresh(F5) Regedit Screen after each procedure

    'OVERALL: Create a Key - Folder Column in RegEdit.Exe
    Call p_Create_Key

    'OVERALL: Create a Value for a registry Key - Name Column in RegEdit.Exe
    Call p_Create_Value(str_Value_ProgramName, str_Data_ProgramPath)

    'OVERALL: Read Data or File Path from a Value - Data Column in RegEdit.Exe
    Call p_Read_Data_From_Value(str_Value_ProgramName)

    'OVERALL: Delete a Value from a registry Key
    Call p_Delete_Value(str_Value_ProgramName)

    'OVERALL: Delete a Key and all of its Value
    Call p_Delete_Key
    End Sub






    this piece of code create a key, create a value, read the value, delete the value, delete the key


    to test this code run it with F8 and open the regedit.exe
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  6. #6
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    yes, i agree, its very long, but u only have to edit the following sub (dont look at the rest)






    Sub Main()
    'CONCEPTS: KEY - Folders in Window Explorers
    ' VALUE - Files
    ' DATA - Path

    'PITFALL: Make sure there is no "\" at the end

    str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Testing"
    'str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" 'NOTICE: Uncomment this line will make program start everytime log on
    str_Value_ProgramName = "Project1"
    str_Data_ProgramPath = "C:\Test.exe"


    'Open RegEdit.Exe while step through this code - Refresh(F5) Regedit Screen after each procedure

    'OVERALL: Create a Key - Folder Column in RegEdit.Exe
    Call p_Create_Key

    'OVERALL: Create a Value for a registry Key - Name Column in RegEdit.Exe
    Call p_Create_Value(str_Value_ProgramName, str_Data_ProgramPath)

    'OVERALL: Read Data or File Path from a Value - Data Column in RegEdit.Exe
    Call p_Read_Data_From_Value(str_Value_ProgramName)

    'OVERALL: Delete a Value from a registry Key
    Call p_Delete_Value(str_Value_ProgramName)

    'OVERALL: Delete a Key and all of its Value
    Call p_Delete_Key
    End Sub






    this piece of code create a key, create a value, read the value, delete the value, delete the key


    to test this code run it with F8 and open the regedit.exe
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  7. #7
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Why not make a shortcut in
    C:\windows\start menu\programs\start up\
    ?
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  8. #8

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    54
    When I open the Regedit.exe file what am I suppossed to be looking for? What do you mean by ( str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Testing" )
    What does this do?

    So if I wanted to beable to change it to startup or not startup in runtime How would I do that in a menu command?

  9. #9
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    this folder is just for testing, the real one is:

    str_KeyFolder = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" 'NOTICE: Uncomment this line will make program start everytime log on

    in this folder stays all the apps that run when windows start



    when u hit the command key u got to read the value, and if does not exists then u got to create a key, and create a value.

    sorry but i goto go and i dont have time to do what u ask me, but i recommend for you to analyse the sub Main first...
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width