Почему приведенный ниже код не работает на Windows2003-server? Код взял из примера с VBNet, в описании сказано, что работает только на XP и Win2000, но почему, и как это поправить?
Option Explicit
Private Declare Sub MemCpy Lib "KERNEL32" Alias "RtlMoveMemory" (ByVal hpvDest As Any, ByVal hpvSource As Any, ByVal cbCopy 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 CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl Lib "KERNEL32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, ByVal lpInBuffer As Long, ByVal nInBufferSize As Long, ByVal lpOutBuffer As Long, ByVal nOutBufferSize As Long, ByRef lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
Private Type SrbIoControl
HeaderLength As Long
Signature(7) As Byte
Timeout As Long
ControlCode As Long
ReturnCode As Long
Length As Long
End Type
Private Type IDERegs
bFeaturesReg As Byte
bSectorCountReg As Byte
bSectorNumberReg As Byte
bCylLowReg As Byte
bCylHighReg As Byte
bDriveHeadReg As Byte
bCommandReg As Byte
bReserved As Byte
End Type
Private Type SendCmdInParams
cBufferSize As Long
irDriveRegs As IDERegs
bDriveNumber As Byte
bReserved(2) As Byte
dwReserved(3) As Long
bBuffer(0) As Byte
End Type
Dim Buffer() As Byte
Dim buffin() As Byte
Dim buffout() As Byte
Private Sub Command1_Click()
Dim DataSize As Integer
Dim BufferSize As Integer
Dim srbControl As SrbIoControl
Dim SendCmdInParams As SendCmdInParams
Dim hDevice As Long
Dim cbBytesReturned As Long
Dim retval As Long
hDevice = CreateFile("\\.\PhysicalDrive0", &H40000000 Or &H80000000, &H1 Or &H2, 0, 3, 0, 0)
If hDevice = -1 Then End
DataSize = Len(SendCmdInParams) - 1 + 512
BufferSize = Len(srbControl) + DataSize
ReDim Buffer(BufferSize - 1)
srbControl.HeaderLength = Len(srbControl)
MemCpy VarPtr(srbControl.Signature(0)), "SCSIDISK", 8
srbControl.Timeout = 2
srbControl.ControlCode = &H1B0501
srbControl.Length = DataSize
With SendCmdInParams
.cBufferSize = 512
.bDriveNumber = 0
With .irDriveRegs
.bFeaturesReg = 0
.bSectorCountReg = 1
.bSectorNumberReg = 1
.bCylLowReg = 0
.bCylHighReg = 0
.bDriveHeadReg = &HA0 Or ((0 And 1) * 8 ^ 4)
.bCommandReg = &HEC
End With
End With
MemCpy VarPtr(Buffer(0)), VarPtr(srbControl.HeaderLength), Len(srbControl)
MemCpy VarPtr(Buffer(Len(srbControl))), VarPtr(SendCmdInParams.cBufferSize), _
Len(SendCmdInParams)
retval = DeviceIoControl(hDevice, &H4D008, VarPtr(Buffer(0)), BufferSize, _
VarPtr(Buffer(0)), BufferSize, cbBytesReturned, 0)
'вот здесь вызов ф-ии возвращает 0, почему?
If retval = 0 Then End
CloseHandle (hDevice)
MsgBox "S/N - " & GetInfo(64, 20)
End Sub
Private Function GetInfo(offset As Integer, leninfo As Integer) As String
Dim str As String
ReDim buffin(leninfo - 1)
MemCpy VarPtr(buffin(0)), VarPtr(Buffer(offset)), UBound(buffin) + 1
ReverseOrderByte buffin, buffout
str = String(UBound(buffin) + 1, " ")
MemCpy str, VarPtr(buffout(0)), UBound(buffin) + 1
str = LTrim(str)
str = RTrim(str)
GetInfo = str
End Function
Private Function ReverseOrderByte(buffin() As Byte, buffout() As Byte)
Dim i As Integer
Dim bufflen As Integer
bufflen = UBound(buffin) + 1
ReDim buffout(bufflen - 1)
For i = 0 To (bufflen) - 1 Step 2
buffout(i) = buffin(i + 1)
buffout(i + 1) = buffin(i)
Next
End Function
Ответить
|