|
-
May 23rd, 2001, 01:35 AM
#1
Thread Starter
Hyperactive Member
Run on startup.....
Hi,
this probably is around somewhere, but am unable to search for it....so here goes.....how do i set my application to run at startup on an NT server??? do i just have to copy it to the startup folder?
thanx.
Last edited by rammy; May 23rd, 2001 at 01:40 AM.
-
May 23rd, 2001, 01:58 AM
#2
Member
you want it to run before login or after?
Matt Bradbury
An optimist will claim the glass is half full.
A pessimist that it is half empty.
I just think the glass is too big.
-
May 23rd, 2001, 02:02 AM
#3
Thread Starter
Hyperactive Member
-
May 23rd, 2001, 02:06 AM
#4
Member
just put it in the startup folder ... either that or you can write a registry entry in the HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\run branch.
Matt Bradbury
An optimist will claim the glass is half full.
A pessimist that it is half empty.
I just think the glass is too big.
-
May 23rd, 2001, 02:25 AM
#5
Lively Member
creating a shortcut in the startup folder.
Code:
Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal
lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As
String, ByVal lpstrLinkArgs As String) As Long
lReturn = fCreateShellLink("\Startup", "MyProgram", _
"c:\myprog\prog.exe", "")
'removing from startup:
Kill "C:\WINDOWS\Start Menu\Programs\StartUp\Myprogram.lnk"
-
May 23rd, 2001, 03:29 AM
#6
Thread Starter
Hyperactive Member
thanx rebel and rod.
but rod, i dont have the dll on the system.
-
May 23rd, 2001, 04:00 AM
#7
Lively Member
Stkit432.dll is for Visual Basic 4.0. Replace it with Vb5stkit.dll for Visual Basic 5.0, Vb6stkit.dll for Visual Basic 6.0
-
May 23rd, 2001, 04:47 AM
#8
Thread Starter
Hyperactive Member
-
May 23rd, 2001, 05:56 AM
#9
Hyperactive Member
How to make your app run at startup:
Use the registry:
Code:
'Insert the following code into a basic module:
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 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
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const ERROR_SUCCESS = 0&
Public Sub DeleteValue(ByVal hKey As Long, _
ByVal strPath As String, ByVal strValue As String)
On Error Resume Next
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)
On Error Resume Next
Dim lRegResult As Long
lRegResult = RegDeleteKey(hKey, strPath)
End Sub
Public Sub CreateKey(hKey As Long, strPath As String)
On Error Resume Next
Dim hCurKey As Long
Dim lRegResult As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
If lRegResult <> ERROR_SUCCESS Then
MsgBox "Error creating key in registry. Unhandled routine.", _
vbCritical, "Error"
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
On Error Resume Next
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
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
Err.Raise 0
End If
lRegResult = RegCloseKey(hCurKey)
End Function
Public Sub SaveSettingString(hKey As Long, strPath _
As String, strValue As String, strData As String)
On Error Resume Next
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
MsgBox "Error saving settings to registry. Unhandled routine.", _
vbCritical, "Error"
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
On Error Resume Next
Dim lRegResult As Long
Dim lValueType As Long
Dim lBuffer As Long
Dim lDataBufferSize As Long
Dim hCurKey As Long
If Not IsEmpty(Default) Then
GetSettingLong = Default
Else
GetSettingLong = 0
End If
lRegResult = RegOpenKey(hKey, strPath, hCurKey)
lDataBufferSize = 4
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, _
lValueType, lBuffer, lDataBufferSize)
If lRegResult = ERROR_SUCCESS Then
If lValueType = REG_DWORD Then
GetSettingLong = lBuffer
End If
Else
MsgBox "Error read settings from registry. Unhandled routine.", _
vbCritical, "Error"
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)
On Error Resume Next
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
MsgBox "Error saving settings to registry. Unhandled routine.", _
vbCritical, "Error"
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
On Error Resume Next
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
MsgBox "Error read settings from registry. Unhandled routine.", _
vbCritical, "Error"
End If
lRegResult = RegCloseKey(hCurKey)
End Function
Public Function SaveSettingByte(ByVal hKey As Long, ByVal _
strPath As String, ByVal strValueName As String, byData() As Byte)
On Error Resume Next
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 Function
'Insert the following code into the a startup form, or command button:
Private Sub Form_Load()
'For example: this inserts a string to the registry of the current user
'which runs your program at startup.
'If you want to run it for every user... just use HKEY_LOCAL_MACHINE
'instead of HKEY_CURRENT_USER
SaveSettingString HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", _
"MyApp", App.Path & "\" & App.EXEName & ".exe"
'This removes the string from the registry
DeleteValue HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", "MyApp"
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|