Results 1 to 4 of 4

Thread: setting an exe to runonce

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    setting an exe to runonce

    Hi there

    after my prog has been installed i need to run a .bat or an exe file on the next boot

    I know i need to set a reg key in the runonce key, but i i havent fouind any examples of what i actually need to write

    My program is at Crogram files/my prog/runme.bat

    Could someone show me what i need to write and how i write it

    Many thanks

    Jamie

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: setting an exe to runonce

    The next boot of what? The machine itself or your program?

    Does your program require a reboot to work?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    Re: setting an exe to runonce

    hi there

    Basically we have a reader program amd a full program, When installing the full version, we need to un register and remove the reader dll on the next boot of the machine, because it may be in use when installing the full prog

    Jamie

  4. #4
    Member
    Join Date
    Sep 2006
    Posts
    41

    Re: setting an exe to runonce

    This will set your App to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce

    First the Declarations:
    VB Code:
    1. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    2. (ByVal hKey As Long, ByVal lpSubKey As String, _
    3. ByVal ulOptions As Long, _
    4. ByVal samDesired As Long, _
    5. phkResult As Long) As Long
    6.  
    7. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    8.  
    9. Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
    10. (ByVal hKey As Long, ByVal lpValueName As String, _
    11. ByVal Reserved As Long, _
    12. ByVal dwType As Long, _
    13. lpData As Any, _
    14. ByVal cbData As Long) As Long

    REG KEY'S CONST:
    VB Code:
    1. Private Const HKEY_CURRENT_USER = &H80000001
    2. Private Const HKEY_LOCAL_MACHINE = &H80000002
    3. Private Const KEY_WRITE = &H20006
    4. Private Const REG_SZ = 1

    Make the Sub Setboot:
    VB Code:
    1. Private Sub SetBoot(ByVal hKey As Long, ByVal MKey As String, ByVal stringKeyVal As String, ByVal subkey As String)
    2. Dim HRKey As Long, StrB As String
    3. Dim retval As Long
    4. retval = RegOpenKeyEx(hKey, subkey, 0, KEY_WRITE, HRKey)
    5. If retval <> 0 Then
    6. Exit Sub
    7. End If
    8. StrB = stringKeyVal & vbNullChar
    9. retval = RegSetValueEx(HRKey, MKey, 0, REG_SZ, ByVal StrB, Len(StrB))
    10. RegCloseKey HRKey
    11. End Sub

    Finaly in your Form_Load you can add the following code:
    VB Code:
    1. Call SetBoot(HKEY_LOCAL_MACHINE, "YOUR APP", App.Path & "\" & App.EXEName & ".exe", "Software\Microsoft\Windows\CurrentVersion\RunOnce")

    Hope it helps a little

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width