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 C:program files/my prog/runme.bat
Could someone show me what i need to write and how i write it
Many thanks
Jamie
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?
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
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:
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private 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
REG KEY'S CONST:
VB Code:
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const KEY_WRITE = &H20006
Private Const REG_SZ = 1
Make the Sub Setboot:
VB Code:
Private Sub SetBoot(ByVal hKey As Long, ByVal MKey As String, ByVal stringKeyVal As String, ByVal subkey As String)
Dim HRKey As Long, StrB As String
Dim retval As Long
retval = RegOpenKeyEx(hKey, subkey, 0, KEY_WRITE, HRKey)
If retval <> 0 Then
Exit Sub
End If
StrB = stringKeyVal & vbNullChar
retval = RegSetValueEx(HRKey, MKey, 0, REG_SZ, ByVal StrB, Len(StrB))
RegCloseKey HRKey
End Sub
Finaly in your Form_Load you can add the following code:
VB Code:
Call SetBoot(HKEY_LOCAL_MACHINE, "YOUR APP", App.Path & "\" & App.EXEName & ".exe", "Software\Microsoft\Windows\CurrentVersion\RunOnce")
Hope it helps a little