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
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



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

Reply Post New Thread
 
Thread Tools Display Modes
Old Nov 28th, 2009, 01:51 PM   #1
JamieWarren09
Hyperactive Member
 
Join Date: May 09
Posts: 324
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, 02:03 PM   #2
LaVolpe
VBaholic & Loving It
 
LaVolpe's Avatar
 
Join Date: Oct 07
Location: GetWindowRect()
Posts: 7,895
LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)
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. Read the HitchHiker's Guide to Getting Help on the Forums.

{Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor} {VBA Control Arrays}
{XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}
LaVolpe is offline   Reply With Quote
Old Nov 28th, 2009, 02:04 PM   #3
JamieWarren09
Hyperactive Member
 
Join Date: May 09
Posts: 324
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, 02:23 PM   #4
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 30,091
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, 02:34 PM   #5
JamieWarren09
Hyperactive Member
 
Join Date: May 09
Posts: 324
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, 02:48 PM   #6
LaVolpe
VBaholic & Loving It
 
LaVolpe's Avatar
 
Join Date: Oct 07
Location: GetWindowRect()
Posts: 7,895
LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)LaVolpe is a name known to all (1000+)
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. Read the HitchHiker's Guide to Getting Help on the Forums.

{Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor} {VBA Control Arrays}
{XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}
LaVolpe is offline   Reply With Quote
Old Nov 28th, 2009, 04:00 PM   #7
Justa Lol
Fanatic Member
 
Join Date: Jun 08
Location: Faroe islands
Posts: 684
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, 08:24 PM   #8
ThEiMp
Frenzied Member
 
Join Date: Dec 07
Location: Take The PCI Bus Across To The CPU!!
Posts: 1,808
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.
__________________
Public Sub Form_Load()
Form1.Label1.Caption = "Advanced Notice := If I do good, then please rate my post. Thanks, in advance!!"
End Sub

ActiveX OCX Controls:
| Vert & Hort ScrollBar Control | New Kind of Frame Control |

Beta Testers Wanted For Unpaid Work:
Please PM me, with your email address and your screen name on this Forum, using the Forum send Email private message. Thanks for the help!!

Visual Basic Games & Programs:
| Visual Director v1.00 | Scorched Earth v1.00|
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
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 05:10 AM.





Acceptable Use Policy

Internet.com
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.