ABRIR PROGRAMAR AO INICIAR O WINDOWS
Olá =)
Gostaria de saber qual função eu uso para fazer que o programa inicie-se automaticamente toda vez que o windows for iniciado...
Obrigado..
Gostaria de saber qual função eu uso para fazer que o programa inicie-se automaticamente toda vez que o windows for iniciado...
Obrigado..
Eu conheço 2 opções...
1. No menu iniciar >> programas >> Iniciar
(vc coloca o atalho do seu programa e quando o windows abrir ele executa sozinho)
2. colocando no registro do windows: chave (HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run)
espero ter ajudado... t+
1. No menu iniciar >> programas >> Iniciar
(vc coloca o atalho do seu programa e quando o windows abrir ele executa sozinho)
2. colocando no registro do windows: chave (HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run)
espero ter ajudado... t+
Como eu poderia alterar o registro? existe algum comando?
CERVEJ4
Faça o que o LMestrinare disse e ache essa chave
Qdo achar clique com botão direito do lado direito da janela, NOVO > Valor da Sequência - Coloque o nome do seu sistema
Depois clique com botão direito em cima dele, vá em Modificar.
Em Dados do Valor, escreva o path do seu programa e o executável tipo: C:\Windows\Calc.exe
Isso resolverá seu problema
Ou mais simples, crie um atalho do seu programa e coloque dentro do Menu Programas/Inicializar do computador.
Boa sorte!
Há algum API que funcione no VB para inserir essa chave?
Pesquisei aqui no forum mesmo e tem varios exemplos de como trabalhar com registro do windows, procura por registro que você vai ver varios exemplos.
Fiz uma classe simples de manipulação de regstro.... Talvez possa ajudar!
link off aki =/
'APIs to handle Registry
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) 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 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
'HKEYs
Public Enum KeyName
HKEY_CLASSES_ROOT = 0
HKEY_CURRENT_USER = 1
HKEY_LOCAL_MACHINE = 2
HKEY_USERS = 3
HKEY_CURRENT_CONFIG = 5
End Enum
'Value types
Public Enum ValueType
REG_SZ = 1 ' Unicode nul terminated string
REG_BINARY = 3 ' Free form binary
REG_DWORD = 4 ' 32-bit number
End Enum
'Available operations to values
Public Enum RegValueOperation
DeleteValue = 0
UpdateValue = 1
QueryValue = 2
End Enum
'Available operations to keys
Public Enum RegKeyOperation
DeleteKey = 0
UpdateKey = 1
End Enum
'Error message in failure case
Public ErrorMessage As String
'In the query case, the variable ValueContent will receive the value from registry
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) 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 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
'HKEYs
Public Enum KeyName
HKEY_CLASSES_ROOT = 0
HKEY_CURRENT_USER = 1
HKEY_LOCAL_MACHINE = 2
HKEY_USERS = 3
HKEY_CURRENT_CONFIG = 5
End Enum
'Value types
Public Enum ValueType
REG_SZ = 1 ' Unicode nul terminated string
REG_BINARY = 3 ' Free form binary
REG_DWORD = 4 ' 32-bit number
End Enum
'Available operations to values
Public Enum RegValueOperation
DeleteValue = 0
UpdateValue = 1
QueryValue = 2
End Enum
'Available operations to keys
Public Enum RegKeyOperation
DeleteKey = 0
UpdateKey = 1
End Enum
'Error message in failure case
Public ErrorMessage As String
'In the query case, the variable ValueContent will receive the value from registry
Public Function EditRegValue(ByVal RegOperation As RegValueOperation, _
ByVal KeyName As KeyName, _
ByVal SubKey As String, _
ByVal ValueName As String, _
Optional ByVal ValueType As ValueType, _
Optional ByRef ValueContent As Variant) As Boolean
Dim result As Long
Dim key As Long
Dim QueryResultDWORD As Long
Dim QueryResult As String
Dim QueryBuffer As Long
EditRegValue = False
'Open the key
result = RegOpenKey("&H8000000" & KeyName, SubKey, key)
'Error test
If result <> 0 Then
ErrorMessage = "Unable to open key"
Exit Function
End If
Select Case RegOperation
Case DeleteValue
'Deletes a value inside the opened key
result = RegDeleteValue(key, ValueName)
ErrorMessage = "Unable to delete value"
Case UpdateValue
'The update function create the value if it doesn't exist
If ValueType = REG_DWORD Then
'Create/Update DWORD values
result = RegSetValueEx(key, ValueName, 0&, ValueType, CLng(ValueContent), 4)
Else
'Create/Update string values
result = RegSetValueEx(key, ValueName, 0&, ValueType, ByVal CStr(ValueContent), Len(ValueContent))
End If
ErrorMessage = "Unable to update value"
Case QueryValue
'Take the buffer size of value
result = RegQueryValueEx(key, ValueName, 0&, ValueType, ByVal 0, QueryBuffer)
If ValueType = REG_SZ Then
'Fill the string variable to receive the value
QueryResult = String(QueryBuffer, 0)
'Take the value from registry
result = RegQueryValueEx(key, ValueName, 0&, ValueType, ByVal QueryResult, QueryBuffer)
If result = 0 Then
'Take off the last char from string (null char)
ValueContent = Left(QueryResult, QueryBuffer - 1)
End If
Else
'In DWORD & BINARY cases we don't need to fill the variable that will receive the value
result = RegQueryValueEx(key, ValueName, 0&, ValueType, QueryResultDWORD, QueryBuffer)
If result = 0 Then
'Returns the value
ValueContent = QueryResultDWORD
End If
End If
ErrorMessage = "Unable to query value"
End Select
If result <> 0 Then
Exit Function
Else
ErrorMessage = ""
EditRegValue = True
End If
RegCloseKey key
End Function
Public Function EditRegKey(ByVal RegOperation As RegKeyOperation, _
ByVal KeyName As KeyName, _
ByVal SubKey As String, _
ByVal Name As String) As Boolean
Dim result As Long
Dim key As Long
Dim phkResult As Long
EditRegKey = False
'Open the key
result = RegOpenKey("&H8000000" & KeyName, SubKey, key)
'Error test
If result <> 0 Then
ErrorMessage = "Unable to open key"
Exit Function
End If
Select Case RegOperation
Case DeleteKey
'Deletes a subkey inside the opened key
'If we have subkeys under these one, the function fails
result = RegDeleteKey(key, Name)
If result = 5 Then
ErrorMessage = "Unable to delete a key that contain subkeys"
Else
ErrorMessage = "Unable to delete key"
End If
Case UpdateKey
'Create a new key under the opened key
result = RegCreateKey(key, Name, phkResult)
ErrorMessage = "Unable to update key"
End Select
If result <> 0 Then
Exit Function
Else
ErrorMessage = ""
EditRegKey = True
End If
RegCloseKey key
End Function
Obrigado Grillo
Tópico encerrado , respostas não são mais permitidas