Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 | 2 |

 

  Вопрос: реестр Добавлено: 09.01.10 20:12  

Автор вопроса:  ηikolaŠ~rus | ICQ: 604058327 
Здрасте!Как програмно записать(при нажатии на кнопку) прогу в реестр в Run (автозагрузка)
Пробовал
Dim q As String
Private Sub Command1_Click()
q = App.Path + "\proga.exe" 'Узнаем путь к нашей программе(App.Path), и прибавляем ее название(НЕЗАБУДЬ ЕЕ ПЕРЕИМЕНОВАТЬ В proga)
SetKeyValue HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Proga", q, REG_SZ 'Запись!
End Sub

Не идет, назнаю чем автор думал когда ето писал

Ответить

  Ответы Всего ответов: 17  

Номер ответа: 1
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #1
Добавлено: 09.01.10 21:39
ОН, наверное, как раз-таки думал. Где функция SetKeyValue?

Ответить

Номер ответа: 2
Автор ответа:
 Саня



ICQ: 553816426 

Вопросов: 10
Ответов: 99
 Профиль | | #2 Добавлено: 09.01.10 23:15
Записать программу на авто запуск можно двумя способами:
1. Создать файл ключа реестра и запустить на исполнение с ключом S
2. Или написать программу, которая производит запись в реестр, средствами АПИ функций.
СПОСОБ ПЕРВЫЙ
Создаем текстовый файл с расширением reg и с таким содержимым:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN]
"Троян"="C:\\WINDOWS\\system\\Троян.ехе"
И запускаем его с ключом /s (это чтобы не было вопросов).
(предполагаю, что автору вопроса, известно как, программно, создавать\удалять текстовые файлы и запускать их - если, нет, то напишу.).

СПОСОБ ВТОРОЙ
Создаем новый проект.
В разделе General пишем:

  1. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  2. Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
  3. Private Const REG_SZ = 1
  4. Private Const HKEY_LOCAL_MACHINE = &H80000002

Добавляем модуль с именем basRegistry
В модуль пишем это:
  1. '*********************************************************************
  2. ' REGSITRY.BAS - Contains the code necessary to access the Windows
  3. '                registration datbase.
  4. '*********************************************************************
  5. Option Explicit
  6. '*********************************************************************
  7. ' The minimal API calls required to read from and write to the
  8. ' registry.
  9. '*********************************************************************
  10. Private Declare Function RegOpenKeyEx Lib "advapi32" Alias _
  11.     "RegOpenKeyExA" (ByVal hKey&, ByVal lpSubKey$, ByVal _
  12.     dwReserved&, ByVal samDesired As Long, phkResult As Long) As Long
  13.     
  14. Private Declare Function RegQueryValueEx Lib "advapi32" Alias _
  15.     "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  16.     String, lpReserved As Long, lpType As Long, lpData As Any, _
  17.     lpcbData As Long) As Long
  18.     
  19. Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias _
  20.     "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  21.     String, ByVal Reserved As Long, ByVal dwType As Long, lpData _
  22.     As Any, ByVal cbData As Long) As Long
  23.     
  24. Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
  25.     "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
  26.     ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
  27.     As Long, ByVal samDesired As Long, lpSecurityAttributes As _
  28.     Long, phkResult As Long, lpdwDisposition As Long) _
  29.     As Long
  30. Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  31.  
  32. Private Declare Function RegCloseKey& Lib "advapi32" (ByVal hKey&)
  33. '*********************************************************************
  34. ' The constants used in this module for the registry API calls.
  35. '*********************************************************************
  36. Private Const KEY_QUERY_VALUE = &H1
  37. Private Const KEY_SET_VALUE = &H2
  38. Private Const KEY_CREATE_SUB_KEY = &H4
  39. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  40. Private Const KEY_NOTIFY = &H10
  41. Private Const KEY_CREATE_LINK = &H20
  42. Private Const STANDARD_RIGHTS_ALL = &H1F0000
  43. Private Const SYNCHRONIZE = &H100000
  44.  
  45. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or _
  46.         KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY _
  47.         Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
  48.         KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  49.  
  50. Private Const REG_SZ = 1        ' Unicode null terminated string
  51. Private Const ERROR_SUCCESS = 0
  52. '*********************************************************************
  53. ' The numeric constants for the major keys in the registry.  These
  54. ' are made public so users can use these numeric constants externally.
  55. '*********************************************************************
  56. Public Const HKEY_CLASSES_ROOT = &H80000000
  57. Public Const HKEY_CURRENT_USER = &H80000001
  58. Public Const HKEY_LOCAL_MACHINE = &H80000002
  59. Public Const HKEY_USERS = &H80000003
  60. Public Const HKEY_PERFORMANCE_DATA = &H80000004
  61. '*********************************************************************
  62. ' This module raises errors using this base value
  63. '*********************************************************************
  64. Public Const ERRBASE As Long = vbObjectError + 6000
  65. Public Const REG_UNSUPPORTED As String = _
  66.                             "<Format Not Supported by Registry.bas>"
  67. '*********************************************************************
  68. ' Additional API calls for advanced registry features. These features
  69. ' are included by default, but may be excluded by setting the
  70. ' LEAN_AND_MEAN conditional compilation argument = 1 in your project
  71. ' properties dialog.
  72. '*********************************************************************
  73. #If LEAN_AND_MEAN = 0 Then
  74. Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias _
  75.     "RegEnumKeyExA" (ByVal hKey&, ByVal dwIndex&, ByVal lpName$, _
  76.     lpcbName As Long, ByVal lpReserved&, ByVal lpClass$, lpcbClass&, _
  77.     lpftLastWriteTime As Any) As Long
  78.     
  79. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias _
  80.     "RegEnumValueA" (ByVal hKey&, ByVal dwIndex&, ByVal lpValueName$ _
  81.     , lpcbValueName&, ByVal lpReserved&, lpType&, lpData As Any, _
  82.     lpcbData As Long) As Long
  83.     
  84. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias _
  85.     "RegDeleteKeyA" (ByVal hKey&, ByVal lpSubKey As String) As Long
  86.  
  87. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias _
  88.     "RegDeleteValueA" (ByVal hKey&, ByVal lpValueName$) As Long
  89.     
  90. Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias _
  91.     "RegQueryInfoKeyA" (ByVal hKey&, ByVal lpClass$, lpcbClass&, _
  92.     ByVal lpReserved&, lpcSubKeys&, lpcbMaxSubKeyLen&, _
  93.     lpcbMaxClassLen&, lpcValues&, lpcbMaxValueNameLen&, _
  94.     lpcbMaxValueLen&, lpcbSecurityDescriptor&, lpftLastWriteTime _
  95.     As Any) As Long
  96.     
  97. '*********************************************************************
  98. ' Additional constants used by these registry API calls.
  99. '*********************************************************************
  100. Private Const ERROR_NO_MORE_ITEMS = 259&
  101. Private Const REG_DWORD = 4
  102. #End If
  103.  
  104. '*********************************************************************
  105. ' GetRegString takes three arguments. A HKEY constant (listed above),
  106. ' a subkey, and a value in that subkey. This function returns the
  107. ' string stored in the strValueName value in the registry.
  108. '*********************************************************************
  109. Public Function GetRegString(hKey As Long, strSubKey As String, _
  110.                                 strValueName As String) As String
  111.     Dim strSetting As String
  112.     Dim lngDataLen As Long
  113.     Dim hSubKey As Long
  114.     '*****************************************************************
  115.     ' Open the key. If success, then get the data from the key.
  116.     '*****************************************************************
  117.     If RegOpenKeyEx(hKey, strSubKey, 0, KEY_ALL_ACCESS, hSubKey) = _
  118.         ERROR_SUCCESS Then
  119.         strSetting = Space(255)
  120.         lngDataLen = Len(strSetting)
  121.         '*************************************************************
  122.         ' Query the key for the current setting. If this call
  123.         ' succeeds, then return the string.
  124.         '*************************************************************
  125.         If RegQueryValueEx(hSubKey, strValueName, ByVal 0, _
  126.             REG_SZ, ByVal strSetting, lngDataLen) = _
  127.             ERROR_SUCCESS Then
  128.             If lngDataLen > 1 Then
  129.                 GetRegString = Left(strSetting, lngDataLen - 1)
  130.             End If
  131.         Else
  132.             Err.Raise ERRBASE + 1, "GetRegString", _
  133.                 "RegQueryValueEx failed!"
  134.         End If
  135.         '*************************************************************
  136.         ' ALWAYS close any keys that you open.
  137.         '*************************************************************
  138.         RegCloseKey hSubKey
  139.     End If
  140. End Function
  141. Public Sub SetRegString(hKey As Long, strSubKey As String, strValueName As String, strSetting As String)
  142. Dim hNewHandle As Long
  143. Dim lpdwDisposition As Long
  144. If RegCreateKeyEx(hKey, strSubKey, 0, strValueName, 0, KEY_ALL_ACCESS, 0&, hNewHandle, lpdwDisposition) = ERROR_SUCCESS Then
  145.        If RegSetValueEx(hNewHandle, strValueName, 0, REG_SZ, ByVal strSetting, Len(strSetting)) <> ERROR_SUCCESS Then
  146.             Err.Raise ERRBASE + 2, "SetRegString", "RegSetValueEx failed!"
  147.         Else
  148.         MsgBox "&#194;&#242;&#238;&#240;&#238;&#233; &#240;&#224;&#231; &#237;&#229;&#242;"
  149.         End If
  150. Else
  151.     Dim a
  152.     a = RegCreateKeyEx(hKey, strSubKey, 0, strValueName, 0, KEY_ALL_ACCESS, 0&, hNewHandle, lpdwDisposition)
  153.     MsgBox a
  154. a = 0
  155. a = RegCreateKey(HKEY_LOCAL_MACHINE, "Software\XYZ", hNewHandle)
  156. MsgBox a
  157.  
  158. '        Err.Raise ERRBASE + 3, "SetRegString", "RegCreateKeyEx failed!"
  159. End If
  160. RegCloseKey hNewHandle
  161. End Sub
  162. '*********************************************************************
  163. ' Extended registry functions begin here
  164. '*********************************************************************
  165. #If LEAN_AND_MEAN = 0 Then
  166. '*********************************************************************
  167. ' Returns a DWORD value from a given regsitry key
  168. '*********************************************************************
  169. Public Function GetRegDWord(hKey&, strSubKey$, strValueName$) As Long
  170.     Dim lngDataLen As Long
  171.     Dim hSubKey As Long
  172.     Dim lngRetVal As Long
  173.     '*****************************************************************
  174.     ' Open the key. If success, then get the data from the key.
  175.     '*****************************************************************
  176.     If RegOpenKeyEx(hKey, strSubKey, 0, KEY_ALL_ACCESS, hSubKey) = _
  177.         ERROR_SUCCESS Then
  178.         '*************************************************************
  179.         ' Query the key for the current setting. If this call
  180.         ' succeeds, then return the string.
  181.         '*************************************************************
  182.         lngDataLen = 4 'Bytes
  183.         If RegQueryValueEx(hSubKey, strValueName, ByVal 0, _
  184.             REG_DWORD, lngRetVal, lngDataLen) = ERROR_SUCCESS Then
  185.             GetRegDWord = lngRetVal
  186.         Else
  187.             Err.Raise ERRBASE + 1, "GetRegDWord", _
  188.                 "RegQueryValueEx failed!"
  189.         End If
  190.         '*************************************************************
  191.         ' ALWAYS close any keys that you open.
  192.         '*************************************************************
  193.         RegCloseKey hSubKey
  194.     End If
  195. End Function
  196. '*********************************************************************
  197. ' Sets a registry key to a DWORD value
  198. '*********************************************************************
  199. Public Sub SetRegDWord(hKey&, strSubKey$, strValueName$, lngSetting&)
  200.     Dim hNewHandle As Long
  201.     Dim lpdwDisposition As Long
  202.     '*****************************************************************
  203.     ' Create & open the key. If success, then get then write the data
  204.     ' to the key.
  205.     '*****************************************************************
  206.     If RegCreateKeyEx(hKey, strSubKey, 0, strValueName, 0, _
  207.         KEY_ALL_ACCESS, 0&, hNewHandle, lpdwDisposition) = _
  208.         ERROR_SUCCESS Then
  209.         If RegSetValueEx(hNewHandle, strValueName, 0, REG_DWORD, _
  210.             lngSetting, 4) <> ERROR_SUCCESS Then
  211.             Err.Raise ERRBASE + 2, "SetRegDWord", _
  212.                 "RegSetValueEx failed!"
  213.         End If
  214.     Else
  215.         Err.Raise ERRBASE + 3, "SetRegString", "RegCreateKeyEx failed!"
  216.     End If
  217.     '*****************************************************************
  218.     ' ALWAYS close any keys that you open.
  219.     '*****************************************************************
  220.     RegCloseKey hNewHandle
  221. End Sub
  222. '*********************************************************************
  223. ' Returns an array of all of the registry keys in a given key
  224. '*********************************************************************
  225. Public Function GetRegKeys(hKey&, Optional strSubKey$) As Variant
  226.     Dim hChildKey As Long
  227.     Dim lngSubKeys As Long
  228.     Dim lngMaxKeySize As Long
  229.     Dim lngDataRetBytes As Long
  230.     Dim i As Integer
  231.     '*****************************************************************
  232.     ' Create a string array to hold the return values
  233.     '*****************************************************************
  234.     Dim strRetArray() As String
  235.     '*****************************************************************
  236.     ' If strSubKey was provided, then open it...
  237.     '*****************************************************************
  238.     If Len(strSubKey) Then
  239.         '*************************************************************
  240.         ' Exit if you did not successfully open the child key
  241.         '*************************************************************
  242.         If RegOpenKeyEx(hKey, strSubKey, 0, KEY_ALL_ACCESS, _
  243.             hChildKey) <> ERROR_SUCCESS Then
  244.             Err.Raise ERRBASE + 4, "GetRegKeys", "RegOpenKeyEx failed!"
  245.             Exit Function
  246.         End If
  247.     '*****************************************************************
  248.     ' Otherwise use the top level hKey handle
  249.     '*****************************************************************
  250.     Else
  251.         hChildKey = hKey
  252.     End If
  253.     '*****************************************************************
  254.     ' Find out the array and value sizes in advance
  255.     '*****************************************************************
  256.     If QueryRegInfoKey(hChildKey, lngSubKeys, lngMaxKeySize) _
  257.         <> ERROR_SUCCESS Or lngSubKeys = 0 Then
  258.         Err.Raise ERRBASE + 5, "GetRegKeys", "RegQueryInfoKey failed!"
  259.         If Len(strSubKey) Then RegCloseKey hChildKey
  260.         Exit Function
  261.     End If
  262.     '*****************************************************************
  263.     ' Resize the array to fit the return values
  264.     '*****************************************************************
  265.     lngSubKeys = lngSubKeys - 1 ' Adjust to zero based
  266.     ReDim strRetArray(lngSubKeys) As String
  267.     '*****************************************************************
  268.     ' Get all of the keys
  269.     '*****************************************************************
  270.     For i = 0 To lngSubKeys
  271.         '*************************************************************
  272.         ' Set the buffers to max key size returned from
  273.         ' RegQueryInfoKey
  274.         '*************************************************************
  275.         lngDataRetBytes = lngMaxKeySize
  276.         strRetArray(i) = Space(lngMaxKeySize)
  277.         
  278.         RegEnumKeyEx hChildKey, i, strRetArray(i), _
  279.             lngDataRetBytes, 0&, vbNullString, ByVal 0&, ByVal 0&
  280.         '*************************************************************
  281.         ' Trim off trailing nulls
  282.         '*************************************************************
  283.         strRetArray(i) = Left(strRetArray(i), lngDataRetBytes)
  284.     Next i
  285.     '*****************************************************************
  286.     ' ALWAYS close any key that you open (but NEVER close the top
  287.     ' level keys!!!!)
  288.     '*****************************************************************
  289.     If Len(strSubKey) Then RegCloseKey hChildKey
  290.     '*****************************************************************
  291.     ' Return the string array with the results
  292.     '*****************************************************************
  293.     GetRegKeys = strRetArray
  294. End Function
  295. '*********************************************************************
  296. ' Returns a multi dimensional variant array of all the values and
  297. ' settings in a given registry subkey.
  298. '*********************************************************************
  299. Public Function GetRegKeyValues(hKey&, strSubKey$) As Variant
  300.     Dim lngNumValues As Long      ' Number values in this key
  301.     
  302.     Dim strValues() As String     ' Value and return array
  303.     Dim lngMaxValSize  As Long    ' Size of longest value
  304.     Dim lngValRetBytes As Long    ' Size of current value
  305.     
  306.     Dim lngMaxSettingSize As Long ' Size of longest REG_SZ in this key
  307.     Dim lngSetRetBytes As Long    ' Size of current REG_SZ
  308.     
  309.     Dim lngSetting As Long        ' Used for DWORD
  310.             
  311.     Dim lngType As Long           ' Type of value returned from
  312.                                   ' RegEnumValue
  313.     
  314.     Dim hChildKey As Long         ' The handle of strSubKey
  315.     Dim i As Integer              ' Loop counter
  316.     '*****************************************************************
  317.     ' Exit if you did not successfully open the child key
  318.     '*****************************************************************
  319.     If RegOpenKeyEx(hKey, strSubKey, 0, KEY_ALL_ACCESS, hChildKey) _
  320.         <> ERROR_SUCCESS Then
  321.         Err.Raise ERRBASE + 4, "GetRegKeyValues", _
  322.             "RegOpenKeyEx failed!"
  323.         Exit Function
  324.     End If
  325.     '*****************************************************************
  326.     ' Find out the array and value sizes in advance
  327.     '*****************************************************************
  328.     If QueryRegInfoKey(hChildKey, , , lngNumValues, lngMaxValSize, _
  329.         lngMaxSettingSize) <> ERROR_SUCCESS Or lngNumValues = 0 Then
  330.         Err.Raise ERRBASE + 5, "GetRegKeyValues", _
  331.             "RegQueryInfoKey failed!"
  332.         RegCloseKey hChildKey
  333.         Exit Function
  334.     End If
  335.     '*****************************************************************
  336.     ' Resize the array to fit the return values
  337.     '*****************************************************************
  338.     lngNumValues = lngNumValues - 1 ' Adjust to zero based
  339.     ReDim strValues(0 To lngNumValues, 0 To 1) As String
  340.     '*****************************************************************
  341.     ' Get all of the values and settings for the key
  342.     '*****************************************************************
  343.     For i = 0 To lngNumValues
  344.         '*************************************************************
  345.         ' Make the return buffers large enough to hold the results
  346.         '*************************************************************
  347.         strValues(i, 0) = Space(lngMaxValSize)
  348.         lngValRetBytes = lngMaxValSize
  349.         
  350.         strValues(i, 1) = Space(lngMaxSettingSize)
  351.         lngSetRetBytes = lngMaxSettingSize
  352.         '*************************************************************
  353.         ' Get a single value and setting from the registry
  354.         '*************************************************************
  355.         RegEnumValue hChildKey, i, strValues(i, 0), lngValRetBytes, _
  356.             0, lngType, ByVal strValues(i, 1), lngSetRetBytes
  357.         '*************************************************************
  358.         ' If the return value was a string, then trim trailing nulls
  359.         '*************************************************************
  360.         If lngType = REG_SZ Then
  361.             strValues(i, 1) = Left(strValues(i, 1), lngSetRetBytes - 1)
  362.         '*************************************************************
  363.         ' Else if it was a DWord, call RegEnumValue again to store
  364.         ' the return setting in a long variable
  365.         '*************************************************************
  366.         ElseIf lngType = REG_DWORD Then
  367.             '*********************************************************
  368.             ' We already know the return size of the value because
  369.             ' we got it in the last call to RegEnumValue, so we
  370.             ' can tell RegEnumValue that its buffer size is the
  371.             ' length of the string already returned, plus one (for
  372.             ' the trailing null terminator)
  373.             '*********************************************************
  374.             lngValRetBytes = lngValRetBytes + 1
  375.             '*********************************************************
  376.             ' Make the call again using a long instead of string
  377.             '*********************************************************
  378.             RegEnumValue hChildKey, i, strValues(i, 0), _
  379.                 lngValRetBytes, 0, lngType, lngSetting, lngSetRetBytes
  380.             '*********************************************************
  381.             ' Return the long as a string
  382.             '*********************************************************
  383.             strValues(i, 1) = CStr(lngSetting)
  384.         '*************************************************************
  385.         ' Otherwise let the user know that this code doesn't support
  386.         ' the format returned (such as REG_BINARY)
  387.         '*************************************************************
  388.         Else
  389.             strValues(i, 1) = REG_UNSUPPORTED
  390.         End If
  391.         '*************************************************************
  392.         ' Store the return value and setting in a multi dimensional
  393.         ' array with the value in the 0 index and the setting in
  394.         ' the 1 index of the second dimension.
  395.         '*************************************************************
  396.         strValues(i, 0) = RTrim(Left(strValues(i, 0), lngValRetBytes))
  397.         strValues(i, 1) = RTrim(strValues(i, 1))
  398.     Next i
  399.     '*****************************************************************
  400.     ' ALWAYS close any keys you open
  401.     '*****************************************************************
  402.     RegCloseKey hChildKey
  403.     '*****************************************************************
  404.     ' Return the result as an array of strings
  405.     '*****************************************************************
  406.     GetRegKeyValues = strValues
  407. End Function
  408. '*********************************************************************
  409. ' Removes a given key from the registry
  410. '*********************************************************************
  411. Public Sub DeleteRegKey(hKey&, strParentKey$, strKeyToDel$, _
  412.     Optional blnConfirm As Boolean)
  413.     '*****************************************************************
  414.     ' Get a handle to the parent key
  415.     '*****************************************************************
  416.     Dim hParentKey As Long
  417.     If RegOpenKeyEx(hKey, strParentKey, 0, KEY_ALL_ACCESS, _
  418.         hParentKey) <> ERROR_SUCCESS Then
  419.         Err.Raise ERRBASE + 4, "DeleteRegValue", "RegOpenKeyEx failed!"
  420.         Exit Sub
  421.     End If
  422.     '*****************************************************************
  423.     ' If blnConfirm, then make sure the user wants to delete the key
  424.     '*****************************************************************
  425.     If blnConfirm Then
  426.         If MsgBox("Are you sure you want to delete " & strKeyToDel & _
  427.            "?", vbQuestion Or vbYesNo Or vbDefaultButton2) = vbNo Then
  428.             RegCloseKey hParentKey
  429.             Exit Sub
  430.         End If
  431.     End If
  432.     '*****************************************************************
  433.     ' Delete the key then close the parent key
  434.     '*****************************************************************
  435.     RegDeleteKey hParentKey, strKeyToDel
  436.     RegCloseKey hParentKey
  437. End Sub
  438. '*********************************************************************
  439. ' Removes a given value from a given registry key
  440. '*********************************************************************
  441. Public Sub DeleteRegValue(hKey&, strSubKey$, strValToDel$, _
  442.     Optional blnConfirm As Boolean)
  443.     '*****************************************************************
  444.     ' Get the handle to the subkey
  445.     '*****************************************************************
  446.     Dim hSubKey As Long
  447.     If RegOpenKeyEx(hKey, strSubKey, 0, KEY_ALL_ACCESS, _
  448.         hSubKey) = ERROR_SUCCESS Then
  449.         Err.Raise ERRBASE + 4, "DeleteRegValue", "RegOpenKeyEx failed!"
  450.     End If
  451.     '*****************************************************************
  452.     ' If blnConfirm, then make sure the user wants to delete the value
  453.     '*****************************************************************
  454.     If blnConfirm Then
  455.         If MsgBox("Are you sure you want to delete " & strValToDel & _
  456.            "?", vbQuestion Or vbYesNo Or vbDefaultButton2) = vbNo Then
  457.             RegCloseKey hSubKey
  458.             Exit Sub
  459.         End If
  460.     End If
  461.     '*****************************************************************
  462.     ' Delete the value then close the subkey
  463.     '*****************************************************************
  464.     RegDeleteValue hSubKey, strValToDel
  465.     RegCloseKey hSubKey
  466. End Sub
  467. '*********************************************************************
  468. ' Query the registry to find out information about the values about
  469. ' to be returned in subsequent calls.
  470. '*********************************************************************
  471. Private Function QueryRegInfoKey(hKey&, Optional lngSubKeys&, _
  472.     Optional lngMaxKeyLen&, Optional lngValues&, Optional _
  473.     lngMaxValNameLen&, Optional lngMaxValLen&)
  474.     
  475.     QueryRegInfoKey = RegQueryInfoKey(hKey, vbNullString, _
  476.         ByVal 0&, 0&, lngSubKeys, lngMaxKeyLen, ByVal 0&, lngValues, _
  477.         lngMaxValNameLen, lngMaxValLen, ByVal 0&, ByVal 0&)
  478.     '*****************************************************************
  479.     ' Increase these values to include room for the terminating null
  480.     '*****************************************************************
  481.     lngMaxKeyLen = lngMaxKeyLen + 1
  482.     lngMaxValNameLen = lngMaxValNameLen + 1
  483.     lngMaxValLen = lngMaxValLen + 1
  484. End Function
  485. #End If

Записываем в реестр так:
  1. Dim Adres  As String
  2. Dim R as Variant
  3. Adres=” C:\WINDOWS\system\Троян.ехе”
  4. R = RegSetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", REG_SZ, Adres, Len(Adres))

PS. Эти два способа не сработают если на машине установлен антивирус Касперского 2010, программа с таким кодом, будет автоматически помещена на карантин, по подозрению на Троян. Как это обойти пока не знаю.

Ответить

Номер ответа: 3
Автор ответа:
 Саня



ICQ: 553816426 

Вопросов: 10
Ответов: 99
 Профиль | | #3 Добавлено: 09.01.10 23:39
Просьба не воспринимать мое сообщение как рекламу отдельно взятого антивирусного продукта лаборатории Касперского, так как на антивирусах других производителей не тестировал и вполне может быть, что последние версии их программного обеспечения будут вести себя аналогично.

Ответить

Номер ответа: 4
Автор ответа:
 Smith



ICQ: adamis@list.ru 

Вопросов: 153
Ответов: 3632
 Профиль | | #4 Добавлено: 09.01.10 23:47
Я воспринимаю это сообщение как ответ на вопрос "покажите кучу разного кода для работы с реестром" :).
Для добавления в Run нафиг ненужно столько всего.

Ответить

Номер ответа: 5
Автор ответа:
 Саня



ICQ: 553816426 

Вопросов: 10
Ответов: 99
 Профиль | | #5 Добавлено: 09.01.10 23:53
Согласен, но сейчас ему нужно автозапускать программу, а завтра настройки захочет сохранять и читать...

Ответить

Номер ответа: 6
Автор ответа:
 Саня



ICQ: 553816426 

Вопросов: 10
Ответов: 99
 Профиль | | #6 Добавлено: 10.01.10 00:00
Да и по именам функций нетрудно догадаться которая производит запмсь

Ответить

Номер ответа: 7
Автор ответа:
 ηikolaŠ~rus



ICQ: 604058327 

Вопросов: 50
Ответов: 287
 Профиль | | #7 Добавлено: 10.01.10 10:55
cпасибо! попробую во ВСЕМ этом разобраться.

Ответить

Номер ответа: 8
Автор ответа:
 ηikolaŠ~rus



ICQ: 604058327 

Вопросов: 50
Ответов: 287
 Профиль | | #8 Добавлено: 10.01.10 10:57
кстати автора этой киги я видел на этом форуме,он опять свою книгу рекламировал(в которой половина кодов не пашет)

Ответить

Номер ответа: 9
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #9
Добавлено: 10.01.10 12:35
угу, такой падонок. Наверное хочет, чтобы новички посчитали, что VB6 ВООБЩЕ НЕ РАБОТАЕТ, и переключились на гребаный дотнет.

Ответить

Номер ответа: 10
Автор ответа:
 UnDeAdZak



Вопросов: 80
Ответов: 476
 Профиль | | #10 Добавлено: 10.01.10 15:36
или даже на c#)

Ответить

Номер ответа: 11
Автор ответа:
 ηikolaŠ~rus



ICQ: 604058327 

Вопросов: 50
Ответов: 287
 Профиль | | #11 Добавлено: 10.01.10 18:22
Cаня а можно плиз объяснить что куда писать,чтоб при нажатии на кнопку проект зиписывался в атозагрузку.???

Ответить

Номер ответа: 12
Автор ответа:
 Smith



ICQ: adamis@list.ru 

Вопросов: 153
Ответов: 3632
 Профиль | | #12 Добавлено: 10.01.10 18:37
Тема записи в реестр раскрыта неполностью :)

Ответить

Номер ответа: 13
Автор ответа:
 Саня



ICQ: 553816426 

Вопросов: 10
Ответов: 99
 Профиль | | #13 Добавлено: 10.01.10 22:49
Читай здесь http://www.kgcoder.org/index.php?option=com_content&task=view&id=289&Itemid=39

Ответить

Номер ответа: 14
Автор ответа:
 ηikolaŠ~rus



ICQ: 604058327 

Вопросов: 50
Ответов: 287
 Профиль | | #14 Добавлено: 10.01.10 23:03
Спасибо за сылку там много интересного,но всетаки как мне прогк записать в автозагрузку?(на этом сайте я не нашел ка это делать)

Ответить

Номер ответа: 15
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #15
Добавлено: 11.01.10 00:05
nikolas-rus, я не поленившись нашел пример, который, ты привел в самом начале.
Сначала надо было прочитать это http://vbbook.ru/book/75/
А потом уже это http://vbbook.ru/book/76/

Ответить

Страница: 1 | 2 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам