INICIAR O SISTEMA AO INICIAR O WINDOWS...
ae galera, como faço para que ao iniciar o windows, iniciar automaticamente a aplicação... obrigado.
para gravar
SetValue(eHKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "seusoftware", caminhodoexecutavel )
num módulo
Private Const KEY_ALL_ACCESS = ((1 Or 2) And (Not 1048576))
Enum HKEYs
eHKEY_CLASSES_ROOT = &H80000000
eHKEY_CURRENT_USER = &H80000001
eHKEY_LOCAL_MACHINE = &H80000002
eHKEY_USERS = &H80000003
eHKEY_PERFORMANCE_DATA = &H80000004
eHKEY_CURRENT_CONFIG = &H80000005
eHKEY_DYN_DATA = &H80000006
End Enum
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 RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private 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
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As String, lpcbData 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 Long, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
SetValue(eHKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "seusoftware", caminhodoexecutavel )
num módulo
Private Const KEY_ALL_ACCESS = ((1 Or 2) And (Not 1048576))
Enum HKEYs
eHKEY_CLASSES_ROOT = &H80000000
eHKEY_CURRENT_USER = &H80000001
eHKEY_LOCAL_MACHINE = &H80000002
eHKEY_USERS = &H80000003
eHKEY_PERFORMANCE_DATA = &H80000004
eHKEY_CURRENT_CONFIG = &H80000005
eHKEY_DYN_DATA = &H80000006
End Enum
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 RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private 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
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As String, lpcbData 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 Long, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Function SetValue(ByVal Predefinedkey As HKEYs, ByVal KeyName As String, ByVal ValueName As String, ByVal Value As Variant, Optional ComputerName As String) As Boolean
Dim GetHandle As Long
Dim hKey As Long
Dim lpType As Long
Dim lpcbData As Long
Dim lpData As String
Dim lReturnCode As Long
Dim lhRemoteRegistry As Long
On Error Resume Next
If Left$(KeyName, 1) = "\" Then
KeyName = Right$(KeyName, Len(KeyName) - 1)
End If
Call CreateSubKeys(Predefinedkey, KeyName, ComputerName)
If ComputerName = "" Then
GetHandle = RegOpenKeyEx(Predefinedkey, KeyName, 0, KEY_ALL_ACCESS, hKey)
Else
lReturnCode = RegConnectRegistry(ComputerName, Predefinedkey, lhRemoteRegistry)
GetHandle = RegOpenKeyEx(lhRemoteRegistry, KeyName, 0, KEY_ALL_ACCESS, hKey)
End If
If GetHandle = 0 Then
lpcbData = 255
lpData = String(lpcbData, Chr(0))
GetHandle = RegQueryValueEx(hKey, ValueName, 0, lpType, ByVal lpData, lpcbData)
If GetHandle = 0 Then
Select Case lpType
Case 1
GetHandle = RegSetValueExString(hKey, ValueName, 0, 1, CStr(Value), Len(Value) + 1)
Case 4
GetHandle = RegSetValueEx(hKey, ValueName, 0, 4, ByVal CLng(Value), lpcbData)
Case 3
GetHandle = RegSetValueExString(hKey, ValueName, 0, 3, CByte(Value), Len(Value) + 1)
End Select
Else
GetHandle = RegSetValueExString(hKey, ValueName, 0, 1, ByVal CStr(Value), Len(CStr(Value)) + 1)
End If
Else:
RegCloseKey hKey
End If
SetValue = True
Exit Function
End Function
Function GetValue(ByVal Predefinedkey As HKEYs, ByVal KeyName As String, ByVal ValueName As String, Optional ComputerName As String) As Variant
Dim GetHandle As Long
Dim hKey As Long
Dim lpData As String
Dim lpDataDWORD As Long
Dim lpcbData As Long
Dim lpType As Long
Dim lReturnCode As Long
Dim lhRemoteRegistry As Long
On Error Resume Next
If Left$(KeyName, 1) = "\" Then
KeyName = Right$(KeyName, Len(KeyName) - 1)
End If
If ComputerName = "" Then
GetHandle = RegOpenKeyEx(Predefinedkey, KeyName, 0, KEY_ALL_ACCESS, hKey)
Else
lReturnCode = RegConnectRegistry(ComputerName, Predefinedkey, lhRemoteRegistry)
GetHandle = RegOpenKeyEx(lhRemoteRegistry, KeyName, 0, KEY_ALL_ACCESS, hKey)
End If
If GetHandle = 0 Then
lpcbData = 255
lpData = String(lpcbData, Chr(0))
GetHandle = RegQueryValueEx(hKey, ValueName, 0, lpType, ByVal lpData, lpcbData)
If GetHandle = 0 Then
Select Case lpType
Case 1
GetHandle = RegQueryValueExString(hKey, ValueName, 0, lpType, ByVal lpData, lpcbData)
If GetHandle = 0 Then
GetValue = Left$(lpData, lpcbData - 1)
Else
GetValue = ""
End If
Case 4
GetHandle = RegQueryValueEx(hKey, ValueName, 0, lpType, lpDataDWORD, lpcbData)
If GetHandle = 0 Then
GetValue = CLng(lpDataDWORD)
Else
GetValue = 0
End If
Case 3
GetHandle = RegQueryValueEx(hKey, ValueName, 0, lpType, lpDataDWORD, lpcbData)
If GetHandle = 0 Then
GetValue = CByte(lpDataDWORD)
Else
GetValue = 0
End If
End Select
End If
RegCloseKey hKey
End If
Exit Function
End Function
Function DeletKey(ByVal Predefinedkey As HKEYs, ByVal KeyName As String, Optional ComputerName As String) As Boolean
Dim GetHandle As Long
Dim hKey As Long
Dim lReturnCode As Long
Dim lhRemoteRegistry As Long
On Error Resume Next
If Len(KeyName) = 0 Then
Exit Function
End If
If KeyNameExist(Predefinedkey, KeyName, ComputerName) = False Then
DeletKey = False
Exit Function
End If
If ComputerName = "" Then
GetHandle = RegOpenKeyEx(Predefinedkey, "", 0, KEY_ALL_ACCESS, hKey)
Else
lReturnCode = RegConnectRegistry(ComputerName, Predefinedkey, lhRemoteRegistry)
GetHandle = RegOpenKeyEx(lhRemoteRegistry, "", 0, KEY_ALL_ACCESS, hKey)
End If
If GetHandle = 0 Then
Call RegDeleteKey(hKey, KeyName)
RegCloseKey hKey
DeletKey = True
Exit Function
End If
DeletKey = False
End Function
Private Function CreateSubKeys(ByVal Predefinedkey As HKEYs, ByVal KeyName As String, Optional ComputerName As String)
Dim Temp As String
Dim n As Long
Dim Result As Long
On Error Resume Next
n = 1
If Left$(KeyName, 1) = "\" Then KeyName = Right$(KeyName, Len(KeyName) - 1)
BackCreateSubKeys:
n = InStr(n, KeyName, "\")
If n > 0 Then
Temp = Mid(KeyName, 1, n)
If KeyNameExist(Predefinedkey, Temp, ComputerName) = False Then
Call DoDir(Predefinedkey, Temp, ComputerName)
End If
n = n + 1
GoTo BackCreateSubKeys:
End If
If KeyNameExist(Predefinedkey, KeyName, ComputerName) = False Then
Call DoDir(Predefinedkey, KeyName, ComputerName)
End If
End Function
Private Function DoDir(ByVal Predefinedkey As HKEYs, ByVal KeyName As String, Optional ComputerName As String)
Dim GetHandle As Long
Dim hKey As Long
Dim lReturnCode As Long
Dim lhRemoteRegistry As Long
On Error Resume Next
If ComputerName = "" Then
GetHandle = RegOpenKeyEx(Predefinedkey, "", 0, KEY_ALL_ACCESS, hKey)
Else
lReturnCode = RegConnectRegistry(ComputerName, Predefinedkey, lhRemoteRegistry)
GetHandle = RegOpenKeyEx(lhRemoteRegistry, "", 0, KEY_ALL_ACCESS, hKey)
End If
Call RegCreateKey(hKey, KeyName, lReturnCode)
RegCloseKey hKey
End Function
Private Function KeyNameExist(ByVal Predefinedkey As HKEYs, ByVal KeyName As String, Optional ComputerName As String) As Boolean
Dim GetHandle As Long
Dim hKey As Long
Dim lReturnCode As Long
Dim lhRemoteRegistry As Long
On Error Resume Next
If Left$(KeyName, 1) = "\" Then
KeyName = Right$(KeyName, Len(KeyName) - 1)
End If
If ComputerName = "" Then
GetHandle = RegOpenKeyEx(Predefinedkey, KeyName, 0, KEY_ALL_ACCESS, hKey)
Else
lReturnCode = RegConnectRegistry(ComputerName, Predefinedkey, lhRemoteRegistry)
GetHandle = RegOpenKeyEx(lhRemoteRegistry, KeyName, 0, KEY_ALL_ACCESS, hKey)
End If
If GetHandle = 0 Then
KeyNameExist = True
End If
RegCloseKey hKey
End Function
Tópico encerrado , respostas não são mais permitidas