|
-
Jan 17th, 2001, 11:37 AM
#1
Thread Starter
New Member
I need to run my app when system starts.
Thanks in advance.
-
Jan 17th, 2001, 12:24 PM
#2
PowerPoster
Create a shortcut in the Startup group of the start menu
-
Jan 17th, 2001, 12:41 PM
#3
PowerPoster
amitabh, that not a good solution, try to add an entry into the following registry path
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
-
Jan 17th, 2001, 12:48 PM
#4
PowerPoster
Juz paste this code into your project file will do.
Code:
'Put this code under a Basic Module
Option Explicit
'WIN32API Costant
Public Const REG_SZ = 1
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const ERROR_SUCCESS = 0&
'WIN32 API declaration
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
Public 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private hCurKey As Long
Public Function SaveSetting(ByVal hkey As Long, ByVal lpSubKey As String, ByVal lpString As String, ByVal dwType As Long, ByVal lpData As String) As Long
On Error GoTo ErrHandle
'Data validation
If hkey = 0 Or lpSubKey = "" Or lpString = "" Then GoTo ErrHandle
'Open the given hkey + subkey
If RegOpenKey(hkey, lpSubKey, hCurKey) = ERROR_SUCCESS Then
'Create the given string + value
If RegSetValueEx(hCurKey, lpString, 0, dwType, ByVal lpData, Len(lpData)) = ERROR_SUCCESS Then
SaveSetting = 1
Else
SaveSetting = 0
End If
Else
SaveSetting = 0
End If
RegCloseKey hCurKey
Exit Function
ErrHandle:
SaveSetting = 0
End Function
Code:
'Call the function
'Add data into the registry
If SaveSetting(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "MyAPP", REG_SZ, "C:\1.exe") = 1 Then
MsgBox "Data saved"
Else
MsgBox "Fail to save"
End If
Cheers!
-
Jan 17th, 2001, 10:44 PM
#5
PowerPoster
Thanks Chris, I knew that you could use the registry, but didn't knew the key used for he purpose.
-
Jan 18th, 2001, 02:40 AM
#6
PowerPoster
amitahb, which key that you don't know there usage? Perhaps I can explain to you?
-
Jan 18th, 2001, 03:22 PM
#7
There different keys you can use are Run, RunOnce and RunService.
-
Jan 19th, 2001, 11:48 AM
#8
PowerPoster
Actually I am confused in usage of all three that Megatron has written. I know that all three are used for more or less the same purpose, but what's their exact operation. Especially, how do Run and RunOnce differ
-
Jan 19th, 2001, 03:41 PM
#9
Run:-Runs everytime Windows starts
RunOnce:--Runs only once
RunService:-Runs much before normal Apps start (usually Anti-Virus programs start here)
-
Jan 20th, 2001, 12:13 AM
#10
PowerPoster
Do all three remain same on NT, provided you have the requisite permissions? And do the entries in RunOnce gets deleted after being executed once
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|