Visual Basic - Programador

Life is soft - evento anual de software empresarial
 
Vista:

Programador

Publicado por Javier Ivars (1 intervención) el 22/02/2001 07:40:52
¿Cómo puedo hacer para introducir una cadena en el registro de windows en la ubicación
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
para que un programa corra al iniciar windows???
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Programador

Publicado por Adán (39 intervenciones) el 23/02/2001 05:22:06
Antes que nada este código no es mío, pero no recuerdo de dónde lo saqué ya que tiene algo de tiempo.

Este ejemplo en realidad cambia al usuario de Windows, pero si cambias el HYEY_LOCAL_MACHINE por HKEY_CURRENT_USER (sólo para el usuario actual, pero si es para todos deja el Local machine) y el "Software\Microsoft\Windows\CurrentVersion" por "Software\Microsoft\Windows\CurrentVersion\Run" queda el código listo para lo que quieres

Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002

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 RegCloseKey Lib _
"advapi32.dll" (ByVal Hkey 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 Any, ByVal _
cbData As Long) As Long

Private Const REG_SZ = 1
Private Const REG_DWORD = 4

Public Function ChangeWindowsOwner(OwnerName As String, _
Organization As String) As Boolean
On Error GoTo ErrorHandler
Dim bAns As Boolean

If OwnerName = "" Or Organization = "" Then
ChangeWindowsOwner = False
Exit Function
End If

bAns = SaveString(HKEY_LOCAL_MACHINE, _
"Software\Microsoft\Windows\CurrentVersion", _
"RegisteredOwner", OwnerName)

If bAns Then bAns = SaveString(HKEY_L
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Programador (2a parte)

Publicado por Adán (39 intervenciones) el 23/02/2001 05:41:30

ChangeWindowsOwner = bAns
Exit Function
ErrorHandler:

ChangeWindowsOwner = False
Exit Function

End Function

Private Function SaveString(Hkey As Long, strPath As String, _
strValue As String, strdata As String) As Boolean

Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, _
REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
SaveString = (r = 0)
End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar