PDA

View Full Version : مشکل تبدیل کد



HadiVB
دوشنبه 22 تیر 1388, 12:30 عصر
سلام اقا این کد یه برنامه ی که سریال هارد را میگیره
کدش اینه

'Version: MPL 1.1
'
' The contents of this file are subject to the Mozilla Public License Version
' 1.1 (the "License"); you may not use this file except in compliance with
' the License. You may obtain a copy of the License at
' http://www.mozilla.org/MPL/
'
' Software distributed under the License is distributed on an "AS IS" basis,
' WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
' for the specific language governing rights and limitations under the
' License.
'
' The Original Code is Get HDD info for Visual basic
'
' The Initial Developer of the Original Code is
' F0ruD - FzerorubigD@CyberRabbits.net.
' Portions created by the Initial Developer are Copyright (C) 2004
' the Initial Developer. All Rights Reserved.
'
' Contributor (s):
'
' ***** END LICENSE BLOCK ***** *)
'
Option Explicit
Option Base 0


Type IDERegs
bFeaturesReg As Byte '// Used for specifying SMART "commands".
bSectorCountReg As Byte '// IDE sector count register
bSectorNumberReg As Byte '// IDE sector number register
bCylLowReg As Byte '// IDE low order cylinder value
bCylHighReg As Byte '// IDE high order cylinder value
bDriveHeadReg As Byte '// IDE drive/head register
bCommandReg As Byte '// Actual IDE command.
bReserved As Byte '// reserved for future use. Must be zero.
End Type

Type SendCmdInParams
'Buffer size in bytes
cBufferSize As Long
'// Structure with drive register values.
irDriveRegs As IDERegs
'// Physical drive number to send command to (0,1,2,3).
bDriveNumbera As Byte
bReserved(2) As Byte
dwReserved(3) As Long
bBuffer As Byte '// Input buffer.
End Type
Type IdSector
wGenConfig As Integer
wNumCyls As Integer

wReserved As Integer
wNumHeads As Integer
wBytesPerTrack As Integer
wBytesPerSector As Integer
wSectorsPerTrack As Integer
wVendorUnique(2) As Integer
sSerialNumber(19) As Byte
wBufferType As Integer
wBufferSize As Integer
wECCSize As Integer
sFirmwareRev(7) As Byte
sModelNumber(39) As Byte
wMoreVendorUnique As Integer
wDoubleWordIO As Integer
wCapabilities As Integer
wReserved1 As Integer
wPIOTiming As Integer
wDMATiming As Integer
wBS As Integer
wNumCurrentCyls As Integer
wNumCurrentHeads As Integer
wNumCurrentSectorsPerTrack As Integer
ulCurrentSectorCapacity As Long
wMultSectorStuff As Integer
ulTotalAddressableSectors As Long
wSingleWordDMA As Integer
wMultiWordDMA As Integer
bReserved(127) As Byte
End Type
'PIdSector = ^TIdSector;
Type DriverStatus
'// Error code from driver, or 0 if no error.
bDriverError As Byte
'// Contents of IDE Error register.
'// Only valid when bDriverError is SMART_IDE_ERROR.
bIDEStatus As Byte
bReserved(1) As Byte
dwReserved(1) As Long
End Type
Type SendCmdOutParams
'// Size of bBuffer in bytes
cBufferSize As Long
'// Driver status structure.
DriverStatus As DriverStatus
'// Buffer of arbitrary length in which to store the data read from the drive.
bBuffer As Byte
End Type

Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Public Type HDDResult
Model As String
Revision As String
Serial As String
End Type
Private Const IDENTIFY_BUFFER_SIZE = 512
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const CREATE_NEW = 1
'Public consts
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const LOGON32_LOGON_INTERACTIVE = 2
Public Const LOGON32_PROVIDER_DEFAULT = 0

Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As SendCmdInParams, ByVal nInBufferSize As Long, ByRef lpOutBuffer As Byte, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As IdSector, ByRef Source As Byte, ByVal Length As Long)
'Public functions
Public Declare Function LogonUser Lib "advapi32" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long
Public Declare Function ImpersonateLoggedOnUser Lib "advapi32" (ByVal hToken As Long) As Long
Public Declare Function RevertToSelf Lib "advapi32.dll" () As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Function WindowsVersion() As Long
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS) 'should be 148
GetVersionEx myOS
'Fill user type with pertinent info
WindowsVersion = myOS.dwPlatformId
End Function
Function ChangeByteOrder(B() As Byte, L As Integer) As String
Dim I As Integer
ChangeByteOrder = ""
For I = 0 To L Step 2
ChangeByteOrder = ChangeByteOrder + Chr(B(I + 1)) + Chr(B(I))
Next I
End Function

Function GetHDDSerial() As HDDResult
Dim t As Long
Dim hDevice As Long, cbBytesReturned As Long, SCIP As SendCmdInParams, aIdOutCmd((20 + IDENTIFY_BUFFER_SIZE - 1) - 1) As Byte 'LenB(SendCmdOutParams)=20

Dim IdOutCmd As IdSector 'absolute aIdOutCmd;
t = (20 + IDENTIFY_BUFFER_SIZE - 1) - 1
If WindowsVersion <> VER_PLATFORM_WIN32_WINDOWS Then
hDevice = CreateFile("\\.\PhysicalDrive0 (file://\\.\PhysicalDrive0)", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
Else
hDevice = CreateFile("\\.\SMARTVSD (file://\\.\SMARTVSD)", 0, 0, 0, CREATE_NEW, 0, 0)
End If

If hDevice = -1 Then Exit Function
cbBytesReturned = 0
' Set up data structures for IDENTIFY command.
With SCIP
.cBufferSize = IDENTIFY_BUFFER_SIZE
With .irDriveRegs
.bSectorCountReg = 1
.bSectorNumberReg = 1
.bDriveHeadReg = &HA0
.bCommandReg = &HEC
End With
End With

'Call device IO control.
If DeviceIoControl(hDevice, &H7C088, SCIP, Len(SCIP), aIdOutCmd(0), t - 1, cbBytesReturned, 0) = 0 Then Exit Function

'Copy buffer to destinition
CopyMemory IdOutCmd, aIdOutCmd(16), LenB(IdOutCmd)
GetHDDSerial.Model = Trim(ChangeByteOrder(IdOutCmd.sModelNumber, 39))
GetHDDSerial.Revision = Trim(ChangeByteOrder(IdOutCmd.sFirmwareRev, 7))
GetHDDSerial.Serial = Trim(ChangeByteOrder(IdOutCmd.sSerialNumber, 19))

CloseHandle hDevice

End Function


بعد توی یه فرم به ای شکل فراخوانی می شه


Private Sub Command1_Click()
Dim tmp As HDDResult
tmp = GetHDDSerial
Text1.Text = tmp.Serial
End Sub

حالا مشکلم اینه که می خوام اونو به دات نت تبدیل کنم اما LENB را ساپرت نمی کنه نمی دونم باید چی کار کنم اگه کسی می تونه این کد رو دات تن تبدیل کنه ممنون می شم
و یا کد شبیه (فقط سریال هارد)

HadiVB
دوشنبه 22 تیر 1388, 21:50 عصر
بابا یکی به داده ما برسه:ناراحت::افسرده::گریه:

samiasoft
دوشنبه 14 فروردین 1396, 15:35 عصر
منم دقیقا همین مشکل رو دارم...به قسمت lenB خطا میگیره