I want my program to auto start on machine reboot (WIN95/98 VB6).
I know I can manually add the .exe name to windows/all users/startmenu/programs/startup folder, but I want the program to install /check installed itself somehow. Maybe an API call?
Printable View
I want my program to auto start on machine reboot (WIN95/98 VB6).
I know I can manually add the .exe name to windows/all users/startmenu/programs/startup folder, but I want the program to install /check installed itself somehow. Maybe an API call?
you can either add a registry entry, or add a shortcut to the start up folder.
you have to use API for either option.
ok, what API's do I need to
check if shortcut exists, add one if not existing?
(is s/cut's safer than delving into registry?)
for registry...you create an entry in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
this is fopr running the app when user logs in...
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
this is for running when the computer starts up
using the registry is better as the user won't be able to edit it as easily....
Yeah, but your users will hate you for putting it where it's hard to find. I know I would.
I belive it's this one
Then you would call it in the form_load of you appl.Code:Public Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
'or
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Const REG_CREATED_NEW_KEY = &H1
Hope that helped,
D!m
OK thanks, Now what happen to registry entry each time program starts? is the API call smart enought not to add a new entry each time?
Also I agree that hiding it in the registry is hell for the end user/system maintenance...
How can I put into startup folder with code ? (& check if exists if necessary)?
I don't remember where the startup folder in Win95/98 (i think it is \windows\startup\ without profile and \windows\profile\Start Menu\Programs\Startup with using profile)
For WinNT, put your shortcut in the All Users startup folder(\WinNT\profiles\All Users\Start Menu\Programs\Startup)
Becuase the shortcut is a file, you can easily check if it exist.
thanks, but HOW do I write code to make the shortcut appear in the startup subdir?? (& check if already exists?)
use this to create a link in the startup folder of the current user
Private Declare Function fCreateShellLink Lib "VB5STKIT.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Private Sub Form_Load()
'Create a shell link on your desktop
lngresult = fCreateShellLink("Startup", "LINK", "C:\myfile.exe", "")
End Sub
thanks all
I will try s/cut code out..
"fCreateShellLink" works well. But it can't add a shortcut to a general folder,such as "d:\". :( Anyone has better way?
If you look on MSDN site for FileSystemObject object, it has a copyfile method/property which you could use for this
It is not very professional I know, but when doing installs, I make some of my small programs install to one directory (user does not have a choice where it goes). For this instance, as I know where the program is, I create a shortcut to that location on my PC, then use this copyfile option to copy this shortcut to the C:☻windows☻startup folder, or as you mentioned D drive.
Alex Read
VB6 learning Edition