Advertisement
rizkijn

Source Code HDSN

Jun 9th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.74 KB | None | 0 0
  1. Option Explicit
  2. Public Const cRegsPath = "Software\www.vb-edan.blogspot.com\vbedan" '' bisa disesuaikan
  3. Private Const GENERIC_READ = &H80000000
  4. Private Const GENERIC_WRITE = &H40000000
  5. Private Const FILE_SHARE_READ = &H1
  6. Private Const FILE_SHARE_WRITE = &H2
  7. Private Const OPEN_EXISTING = 3
  8. Private Const CREATE_NEW = 1
  9. Private Const INVALID_HANDLE_VALUE = -1
  10. Private Const VER_PLATFORM_WIN32_NT = 2
  11. Private Const IDENTIFY_BUFFER_SIZE = 512
  12. Private Const OUTPUT_DATA_SIZE = IDENTIFY_BUFFER_SIZE + 16
  13.  
  14. 'GETVERSIONOUTPARAMS contains the data returned
  15. 'from the Get Driver Version function
  16. Private Type GETVERSIONOUTPARAMS
  17. bVersion As Byte 'Binary driver version.
  18. bRevision As Byte 'Binary driver revision
  19. bReserved As Byte 'Not used
  20. bIDEDeviceMap As Byte 'Bit map of IDE devices
  21. fCapabilities As Long 'Bit mask of driver capabilities
  22. dwReserved(3) As Long 'For future use
  23. End Type
  24.  
  25. 'IDE registers
  26. Private Type IDEREGS
  27. bFeaturesReg As Byte 'Used for specifying SMART "commands"
  28. bSectorCountReg As Byte 'IDE sector count register
  29. bSectorNumberReg As Byte 'IDE sector number register
  30. bCylLowReg As Byte 'IDE low order cylinder value
  31. bCylHighReg As Byte 'IDE high order cylinder value
  32. bDriveHeadReg As Byte 'IDE drive/head register
  33. bCommandReg As Byte 'Actual IDE command
  34. bReserved As Byte 'reserved for future use - must be zero
  35. End Type
  36.  
  37. 'SENDCMDINPARAMS contains the input parameters for the
  38. 'Send Command to Drive function
  39. Private Type SENDCMDINPARAMS
  40. cBufferSize As Long 'Buffer size in bytes
  41. irDriveRegs As IDEREGS 'Structure with drive register values.
  42. bDriveNumber As Byte 'Physical drive number to send command to (0,1,2,3).
  43. bReserved(2) As Byte 'Bytes reserved
  44. dwReserved(3) As Long 'DWORDS reserved
  45. bBuffer() As Byte 'Input buffer.
  46. End Type
  47.  
  48. 'Valid values for the bCommandReg member of IDEREGS.
  49. Private Const IDE_ID_FUNCTION = &HEC 'Returns ID sector for ATA.
  50. Private Const IDE_EXECUTE_SMART_FUNCTION = &HB0 'Performs SMART cmd.
  51. 'Requires valid bFeaturesReg,
  52. 'bCylLowReg, and bCylHighReg
  53.  
  54. 'Cylinder register values required when issuing SMART command
  55. Private Const SMART_CYL_LOW = &H4F
  56. Private Const SMART_CYL_HI = &HC2
  57.  
  58. 'Status returned from driver
  59. Private Type DRIVERSTATUS
  60. bDriverError As Byte 'Error code from driver, or 0 if no error
  61. bIDEStatus As Byte 'Contents of IDE Error register
  62. 'Only valid when bDriverError is SMART_IDE_ERROR
  63. bReserved(1) As Byte
  64. dwReserved(1) As Long
  65. End Type
  66.  
  67. Private Type IDSECTOR
  68. wGenConfig As Integer
  69. wNumCyls As Integer
  70. wReserved As Integer
  71. wNumHeads As Integer
  72. wBytesPerTrack As Integer
  73. wBytesPerSector As Integer
  74. wSectorsPerTrack As Integer
  75. wVendorUnique(2) As Integer
  76. sSerialNumber(19) As Byte
  77. wBufferType As Integer
  78. wBufferSize As Integer
  79. wECCSize As Integer
  80. sFirmwareRev(7) As Byte
  81. sModelNumber(39) As Byte
  82. wMoreVendorUnique As Integer
  83. wDoubleWordIO As Integer
  84. wCapabilities As Integer
  85. wReserved1 As Integer
  86. wPIOTiming As Integer
  87. wDMATiming As Integer
  88. wBS As Integer
  89. wNumCurrentCyls As Integer
  90. wNumCurrentHeads As Integer
  91. wNumCurrentSectorsPerTrack As Integer
  92. ulCurrentSectorCapacity As Long
  93. wMultSectorStuff As Integer
  94. ulTotalAddressableSectors As Long
  95. wSingleWordDMA As Integer
  96. wMultiWordDMA As Integer
  97. bReserved(127) As Byte
  98. End Type
  99.  
  100. 'Structure returned by SMART IOCTL commands
  101. Private Type SENDCMDOUTPARAMS
  102. cBufferSize As Long 'Size of Buffer in bytes
  103. DRIVERSTATUS As DRIVERSTATUS 'Driver status structure
  104. bBuffer() As Byte 'Buffer of arbitrary length for data read from drive
  105. End Type
  106.  
  107. 'Vendor specific feature register defines
  108. 'for SMART "sub commands"
  109. Private Const SMART_ENABLE_SMART_OPERATIONS = &HD8
  110.  
  111. 'Status Flags Values
  112. Public Enum STATUS_FLAGS
  113. PRE_FAILURE_WARRANTY = &H1
  114. ON_LINE_COLLECTION = &H2
  115. PERFORMANCE_ATTRIBUTE = &H4
  116. ERROR_RATE_ATTRIBUTE = &H8
  117. EVENT_COUNT_ATTRIBUTE = &H10
  118. SELF_PRESERVING_ATTRIBUTE = &H20
  119. End Enum
  120.  
  121. 'IOCTL commands
  122. Private Const DFP_GET_VERSION = &H74080
  123. Private Const DFP_SEND_DRIVE_COMMAND = &H7C084
  124. Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088
  125.  
  126. Private Type ATTR_DATA
  127. AttrID As Byte
  128. AttrName As String
  129. AttrValue As Byte
  130. ThresholdValue As Byte
  131. WorstValue As Byte
  132. StatusFlags As STATUS_FLAGS
  133. End Type
  134.  
  135. Public Type DRIVE_INFO
  136. bDriveType As Byte
  137. SerialNumber As String
  138. Model As String
  139. FirmWare As String
  140. Cilinders As Long
  141. Heads As Long
  142. SecPerTrack As Long
  143. BytesPerSector As Long
  144. BytesperTrack As Long
  145. NumAttributes As Byte
  146. Attributes() As ATTR_DATA
  147. End Type
  148.  
  149. Public Enum IDE_DRIVE_NUMBER
  150. PRIMARY_MASTER
  151. PRIMARY_SLAVE
  152. SECONDARY_MASTER
  153. SECONDARY_SLAVE
  154. TERTIARY_MASTER
  155. TERTIARY_SLAVE
  156. QUARTIARY_MASTER
  157. QUARTIARY_SLAVE
  158. End Enum
  159.  
  160. Private Declare Function CreateFile Lib "kernel32" _
  161. Alias "CreateFileA" _
  162. (ByVal lpFileName As String, _
  163. ByVal dwDesiredAccess As Long, _
  164. ByVal dwShareMode As Long, _
  165. lpSecurityAttributes As Any, _
  166. ByVal dwCreationDisposition As Long, _
  167. ByVal dwFlagsAndAttributes As Long, _
  168. ByVal hTemplateFile As Long) As Long
  169.  
  170. Private Declare Function CloseHandle Lib "kernel32" _
  171. (ByVal hObject As Long) As Long
  172.  
  173. Private Declare Function DeviceIoControl Lib "kernel32" _
  174. (ByVal hDevice As Long, _
  175. ByVal dwIoControlCode As Long, _
  176. lpInBuffer As Any, _
  177. ByVal nInBufferSize As Long, _
  178. lpOutBuffer As Any, _
  179. ByVal nOutBufferSize As Long, _
  180. lpBytesReturned As Long, _
  181. lpOverlapped As Any) As Long
  182.  
  183. Private Declare Sub CopyMemory Lib "kernel32" _
  184. Alias "RtlMoveMemory" _
  185. (hpvDest As Any, _
  186. hpvSource As Any, _
  187. ByVal cbCopy As Long)
  188.  
  189. Private Type OSVERSIONINFO
  190. OSVSize As Long
  191. dwVerMajor As Long
  192. dwVerMinor As Long
  193. dwBuildNumber As Long
  194. PlatformID As Long
  195. szCSDVersion As String * 128
  196. End Type
  197.  
  198. Private Declare Function GetVersionEx Lib "kernel32" _
  199. Alias "GetVersionExA" _
  200. (LpVersionInformation As OSVERSIONINFO) As Long
  201.  
  202. Private vhKey As Long
  203. Private vKeyRoot As HKEYROOT
  204. Private vSubKey As String
  205. Private vNKey As Long
  206. Private vNValue As Long
  207.  
  208. Public Enum HKEYROOT
  209. HKEY_CLASSES_ROOT = &H80000000
  210. HKEY_CURRENT_USER = &H80000001
  211. HKEY_LOCAL_MACHINE = &H80000002
  212. HKEY_USERS = &H80000003
  213. HKEY_PERFORMANCE_DATA = &H80000004
  214. HKEY_CURRENT_CONFIG = &H80000005
  215. HKEY_DYN_DATA = &H80000006
  216. End Enum
  217. Private Type SECURITY_ATTRIBUTES
  218. nLength As Long
  219. lpSecurityDescriptor As Long
  220. bInheritHandle As Long
  221. End Type
  222. Public Enum VALUETYPE
  223. REG_SZ = 1
  224. REG_BINARY = 3
  225. REG_DWORD = 4
  226. End Enum
  227. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  228. Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
  229. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  230. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
  231. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
  232. 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
  233. 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.
  234. 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.
  235. Private Const ERROR_NO_MORE_ITEMS = 259
  236. Private Const ERROR_MORE_DATA = 234
  237. Private Const ERROR_FILE_NOT_FOUND = 2
  238. Private Const ERROR_SUCCESS = 0
  239. Private Const ERROR_ISCLOSE = -1
  240. Private Const ERROR_ISOPEN = -2
  241. Private Const ERROR_UNSUPPORT_TYPE = -3
  242. Private Const ERROR_DATA_TO_LONG = -4
  243. Private Const ERROR_VALUE_TYPE = -5
  244.  
  245. Private Const KEY_CREATE_LINK = &H20
  246. Private Const KEY_CREATE_SUB_KEY = &H4
  247. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  248. Private Const KEY_NOTIFY = &H10
  249. Private Const KEY_QUERY_VALUE = &H1
  250. Private Const KEY_READ = KEY_QUERY_VALUE + KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY
  251. Private Const KEY_SET_VALUE = &H2
  252. Private Const KEY_WRITE = KEY_SET_VALUE + KEY_CREATE_SUB_KEY
  253.  
  254.  
  255. Private vSecAttrib As SECURITY_ATTRIBUTES
  256. Private vIsOpen As Boolean
  257. Private vError As Long
  258. Private vEnKey() As String
  259. Private vEnValue() As String
  260. Const MAX_IP = 5 'To make a buffer... i dont think you have more than 5 ip on your pc..
  261.  
  262.  
  263. Public Function CreateKey(ByVal pzKRoot As HKEYROOT, ByVal pzSubKey As String) As Boolean
  264. If (vhKey = 0) Then
  265. vError = RegCreateKeyEx(pzKRoot, pzSubKey, 0, "", 0, KEY_READ + KEY_WRITE, vSecAttrib, vhKey, 0)
  266. If (vError = ERROR_SUCCESS) Then
  267. vKeyRoot = pzKRoot
  268. vSubKey = pzSubKey
  269. End If
  270. Else
  271. vError = ERROR_ISOPEN
  272. End If
  273. CreateKey = vError = ERROR_SUCCESS
  274. End Function
  275. Public Function SetValue(ByVal pzValueName As String, ByVal pzValue As Variant, Optional ByVal pzValueType As VALUETYPE = REG_SZ) As Boolean
  276. '---
  277. Dim tBuffer(2048) As Byte
  278. Dim tLBuffer As Long
  279. Dim tStrBuff As String
  280. Dim i As Integer
  281. '---
  282. vError = ERROR_SUCCESS
  283. If (vhKey = 0) Then
  284. vError = ERROR_ISCLOSE
  285. Else
  286. If (pzValueType = REG_SZ) Then
  287. tStrBuff = CStr(pzValue)
  288. If (Len(tStrBuff) > 2047) Then vError = ERROR_DATA_TO_LONG
  289. Else
  290. Select Case VarType(pzValue)
  291. Case vbInteger, vbLong, vbSingle, vbDouble, vbByte, vbBoolean:
  292. tStrBuff = Hex(pzValue)
  293. If (Len(tStrBuff) Mod 2 = 1) Then tStrBuff = "0" & tStrBuff
  294. If (Len(tStrBuff) < 8) Then tStrBuff = Right("00000000" & tStrBuff, 8)
  295. If (Len(tStrBuff) > 8) And (pzValueType = REG_DWORD) Then vError = ERROR_UNSUPPORT_TYPE
  296. Case vbDate:
  297. If (pzValueType = REG_BINARY) Then
  298. tStrBuff = Format(pzValue, "yyyymmddHhNnSs")
  299. Else
  300. vError = ERROR_UNSUPPORT_TYPE
  301. End If
  302. Case vbString: vError = ERROR_UNSUPPORT_TYPE
  303. End Select
  304. If ((Len(tStrBuff) \ 2) > 2047) Then vError = ERROR_DATA_TO_LONG
  305. End If
  306. '
  307. If (vError = ERROR_SUCCESS) Then
  308. If (pzValueType = REG_SZ) Then
  309. For i = 1 To Len(tStrBuff)
  310. tBuffer(i - 1) = Asc(Mid(tStrBuff, i, 1))
  311. tBuffer(i) = 0
  312. Next
  313. tLBuffer = Len(tStrBuff) + 1
  314. Else
  315. For i = Len(tStrBuff) - 1 To 1 Step -2
  316. tBuffer(3 - (i \ 2)) = Val("&H" & Mid(tStrBuff, i, 2))
  317. Next
  318. tLBuffer = Len(tStrBuff) \ 2
  319. End If
  320. vError = RegSetValueEx(vhKey, pzValueName, 0, pzValueType, tBuffer(0), tLBuffer)
  321. End If
  322. End If
  323. SetValue = vError = ERROR_SUCCESS
  324. End Function
  325.  
  326. Public Function OpenKey(ByVal pzKRoot As HKEYROOT, ByVal pzSubKey As String) As Boolean
  327. If (vhKey = 0) Then
  328. vError = RegOpenKeyEx(pzKRoot, pzSubKey, 0, KEY_READ + KEY_WRITE, vhKey)
  329. If (vError = ERROR_SUCCESS) Then
  330. vKeyRoot = pzKRoot
  331. vSubKey = pzSubKey
  332. End If
  333. Else
  334. vError = ERROR_ISOPEN
  335. End If
  336. OpenKey = vError = ERROR_SUCCESS
  337. End Function
  338. Public Function GetValue(ByVal pzValueName As String, ByRef pzValue As Variant) As Boolean
  339. '---
  340. Dim tBuffer(2048) As Byte
  341. Dim tLBuffer As Long
  342. Dim tStrBuff As String
  343. Dim i As Integer
  344. Dim tValueType As VALUETYPE
  345. '---
  346. On Error Resume Next
  347. If (vhKey = 0) Then
  348. vError = ERROR_ISCLOSE
  349. Else
  350. tLBuffer = 2048
  351. vError = RegQueryValueEx(vhKey, pzValueName, 0, tValueType, tBuffer(0), tLBuffer)
  352. If (vError = ERROR_SUCCESS) Then
  353. Select Case tValueType
  354. Case REG_SZ:
  355. tStrBuff = StrConv(tBuffer, vbUnicode)
  356. tStrBuff = Left(tStrBuff, tLBuffer)
  357. Select Case VarType(pzValue)
  358. Case vbByte: pzValue = CByte(tStrBuff)
  359. Case vbInteger: pzValue = CInt(tStrBuff)
  360. Case vbLong: pzValue = CLng(tStrBuff)
  361. Case vbSingle: pzValue = CSng(tStrBuff)
  362. Case vbDouble: pzValue = CDbl(tStrBuff)
  363. Case vbBoolean: pzValue = CBool(tStrBuff)
  364. Case vbDate: pzValue = CDate(tStrBuff)
  365. Case vbString: pzValue = Left(tStrBuff, tLBuffer - 1)
  366. Case Else: vError = ERROR_VALUE_TYPE
  367. End Select
  368. Case REG_DWORD, REG_BINARY:
  369. Err.Clear
  370. tStrBuff = ""
  371. For i = 0 To tLBuffer - 1
  372. tStrBuff = Right("00" & Hex(tBuffer(i)), 2) & tStrBuff
  373. Next
  374. tStrBuff = Val("&H" & tStrBuff)
  375. Select Case VarType(pzValue)
  376. Case vbByte: pzValue = CByte(tStrBuff)
  377. Case vbInteger: pzValue = CInt(tStrBuff)
  378. Case vbLong: pzValue = CLng(tStrBuff)
  379. Case vbSingle: pzValue = CSng(tStrBuff)
  380. Case vbDouble: pzValue = CDbl(tStrBuff)
  381. Case vbBoolean: pzValue = CBool(tStrBuff)
  382. Case Else: vError = ERROR_VALUE_TYPE
  383. End Select
  384. If (Err.Number <> 0) Then vError = ERROR_VALUE_TYPE
  385. Case Else: vError = ERROR_UNSUPPORT_TYPE
  386. End Select
  387. End If
  388. End If
  389. GetValue = vError = ERROR_SUCCESS
  390. End Function
  391. Function GetDriveInfo(drvNumber As IDE_DRIVE_NUMBER) As DRIVE_INFO
  392.  
  393. Dim hDrive As Long
  394. Dim di As DRIVE_INFO
  395.  
  396. hDrive = SmartOpen(drvNumber)
  397.  
  398. If hDrive <> INVALID_HANDLE_VALUE Then
  399.  
  400. If SmartGetVersion(hDrive) = True Then
  401.  
  402. With di
  403. .bDriveType = 0
  404. .NumAttributes = 0
  405. ReDim .Attributes(0)
  406. .bDriveType = 1
  407. End With
  408.  
  409. If SmartCheckEnabled(hDrive, drvNumber) Then
  410.  
  411. If IdentifyDrive(hDrive, IDE_ID_FUNCTION, drvNumber, di) = True Then
  412.  
  413. GetDriveInfo = di
  414.  
  415. End If 'IdentifyDrive
  416. End If 'SmartCheckEnabled
  417. End If 'SmartGetVersion
  418. End If 'hDrive <> INVALID_HANDLE_VALUE
  419.  
  420. CloseHandle hDrive
  421.  
  422. End Function
  423.  
  424.  
  425.  
  426. Function IdentifyDrive(ByVal hDrive As Long, _
  427. ByVal IDCmd As Byte, _
  428. ByVal drvNumber As IDE_DRIVE_NUMBER, _
  429. di As DRIVE_INFO) As Boolean
  430.  
  431. 'Function: Send an IDENTIFY command to the drive
  432. 'drvNumber = 0-3
  433. 'IDCmd = IDE_ID_FUNCTION or IDE_ATAPI_ID
  434. Dim SCIP As SENDCMDINPARAMS
  435. Dim IDSEC As IDSECTOR
  436. Dim bArrOut(OUTPUT_DATA_SIZE - 1) As Byte
  437. Dim cbBytesReturned As Long
  438.  
  439. With SCIP
  440. .cBufferSize = IDENTIFY_BUFFER_SIZE
  441. .bDriveNumber = CByte(drvNumber)
  442.  
  443. With .irDriveRegs
  444. .bFeaturesReg = 0
  445. .bSectorCountReg = 1
  446. .bSectorNumberReg = 1
  447. .bCylLowReg = 0
  448. .bCylHighReg = 0
  449. .bDriveHeadReg = &HA0 'compute the drive number
  450. If Not IsWinNT4Plus Then
  451. .bDriveHeadReg = .bDriveHeadReg Or ((drvNumber And 1) * 16)
  452. End If
  453. 'the command can either be IDE
  454. 'identify or ATAPI identify.
  455. .bCommandReg = CByte(IDCmd)
  456. End With
  457. End With
  458.  
  459. If DeviceIoControl(hDrive, _
  460. DFP_RECEIVE_DRIVE_DATA, _
  461. SCIP, _
  462. Len(SCIP) - 4, _
  463. bArrOut(0), _
  464. OUTPUT_DATA_SIZE, _
  465. cbBytesReturned, _
  466. ByVal 0&) Then
  467.  
  468. CopyMemory IDSEC, bArrOut(16), Len(IDSEC)
  469.  
  470. di.Model = StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
  471. di.SerialNumber = StrConv(SwapBytes(IDSEC.sSerialNumber), vbUnicode)
  472.  
  473. IdentifyDrive = True
  474.  
  475. End If
  476.  
  477. End Function
  478. Function SwapBytes(B() As Byte) As Byte()
  479.  
  480.  
  481. Dim bTemp As Byte
  482. Dim cnt As Long
  483.  
  484. For cnt = LBound(B) To UBound(B) Step 2
  485. bTemp = B(cnt)
  486. B(cnt) = B(cnt + 1)
  487. B(cnt + 1) = bTemp
  488. Next cnt
  489.  
  490. SwapBytes = B()
  491.  
  492. End Function
  493. Public Function CloseKey() As Boolean
  494. If (vhKey = 0) Then
  495. vError = ERROR_ISCLOSE
  496. Else
  497. vError = RegCloseKey(vhKey)
  498. If (vError = ERROR_SUCCESS) Then
  499. vIsOpen = False
  500. vhKey = 0
  501. vKeyRoot = HKEY_CURRENT_USER
  502. vSubKey = ""
  503. ReDim vEnKey(0)
  504. ReDim vEnValue(0)
  505. End If
  506. End If
  507. CloseKey = vError = ERROR_SUCCESS
  508. End Function
  509.  
  510. Function IsWinNT4Plus() As Boolean
  511.  
  512. 'returns True if running Windows NT4 or later
  513. Dim osv As OSVERSIONINFO
  514.  
  515. osv.OSVSize = Len(osv)
  516.  
  517. If GetVersionEx(osv) = 1 Then
  518.  
  519. IsWinNT4Plus = (osv.PlatformID = VER_PLATFORM_WIN32_NT) And _
  520. (osv.dwVerMajor >= 4)
  521.  
  522. End If
  523.  
  524. End Function
  525. Function SmartGetVersion(ByVal hDrive As Long) As Boolean
  526.  
  527. Dim cbBytesReturned As Long
  528. Dim GVOP As GETVERSIONOUTPARAMS
  529.  
  530. SmartGetVersion = DeviceIoControl(hDrive, _
  531. DFP_GET_VERSION, _
  532. ByVal 0&, 0, _
  533. GVOP, _
  534. Len(GVOP), _
  535. cbBytesReturned, _
  536. ByVal 0&)
  537.  
  538. End Function
  539. Function SmartOpen(drvNumber As IDE_DRIVE_NUMBER) As Long
  540. 'Open SMART to allow DeviceIoControl
  541. 'communications and return SMART handle
  542.  
  543. If IsWinNT4Plus() Then
  544.  
  545. SmartOpen = CreateFile("\\.\PhysicalDrive" & CStr(drvNumber), _
  546. GENERIC_READ Or GENERIC_WRITE, _
  547. FILE_SHARE_READ Or FILE_SHARE_WRITE, _
  548. ByVal 0&, _
  549. OPEN_EXISTING, _
  550. 0&, _
  551. 0&)
  552.  
  553. Else
  554.  
  555. SmartOpen = CreateFile("\\.\SMARTVSD", _
  556. 0&, 0&, _
  557. ByVal 0&, _
  558. CREATE_NEW, _
  559. 0&, _
  560. 0&)
  561. End If
  562.  
  563. End Function
  564.  
  565. Function SmartCheckEnabled(ByVal hDrive As Long, _
  566. drvNumber As IDE_DRIVE_NUMBER) As Boolean
  567.  
  568. 'SmartCheckEnabled - Check if SMART enable
  569. 'FUNCTION: Send a SMART_ENABLE_SMART_OPERATIONS command to the drive
  570. 'bDriveNum = 0-3
  571. Dim SCIP As SENDCMDINPARAMS
  572. Dim SCOP As SENDCMDOUTPARAMS
  573. Dim cbBytesReturned As Long
  574.  
  575. With SCIP
  576.  
  577. .cBufferSize = 0
  578.  
  579. With .irDriveRegs
  580. .bFeaturesReg = SMART_ENABLE_SMART_OPERATIONS
  581. .bSectorCountReg = 1
  582. .bSectorNumberReg = 1
  583. .bCylLowReg = SMART_CYL_LOW
  584. .bCylHighReg = SMART_CYL_HI
  585.  
  586. .bDriveHeadReg = &HA0
  587. If Not IsWinNT4Plus Then
  588. .bDriveHeadReg = .bDriveHeadReg Or ((drvNumber And 1) * 16)
  589. End If
  590. .bCommandReg = IDE_EXECUTE_SMART_FUNCTION
  591.  
  592. End With
  593.  
  594. .bDriveNumber = drvNumber
  595.  
  596. End With
  597.  
  598. SmartCheckEnabled = DeviceIoControl(hDrive, _
  599. DFP_SEND_DRIVE_COMMAND, _
  600. SCIP, _
  601. Len(SCIP) - 4, _
  602. SCOP, _
  603. Len(SCOP) - 4, _
  604. cbBytesReturned, _
  605. ByVal 0&)
  606. End Function
  607.  
  608. Function Enkrip(xInput As String) As String
  609. ''INI HANYA CONTOH
  610. ''bisa disesuikan sendiri berdasarkan Enkrip generate yg anda punya
  611. Dim Output, Inputan As String
  612. Dim Panjang_Input As Integer
  613. Dim i As Integer
  614. Inputan = xInput
  615. Panjang_Input = Len(xInput)
  616. For i = 1 To Panjang_Input
  617. Enkrip = Mid(Inputan, i, 1)
  618. Enkrip = Asc(Enkrip)
  619. Enkrip = (Enkrip + 5) - 4
  620. Enkrip = Chr(Enkrip)
  621. Output = Output & Enkrip
  622.  
  623. Next i
  624.  
  625. Enkrip = Output
  626. End Function
  627.  
  628. Function Dekrip(xInput As String) As String
  629. ''INI HANYA CONTOH
  630. ''bisa disesuikan sendiri berdasarkan Dekrip generate yg anda punya
  631.  
  632. Dim Output, Inputan As String
  633. Dim Panjang_Input, Pesan As Integer
  634. Dim i As Integer
  635. Inputan = xInput
  636. Panjang_Input = Len(xInput)
  637. For i = 1 To Panjang_Input
  638. Dekrip = Mid(Inputan, i, 1)
  639. Dekrip = Asc(Dekrip)
  640. Dekrip = (Dekrip - 5) + 4
  641. Dekrip = Chr(Dekrip)
  642. Output = Output & Dekrip
  643. Next i
  644. Dekrip = Output
  645. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement