Results 1 to 8 of 8

Thread: Stop application running on Windows start up?

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Stop application running on Windows start up?

    Hi guys,

    I am wondering if anybody know's how i can make it so a user can press a commnd button and stop my application running on windows startup.

    This is the code i used to make it run on start up :

    Code:
    Option Explicit
    
    Private Sub cmdTest_Click()
    Dim mRtn As Boolean
    
        'Just call it
        mRtn = AddToStartUp(App.EXEName, App.Path & "\" & App.EXEName, True)
        
        If mRtn Then
            MsgBox "Well Done!!", vbInformation
        Else
            MsgBox "Error occured", vbCritical
        End If
        
    End Sub
    Is there a way to make another command cancel that code and stop it from running on start up??

    Thanks!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Stop application running on Windows start up?

    My guess is that your AddToStartUp is modifying the registry, a batch file or ini file. In that case, whatever that function is adding, create a similar function that removes what was added.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Stop application running on Windows start up?

    That's my question lol! How do i do that? The code above i found online!

    Thanks

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Stop application running on Windows start up?

    How could we possibly know?

    The code you showed calls a routine to do the work - and as you haven't shown us the routine, there is no way for us to tell what it does.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Stop application running on Windows start up?

    Oh I see! This is what is in the module file!

    Sorry & thanks

    Code:
    
    Option Explicit
    
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    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 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 HKEY_PERFORMANCE_DATA = &H80000004
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const HKEY_USERS = &H80000003
    Private Const ERROR_SUCCESS = 0&
    Private Const REG_DWORD = 4
    Private Const REG_SZ = 1
    
    '----------------------------------------------------------------------------------------
    ' Syntax    : AddToStartUp App.EXEName, App.Path & "\" & App.EXEName, True
    '----------------------------------------------------------------------------------------
    '  mItemKey : Just a key to register
    '  mPath    : The path of the file that to be executed
    '  mState   : Sets the value.. True = [Enabled, loads on startup}
    '----------------------------------------------------------------------------------------
    
    Public Function AddToStartUp(mItemKey As String, mPath As String, ByVal mState As Boolean) As Boolean
    Dim keyhand As Long
    Dim Rtn As Long
    Const StrPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
    
        On Error GoTo Handle
        Rtn = RegCreateKey(HKEY_LOCAL_MACHINE, StrPath, keyhand)
        If mState Then
            Rtn = RegSetValueEx(keyhand, mItemKey, 0, REG_SZ, ByVal mPath, Len(mPath))
        Else
            Rtn = RegDeleteValue(keyhand, mItemKey)
        End If
        Rtn = RegCloseKey(keyhand)
        
        AddToStartUp = True
        
    Exit Function
    Handle:
        AddToStartUp = False
    End Function

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Stop application running on Windows start up?

    Have you tried to simply run the same call, but passing False as the last parameter vs. True?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: Stop application running on Windows start up?

    why not just go to start -> run -> msconfig?

  8. #8
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Stop application running on Windows start up?

    Well use the source code that was found in the module file, it has the remove from startup key entry in it. I suggest use it. But next time, don't run or copy any code that you don't know what it does, or what it will do to your system.
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

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