Starting application on Windows start 
Author Message
 Starting application on Windows start

hi,

i want to start my application on Windows start using registry
how can i do that in VB?

i want to add an option that my application will start on win start and saty
in satan by mode in system tray.

any ideas?

- sci



Wed, 02 Apr 2003 03:00:00 GMT  
 Starting application on Windows start

Hi, what about just using a registry Class, and call it post the following
entry:
HKLM/HKCU\Software\Microsoft\Windows\CurrentVersion\Run
YourProduct (String) = "YourFile"

If you don't have such a class or module, there are many out there, or just
create your own one with the help of MSDN.

I'll try to write one for you, but please don't expect it beforeend of
October.

Bye



Quote:
> hi,

> i want to start my application on Windows start using registry
> how can i do that in VB?

> i want to add an option that my application will start on win start and
saty
> in satan by mode in system tray.

> any ideas?

> - sci



Wed, 02 Apr 2003 03:00:00 GMT  
 Starting application on Windows start

Hi,
I wrote this for your purposes.
Althogh I cannot guarantee it won't harm your system (especially not if
you're running NT or 2000 Pro), it worked on my system (98 SE).
Because it's a critical point, you should create a Backup of your USER.dat
first (SYSTEM.dat if you're changing HKEY to HKLM).
I can't take ANY reliability... use at your own risk.
Put this as a new module DIRECTLY into the Project which should be
Auto-Executed.
Before using  any method, you should overlook the Flags at the beginning and
end of the DECLARATIONS Section.
You NEED to change ValueName (down before the Start of InitFile)

Then start calling InitFile ""

When you want to test this Code, change ReleaseMode to 1, and compile to
EXE.
Run the EXE afterwards.

Bye, Patrick

'<Copy Text from here>

'###############################################
'Module Autostart.
'Put it DIRECTLY into Executable to Launch.
'DO NOT PUT IT INTO ANOTHER FILE, FOR THIS FILE WOULD BE EXECUTED AT
STARTUP!
'While using the IDE you shouldn't use this module, for the "Executable" is
your Project (.vbp)!
'If you decide to test it in IDE, BE ABSOLUTELY SURE TO CALL
DeActivateAutoStart() before quiting the Program! On a crash, otherwise, I
can't guarantee you windows will start again (I can't at all...)!
#Const ReleaseMode = 0
'Change upper Line to ...=1 before compiling to Exe.
'Write all code you need, including call-Routines for this module, test in
IDE, and compile with
'releaseMode=1. It will work then.
'To use IsBeeingStartet as a Test in IDE, Change value below.
Private Const IDEDEBUG_IsBeeingStarted = 0    'Sets the ReturnValue for
IsBeeingStarted in IDE Mode.
                                              'Useful for Debugging both
States.
                                              '0: Not
started, -1:Starting, -2:Error
Private Const IDEDEBUG_ActivateStartup = -1   'Sets the ReturnValue for
ActivateStartup
                                              'in IDE Mode. Usefull for
testing Error-Handling (0==Error)
Private Const IDEDEBUG_DeActivateStartup = -1 'Sets the ReturnValue for
DeActivateStartup
                                              'in IDE Mode. Usefull for
testing Error-Handling (0==Error)
'Please Edit the Flags right at Front of the first Procedure before using
this.
'###############################################

'Start of Code

Private Declare Function RegCloseKey Lib "advapi32" (ByVal HKEY As Long) As
Long
Private Declare Function RegCreateKeyEx Lib "advapi32" 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, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByRef
phkResult As Long, ByRef lpdwDisposition As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA"
(ByVal HKEY As Long, ByVal lpSubKey As String, ByVal ulOptions As Long,
ByVal samDesired As Long, ByRef phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias
"RegQueryValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal
lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef
lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA"
(ByVal HKEY As Long, ByVal lpValueName As String, ByVal Reserved As Long,
ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias
"RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long

Const REG_SZ = 1
Const REG_DWORD = 4

Const READ_CONTROL = &H20000
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_READ = KEY_QUERY_VALUE + KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY +
READ_CONTROL
Const KEY_WRITE = KEY_SET_VALUE + KEY_CREATE_SUB_KEY + READ_CONTROL
Const KEY_EXECUTE = KEY_READ
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + KEY_CREATE_SUB_KEY
+ KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL
Const MAXIMUM_ALLOWED = &H2000000

Enum HKEYx
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum

Const ERROR_NONE = 0
Const ERROR_BADKEY = 2
Const ERROR_ACCESS_DENIED = 8
Const ERROR_SUCCESS = 0

Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Boolean
End Type

'#####################
Const HKEY = HKEY_CURRENT_USER      'use hKLM if you are going to create a
System-wide shortcut.
Const Pathname = "Software\Microsoft\Windows\CurrentVersion\Run" 'use
RunOnce for a Once-Execution and auto-deletion afterwarsd, use RunServices
and HKLM for an Execution BEFORE Logon.
Const ValueName = "<Your Product Name (AutoStart ID)>"
'Const FileName = "<Set Path to Executable here, or set it dynamicly to the
Correct Path.>"
Dim FileName$ 'I'd prefere the dynamic solution. Call InitFile First.

Sub InitFile(Arguments$)

#If ReleaseMode Then

FileName = App.Path & IIf(Right(App.Path, 1) = "\", "", "\") & App.EXEName &
".Exe"

If Arguments = "" Then Exit Sub

FileName = FileName & " " & Arguments

#Else

#End If

End Sub

Function ActivateStartup() As Boolean

#If ReleaseMode Then

Dim hkeytmp As Long
Dim ret As Long

ret = RegOpenKeyEx(HKEY, Pathname, 0, MAXIMUM_ALLOWED, hkeytmp)

If ret <> ERROR_SUCCESS Then ActivateStartup = False: RegCloseKey hkeytmp:
Exit Function

ret = RegSetValueEx(hkeytmp, ValueName, 0, REG_SZ, FileName,
LenB(StrConv(FileName, vbFromUnicode)))

If ret <> ERROR_SUCCESS Then ActivateStartup = False: RegCloseKey hkeytmp:
Exit Function

ret = RegCloseKey(hkeytmp)

#Else

ActivateStartup = IDEDEBUG_ActivateStartup

#End If

End Function
Function DeActivateStartup() As Boolean

#If ReleaseMode Then

Dim hkeytmp As Long
Dim ret As Long

ret = RegOpenKeyEx(HKEY, Pathname, 0, MAXIMUM_ALLOWED, hkeytmp)

If ret <> ERROR_SUCCESS Then DeActivateStartup = False: RegCloseKey hkeytmp:
Exit Function

ret = RegDeleteValue(hkeytmp, ValueName)

If ret <> ERROR_SUCCESS Then DeActivateStartup = False: RegCloseKey hkeytmp:
Exit Function

ret = RegCloseKey(hkeytmp)

#Else

DeActivateStartup = IDEDEBUG_DeActivateStartup

#End If

End Function

Function IsBeeingStarted() As Long

#If ReleaseMode Then

Dim hkeytmp As Long
Dim ret As Long

ret = RegOpenKeyEx(HKEY, Pathname, 0, MAXIMUM_ALLOWED, hkeytmp)

If ret <> ERROR_SUCCESS Then IsBeeingStarted = -2: RegCloseKey hkeytmp: Exit
Function

Data = String$(255, 0)
dataln = 255

ret = RegQueryValueEx(hkeytmp, ValueName, 0, typen, Data, dataln)

If ret <> ERROR_SUCCESS Then IsBeeingStarted = -1: RegCloseKey hkeytmp: Exit
Function

On Error Resume Next

Data = Left$(Data, InStr(Data, Chr(0)) - 1)

If Data <> "" Then IsBeeingStarted = -1 Else IsBeeingStarted = 0

#Else

IsBeeingStarted = IDEDEBUG_IsBeeingStarted

#End If

End Function



Thu, 03 Apr 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Starting application on Windows start

2. Start program automatically when Windows starts

3. start my exe when windows starts

4. Making program start when windows starts...

5. How Can I Make My program start when Windows starts and Undo It

6. Start my program when windows starts

7. Make a program start when Windows start

8. Start application when another starts

9. Determining the height of the start bar / fitting applications around start bar

10. Problems Starting Windows Service From Web Application...

11. Start Debug throws security error for Windows Application.

12. Sizing application around Windows Task/Start Bar

 

 
Powered by phpBB® Forum Software