Ive been searching on here and on the net for a easy way to add my program to the startup list in msconfig, and to remove it, both from the program itself.
I finally came up with this:
I have one check box on the form.
I then call one of two subs on exit, based on check value:
I call the subs in form_QueryUnload
This works just fine if I leave quote marks off the app.path and app.exename (chr(34)), but if the app.path has any spaces in it, it wont load on startup, even though it is in the msconfig list.
I fixed this by including the quotes (CHR(34))
But, now when my app starts, it removes the app from the msconfig list, regardless of the checkbox being checked.
I think it is a problem with how I am checking to see if the app is in the list (in form_load).
Is there an easier way to check to see if the app is in the list? Im using this method to set the checkbox or not or app start.
I finally came up with this:
I have one check box on the form.
Code:
Private sub Form_Load()
'This checks to see if the startup exists, and marks the_check box accordingly
On Error GoTo errman
Check1.value = 1
CreateObject("wscript.shell").RegDelete ("HKCU\Software\Microsoft\Windows\CurrentVersion\Run\" & "appname")
CreateObject("wscript.shell").RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\" & "appname", CreateObject("scripting.filesystemobject").BuildPath(Chr(34) & app.path), "app.exename" & (Chr(34))
Exit Sub
errman:
Check1.value = 0
end sub
I then call one of two subs on exit, based on check value:
Code:
Private Sub makestartup()
'Place startup shortcut in msconfig
CreateObject("wscript.shell").RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\" & "app.exename", CreateObject("scripting.filesystemobject").BuildPath(Chr(34) & app.path, "app.exename" & Chr(34))
Check1.value = 1
End Sub
Private Sub removestartup()
'Remove startup shortcut in msconfig
On Error GoTo errman
CreateObject("wscript.shell").RegDelete ("HKCU\Software\Microsoft\Windows\CurrentVersion\Run\" & "appname")
Check1.value = 0
Exit Sub
errman:
Check1.value = 0
End Sub
I call the subs in form_QueryUnload
Code:
If Check1.value = 1 Then makestartup
If Check1.value = 0 Then removestartup
This works just fine if I leave quote marks off the app.path and app.exename (chr(34)), but if the app.path has any spaces in it, it wont load on startup, even though it is in the msconfig list.
I fixed this by including the quotes (CHR(34))
But, now when my app starts, it removes the app from the msconfig list, regardless of the checkbox being checked.
I think it is a problem with how I am checking to see if the app is in the list (in form_load).
Is there an easier way to check to see if the app is in the list? Im using this method to set the checkbox or not or app start.