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!
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.
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
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.
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
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?
Re: Stop application running on Windows start up?
why not just go to start -> run -> msconfig?
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.