Link to home
Start Free TrialLog in
Avatar of waleed_makarem
waleed_makarem

asked on

how to start software automatically when windows starts ?

hi experts;
i am designing a scheduling software. it must log on automatically every time windows 95,98 is initiated, then it will see it the a certain period has passed or not, it it not passed ,the software will close automatically. but if this period is passed "ie, is over" , the software will do certain actions.
Also, when the user opens the software manually form the programs in windows, it will open even if the period did not pass yet.
This idea is the sam as a software for changing the image that is displayed when windows is openning or shutting down, everytime windows starts, it it starts to change the picture that will be displayed the next time and then closed automatically.
also when the user open it from the program files, it opens.
also how to make windows starts a software automatically whenever it starts "i do not like to put the software in StartUP folder".
Thank u for ur help,
waleed said abul makarem
Avatar of slavikn
slavikn

Put it into the registry to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Avatar of Anthony Perkins
This is exactly what Microsoft's Schedulted Tasks does.

Also, please maintain your open questions:

need toll for print+ preview Date: 01/27/2002 03:34AM PST  
https://www.experts-exchange.com/questions/20259926/need-toll-for-print-preview.html
how to know the data control which is bound to a dbgrid at runtime by code Date: 05/12/2002 09:58AM PST  
https://www.experts-exchange.com/questions/20299738/how-to-know-the-data-control-which-is-bound-to-a-dbgrid-at-runtime-by-code.html
i Want to make my Control know it mouse over it or not Date: 03/13/2002 05:36PM PST
https://www.experts-exchange.com/questions/20276685/i-Want-to-make-my-Control-know-it-mouse-over-it-or-not.html
want print + preview for dbgrid Date: 01/26/2002 03:23PM PST
https://www.experts-exchange.com/questions/20259830/want-print-preview-for-dbgrid.html
Want a print and print preview and Grid control Date: 03/07/2002 05:03PM PST  
https://www.experts-exchange.com/questions/20274719/Want-a-print-and-print-preview-and-Grid-control.html
Does Flash support Arabic ? Date: 01/29/2002 04:35PM PST
https://www.experts-exchange.com/questions/20260910/Does-Flash-support-Arabic.html

Thanks,
Anthony

If you don't know how to access the registry, use this module:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Option Explicit

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
Public Const REG_SZ = 1 'Unicode nul terminated string
Public Const REG_BINARY = 3 'Free form binary
Public Const REG_DWORD = 4 '32-bit number
Public Const ERROR_SUCCESS = 0&

Public Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long

Public Declare Function RegCreateKey Lib "advapi32.dll" _
Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey _
As String, phkResult As Long) As Long

Public Declare Function RegDeleteKey Lib "advapi32.dll" _
Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey _
As String) As Long

Public Declare Function RegDeleteValue Lib "advapi32.dll" _
Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal _
lpValueName As String) As Long

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 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

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

Public Sub DeleteValue(ByVal hKey As Long, _
    ByVal strPath As String, ByVal strValue As String)
    Dim hCurKey As Long
    Dim lRegResult As Long

    lRegResult = RegOpenKey(hKey, strPath, hCurKey)
    lRegResult = RegDeleteValue(hCurKey, strValue)
    lRegResult = RegCloseKey(hCurKey)
End Sub

Public Sub DeleteKey(ByVal hKey As Long, ByVal strPath As String)
    Dim lRegResult As Long

    lRegResult = RegDeleteKey(hKey, strPath)
End Sub

Public Sub CreateKey(hKey As Long, strPath As String)
    Dim hCurKey As Long
    Dim lRegResult As Long

    lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    If lRegResult <> ERROR_SUCCESS Then
        'there is a problem
    End If

    lRegResult = RegCloseKey(hCurKey)
End Sub

Public Function GetSettingString(hKey As Long, strPath As String, strValue As String, Optional Default As String) As String
    Dim hCurKey As Long
    Dim lResult As Long
    Dim lValueType As Long
    Dim strBuffer As String
    Dim lDataBufferSize As Long
    Dim intZeroPos As Integer
    Dim lRegResult As Long

    'Set up default value
    If Not IsEmpty(Default) Then
        GetSettingString = Default
            Else
        GetSettingString = ""
    End If

    lRegResult = RegOpenKey(hKey, strPath, hCurKey)
    lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, lValueType, ByVal 0&, lDataBufferSize)
    If lRegResult = ERROR_SUCCESS Then
        If lValueType = REG_SZ Then
            strBuffer = String(lDataBufferSize, " ")
            lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, ByVal strBuffer, lDataBufferSize)
            intZeroPos = InStr(strBuffer, Chr$(0))
            If intZeroPos > 0 Then
                GetSettingString = Left$(strBuffer, intZeroPos - 1)
                    Else
                GetSettingString = strBuffer
            End If
        End If
            Else
        'there is a problem
    End If

    lRegResult = RegCloseKey(hCurKey)
End Function

Public Sub SaveSettingString(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim hCurKey As Long
    Dim lRegResult As Long

    lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    If lRegResult <> ERROR_SUCCESS Then
        'there is a problem
    End If

    lRegResult = RegCloseKey(hCurKey)
End Sub

Public Function GetSettingLong(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String, Optional Default As Long) As Long
    Dim lRegResult As Long
    Dim lValueType As Long
    Dim lBuffer As Long
    Dim lDataBufferSize As Long
    Dim hCurKey As Long

    'Set up default value
    If Not IsEmpty(Default) Then
        GetSettingLong = Default
            Else
        GetSettingLong = 0
    End If
    lRegResult = RegOpenKey(hKey, strPath, hCurKey)
    lDataBufferSize = 4 '4 bytes = 32 bits = long

    lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, _
    lValueType, lBuffer, lDataBufferSize)

    If lRegResult = ERROR_SUCCESS Then
        If lValueType = REG_DWORD Then
            GetSettingLong = lBuffer
        End If
            Else
        'there is a problem
    End If

    lRegResult = RegCloseKey(hCurKey)
End Function

Public Sub SaveSettingLong(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String, ByVal lData As Long)
    Dim hCurKey As Long
    Dim lRegResult As Long

    lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    lRegResult = RegSetValueEx(hCurKey, strValue, 0&, REG_DWORD, lData, 4)
   
    If lRegResult <> ERROR_SUCCESS Then
        'there is a problem
    End If

    lRegResult = RegCloseKey(hCurKey)
End Sub

Public Function GetSettingByte(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, Optional Default As Variant) As Variant
    Dim lValueType As Long
    Dim byBuffer() As Byte
    Dim lDataBufferSize As Long
    Dim lRegResult As Long
    Dim hCurKey As Long

    If Not IsEmpty(Default) Then
        If VarType(Default) = vbArray + vbByte Then
            GetSettingByte = Default
                Else
            GetSettingByte = 0
        End If
            Else
        GetSettingByte = 0
    End If

    lRegResult = RegOpenKey(hKey, strPath, hCurKey)
    lRegResult = RegQueryValueEx(hCurKey, strValueName, 0&, lValueType, ByVal 0&, lDataBufferSize)
    If lRegResult = ERROR_SUCCESS Then
        If lValueType = REG_BINARY Then
            ReDim byBuffer(lDataBufferSize - 1) As Byte
            lRegResult = RegQueryValueEx(hCurKey, strValueName, 0&, lValueType, byBuffer(0), lDataBufferSize)
            GetSettingByte = byBuffer
        End If
            Else
        'there is a problem
    End If

    lRegResult = RegCloseKey(hCurKey)
End Function

Public Sub SaveSettingByte(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, byData() As Byte)
    Dim lRegResult As Long
    Dim hCurKey As Long

    lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    lRegResult = RegSetValueEx(hCurKey, strValueName, 0&, REG_BINARY, byData(0), UBound(byData()) + 1)
   
    lRegResult = RegCloseKey(hCurKey)
End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please accept as answer if this helped!

Best regards,
slavikn.
Avatar of waleed_makarem

ASKER

hi,
thank you for this answer, i will try it right now, but i also want the program to know if this initialization was done automatically when windows starts or by the user who can start the software by progam files and click on software icon.

i will inform u about your code.
thank u in advance ,

waleed said
You can pass a parameter when the program is started from the registery.

For example:
Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Name: MyProg
Value: c:\program files\myprog\start.exe /FromReg

Then when the program starts, check if the first parameter is "FromReg". If yes, the program was started from the registry. If not, it was started by the user.

PLEASE ACCEPT IF MY ANSWERS HELPED!
If you need more help, ask!
hi ,
that is ok
but there still a little bit question ?
How my program will detect this parameter ???

i promise this will be the last question .

Thank u in advance.
waleed said
ASKER CERTIFIED SOLUTION
Avatar of slavikn
slavikn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi Slavikn,

thank u for ur valuable informations anyway.
the problem still exists and i included this part in my first question. i asked about the complete solution of this problem.
Any way, you had enhanced my vb knoledge.
Thank u for that .

Also i will accept ur answer-though the problem still exists- for ur effort and interst u made.
NB. Please inform me if u gain the 80 pts because i have a problem .
Thank u again .

For this final question , acually i do not know ho to get an answer but i will try.

Best regards,
waleed said
thank u so much for the effort u made.
plz contact me if u have any answer for this question.

waleed
Hi,

Thanks. I got 80*4 points. *4 is because of the "A Grade".