To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Nov 28th, 2009, 02:51 PM   #1
JamieWarren09
Addicted Member
 
Join Date: May 09
Posts: 226
JamieWarren09 is an unknown quantity at this point (<10)
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!
JamieWarren09 is offline   Reply With Quote
Old Nov 28th, 2009, 03:03 PM   #2
LaVolpe
VBaholic & Loving It
 
LaVolpe's Avatar
 
Join Date: Oct 07
Location: GetWindowRect()
Posts: 6,223
LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)
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"
Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.

{Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
HitchHiker's Guide to Getting Help on the Forums
LaVolpe is offline   Reply With Quote
Old Nov 28th, 2009, 03:04 PM   #3
JamieWarren09
Addicted Member
 
Join Date: May 09
Posts: 226
JamieWarren09 is an unknown quantity at this point (<10)
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
JamieWarren09 is offline   Reply With Quote
Old Nov 28th, 2009, 03:23 PM   #4
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 27,109
si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)
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.
si_the_geek is offline   Reply With Quote
Old Nov 28th, 2009, 03:34 PM   #5
JamieWarren09
Addicted Member
 
Join Date: May 09
Posts: 226
JamieWarren09 is an unknown quantity at this point (<10)
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
JamieWarren09 is offline   Reply With Quote
Old Nov 28th, 2009, 03:48 PM   #6
LaVolpe
VBaholic & Loving It
 
LaVolpe's Avatar
 
Join Date: Oct 07
Location: GetWindowRect()
Posts: 6,223
LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)LaVolpe is a splendid one to behold (700+)
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"
Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.

{Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
HitchHiker's Guide to Getting Help on the Forums
LaVolpe is offline   Reply With Quote
Old Nov 28th, 2009, 05:00 PM   #7
Justa Lol
Fanatic Member
 
Join Date: Jun 08
Location: Faroe islands
Posts: 638
Justa Lol is on a distinguished road (20+)
Re: Stop application running on Windows start up?

why not just go to start -> run -> msconfig?
Justa Lol is offline   Reply With Quote
Old Nov 28th, 2009, 09:24 PM   #8
ThEiMp
Frenzied Member
 
Join Date: Dec 07
Location: Take The PCI Bus Across To The CPU!!
Posts: 1,364
ThEiMp is on a distinguished road (10+)
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.
__________________
How to change a light bulb?
Ahh yes, I know that?

Light_Bulb1 = Light_Bulb1 + Ladder

PS: If I do good, then please rate my post. Thanks, in advance!!
ThEiMp is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:41 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.