Solved

how to start software automatically when windows starts ?

Posted on 2002-07-14
10
213 Views
Last Modified: 2010-05-03
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
0
Comment
Question by:waleed_makarem
  • 5
  • 4
10 Comments
 
LVL 1

Expert Comment

by:slavikn
ID: 7152734
Put it into the registry to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7152736
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  
http://www.experts-exchange.com/mfc/Q_20259926.html
how to know the data control which is bound to a dbgrid at runtime by code Date: 05/12/2002 09:58AM PST  
http://www.experts-exchange.com/visualbasic/Q_20299738.html
i Want to make my Control know it mouse over it or not Date: 03/13/2002 05:36PM PST
http://www.experts-exchange.com/visualbasic/Q_20276685.html
want print + preview for dbgrid Date: 01/26/2002 03:23PM PST
http://www.experts-exchange.com/visualbasic/Q_20259830.html
Want a print and print preview and Grid control Date: 03/07/2002 05:03PM PST  
http://www.experts-exchange.com/vbcontrols/Q_20274719.html
Does Flash support Arabic ? Date: 01/29/2002 04:35PM PST
http://www.experts-exchange.com/flash/Q_20260910.html

Thanks,
Anthony

0
 
LVL 1

Expert Comment

by:slavikn
ID: 7152737
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.
0
 

Author Comment

by:waleed_makarem
ID: 7155063
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
0
 
LVL 1

Expert Comment

by:slavikn
ID: 7155224
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!
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:waleed_makarem
ID: 7157827
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
0
 
LVL 1

Accepted Solution

by:
slavikn earned 80 total points
ID: 7158002
Hi again,

I am sorry, I don't know how to do it in Visual Basic (just in Delphi). I tried to find it in the MSDN, but was unsuccessful. If you find a way how to do it, please let me know, or post a link to your new question (if you decide to ask it).

I hope I solved your problem. Your last question was an additional one. I WOULD answer it if I knew. Sorry.

I also hope that you will accept my answer.
Thanks in advance.
Slavikn.
0
 

Author Comment

by:waleed_makarem
ID: 7160123
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
0
 

Author Comment

by:waleed_makarem
ID: 7160129
thank u so much for the effort u made.
plz contact me if u have any answer for this question.

waleed
0
 
LVL 1

Expert Comment

by:slavikn
ID: 7160276
Hi,

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now