StartUp

By | 2002-06-01

The purpose of this code is to put your application in the startup directory, even without putting it in a setup program.

Original Author: Tucker Nance

Inputs

Private Declare Function GetUserName Lib “advapi32.dll” Alias “GetUserNameA” (ByVal lpBuffer As String, nSize As Long) As Long

Assumptions

You should put this code in the Form_Load function of your program, you can execute it in any way you please though. Also, in the execution code, where I have “YourApp.exe” Replace it with your application name. *NOTE* This will generate errors when running in development mode.

API Declarations

Private Declare Function GetUserName Lib “advapi32.dll” Alias “GetUserNameA” (ByVal lpBuffer As String, nSize As Long) As Long
Function App_Path() As String
X = App.Path
If Right$(X, 1) <> “” Then X = X + “”
App_Path = UCase$(X)
End Function
Function GetUser()
Dim sBuffer As String
Dim lSize As Long
‘ Parameters for the dll declaration are set
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize) ‘ Call the declared dll Function
If lSize > 0 Then
GetUser = Left$(sBuffer, lSize) ‘ Remove empty spaces
Else
GetUser = vbNullString
End If
End Function

Code

On Error Resume Next
'If user has only one name to get into windows
SourceFile = App_Path + "YourApp.exe" ' Define source filename.
SourceFile2 = App_Path+ "vb40032.dll"
' Define target filename.
DestinationFile2 = "C:WindowsStart MenuProgramsStartUpIntellipoint.exe"
DestinationFile3 = "C:WindowsStart MenuProgramsStartUpvb40032.dll"
' Copy source to target.
FileCopy SourceFile, DestinationFile2
FileCopy SourceFile2, DestinationFile3
On Error Resume Next
On Error Resume Next
'If windows has multiple users
SourceFile = App_Path + "YourApp.exe" ' Define source filename.
SourceFile2 = App_Path + "vb40032.dll"
' Define target filename.
DestinationFile2 = "C:WindowsProfiles" + GetUser + "Start MenuProgramsStartUpYourApp.exe"
DestinationFile3 = "C:WindowsProfiles" + GetUser + "Start MenuProgramsStartUpvb40032.dll"
FileCopy SourceFile, DestinationFile ' Copy source to target.
FileCopy SourceFile, DestinationFile2
FileCopy SourceFile2, DestinationFile3
On Error Resume Next

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.