|
|
#1 |
|
Hyperactive Member
Join Date: May 09
Posts: 324
![]() |
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
Thanks! |
|
|
|
|
|
#2 |
|
VBaholic & Loving It
Join Date: Oct 07
Location: GetWindowRect()
Posts: 7,895
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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} |
|
|
|
|
|
#3 |
|
Hyperactive Member
Join Date: May 09
Posts: 324
![]() |
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 |
|
Super Moderator
Join Date: Jul 02
Location: Bristol, UK
Posts: 30,091
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________
Classic VB FAQs (updated Apr 15th) ...Database Development FAQs/Tutorials (updated Mar 29th) (includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial). Tutorial: How to automate Excel from VB6 (or VB5/VBA) .•. SQL 'Select' statement formatter/checker .•. Convert colour number to colour name .•. FlexGrid: fill from recordset .•. FlexGrid: AutoSize columns .•. DB Reserved Words checker Connection strings .•. MDAC/Jet/ACE downloads .•. SQL Server downloads .•. MZTools (free upgrade for the VB6/VBA Editor) |
|
|
|
|
|
#5 |
|
Hyperactive Member
Join Date: May 09
Posts: 324
![]() |
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 |
|
VBaholic & Loving It
Join Date: Oct 07
Location: GetWindowRect()
Posts: 7,895
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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} |
|
|
|
|
|
#7 |
|
Fanatic Member
Join Date: Jun 08
Location: Faroe islands
Posts: 684
![]() |
Re: Stop application running on Windows start up?
why not just go to start -> run -> msconfig?
|
|
|
|
|
|
#8 |
|
Frenzied Member
Join Date: Dec 07
Location: Take The PCI Bus Across To The CPU!!
Posts: 1,808
![]() |
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| |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|