将 HDD Serial # VB6 代码转换为 VB.NET 代码

2023-11-21

我从 VC++ 项目中获取了一段很酷的代码,它无需使用 WMI 即可获取硬盘驱动器的完整信息(因为 WMI 有其自身的问题)。

我请求那些熟悉 API 函数的人尝试将这个 VB6 代码转换为 VB.NET(或 C#),并帮助很多非常需要这个实用程序类的人。

我花了很多时间,搜索了整个网络,寻找获得硬盘实际型号和序列号的方法,最终找到了这个,如果它是在.NET中就好了……

这是代码,抱歉它的格式问题,只需将其粘贴到 VB6 IDE 中即可:

Option Explicit

''// Antonio Giuliana, 2001-2003 
''// Costanti per l'individuazione della versione di OS
Private Const VER_PLATFORM_WIN32S = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

''// Costanti per la comunicazione con il driver IDE
Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088

''// Costanti per la CreateFile
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const CREATE_NEW = 1

''// Enumerazione dei comandi per la CmnGetHDData
Private Enum HDINFO
   HD_MODEL_NUMBER
   HD_SERIAL_NUMBER
   HD_FIRMWARE_REVISION
End Enum

''// Struttura per l'individuazione della versione di OS
Private Type OSVERSIONINFO
   dwOSVersionInfoSize As Long
   dwMajorVersion As Long
   dwMinorVersion As Long
   dwBuildNumber As Long
   dwPlatformId As Long
   szCSDVersion As String * 128
End Type

''// Struttura per il campo irDriveRegs della struttura SENDCMDINPARAMS
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

''// Struttura per l'I/O dei comandi al driver IDE
Private Type SENDCMDINPARAMS
    cBufferSize As Long
    irDriveRegs As IDEREGS
    bDriveNumber As Byte
    bReserved(1 To 3) As Byte
    dwReserved(1 To 4) As Long
End Type

''// Struttura per il campo DStatus della struttura SENDCMDOUTPARAMS
Private Type DRIVERSTATUS
    bDriveError As Byte
    bIDEStatus As Byte
    bReserved(1 To 2) As Byte
    dwReserved(1 To 2) As Long
End Type

''// Struttura per l'I/O dei comandi al driver IDE
Private Type SENDCMDOUTPARAMS
    cBufferSize As Long
    DStatus As DRIVERSTATUS     ''// ovvero DriverStatus
    bBuffer(1 To 512) As Byte
End Type

''// Per ottenere la versione del SO
Private Declare Function GetVersionEx _
    Lib "kernel32" Alias "GetVersionExA" _
    (lpVersionInformation As OSVERSIONINFO) As Long

''// Per ottenere un handle al device IDE
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

''// Per chiudere l'handle del device IDE
Private Declare Function CloseHandle _
    Lib "kernel32" _
    (ByVal hObject As Long) As Long

''// Per comunicare con il driver IDE
Private Declare Function DeviceIoControl _
    Lib "kernel32" _
    (ByVal hDevice As Long, _
    ByVal dwIoControlCode As Long, _
    lpInBuffer As Any, _
    ByVal nInBufferSize As Long, _
    lpOutBuffer As Any, _
    ByVal nOutBufferSize As Long, _
    lpBytesReturned As Long, _
    ByVal lpOverlapped As Long) As Long

''// Per azzerare buffer di scambio dati
Private Declare Sub ZeroMemory _
    Lib "kernel32" Alias "RtlZeroMemory" _
    (dest As Any, _
    ByVal numBytes As Long)

''// Per copiare porzioni di memoria
Private Declare Sub CopyMemory _
    Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, _
    Source As Any, _
    ByVal Length As Long)

Private Declare Function GetLastError _
    Lib "kernel32" () As Long

Private mvarCurrentDrive As Byte    ''// Drive corrente
Private mvarPlatform As String      ''// Piattaforma usata

Public Property Get Copyright() As String
    ''// Copyright
    Copyright = "HDSN Vrs. 1.00, (C) Antonio Giuliana, 2001-2003"
End Property

''// Metodo GetModelNumber
Public Function GetModelNumber() As String
       ''// Ottiene il ModelNumber
    GetModelNumber = CmnGetHDData(HD_MODEL_NUMBER)
End Function

''// Metodo GetSerialNumber
Public Function GetSerialNumber() As String
   ''// Ottiene il SerialNumber
    GetSerialNumber = CmnGetHDData(HD_SERIAL_NUMBER)
End Function

''// Metodo GetFirmwareRevision
Public Function GetFirmwareRevision() As String
   ''// Ottiene la FirmwareRevision
    GetFirmwareRevision = CmnGetHDData(HD_FIRMWARE_REVISION)
End Function

''// Proprieta' CurrentDrive
Public Property Let CurrentDrive(ByVal vData As Byte)
    ''// Controllo numero di drive fisico IDE
    If vData < 0 Or vData > 3 Then
        Err.Raise 10000, , "Illegal drive number"   ''// IDE drive 0..3
    End If

    ''// Nuovo drive da considerare
    mvarCurrentDrive = vData
End Property

''// Proprieta' CurrentDrive
Public Property Get CurrentDrive() As Byte
    ''// Restituisce drive fisico corrente (IDE 0..3)
    CurrentDrive = mvarCurrentDrive
End Property

''// Proprieta' Platform
Public Property Get Platform() As String
    ''// Restituisce tipo OS
    Platform = mvarPlatform
End Property

Private Sub Class_Initialize()
    ''// Individuazione del tipo di OS
    Dim OS As OSVERSIONINFO
   
    OS.dwOSVersionInfoSize = Len(OS)
    Call GetVersionEx(OS)
    mvarPlatform = "Unk"

    Select Case OS.dwPlatformId
        Case Is = VER_PLATFORM_WIN32S
            mvarPlatform = "32S"                ''// Win32S
        Case Is = VER_PLATFORM_WIN32_WINDOWS
            If OS.dwMinorVersion = 0 Then
                mvarPlatform = "W95"            ''// Win 95
            Else
                mvarPlatform = "W98"            ''// Win 98
            End If
        Case Is = VER_PLATFORM_WIN32_NT
            mvarPlatform = "WNT"                ''// Win NT/2000
    End Select
End Sub

Private Function CmnGetHDData(hdi As HDINFO) As String

    ''// Rilevazione proprieta' IDE 
    Dim bin As SENDCMDINPARAMS
    Dim bout As SENDCMDOUTPARAMS
    Dim hdh As Long
    Dim br As Long
    Dim ix As Long
    Dim hddfr As Long
    Dim hddln As Long
    Dim s As String

    Select Case hdi             ''// Selezione tipo caratteristica richiesta
        Case HD_MODEL_NUMBER
            hddfr = 55          ''// Posizione nel buffer del ModelNumber
            hddln = 40          ''// Lunghezza nel buffer del ModelNumber
        Case HD_SERIAL_NUMBER
            hddfr = 21          ''// Posizione nel buffer del SerialNumber
            hddln = 20          ''// Lunghezza nel buffer del SerialNumber
        Case HD_FIRMWARE_REVISION
            hddfr = 47          ''// Posizione nel buffer del FirmwareRevision
            hddln = 8           ''// Lunghezza nel buffer del FirmwareRevision
        Case Else
            Err.Raise 10001, "Illegal HD Data type" 
        End Select

        Select Case mvarPlatform
        Case "WNT"
            ''// Per Win NT/2000 apertura handle al drive fisico
            hdh = CreateFile("\\.\PhysicalDrive" & mvarCurrentDrive, _
                GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, _
                0, OPEN_EXISTING, 0, 0)
        Case "W95", "W98"
            ''// Per Win 9X apertura handle al driver SMART
            ''// (in \WINDOWS\SYSTEM da spostare in \WINDOWS\SYSTEM\IOSUBSYS)
            ''// che comunica con il driver IDE
            hdh = CreateFile("\\.\Smartvsd", _
                0, 0, 0, CREATE_NEW, 0, 0)
        Case Else
            ''// Piattaforma non supportata (Win32S)
            Err.Raise 10002, , "Illegal platform (only WNT, W98 or W95)"    
    End Select

    ''// Controllo validità handle
    If hdh = 0 Then
        Err.Raise 10003, , "Error on CreateFile"
    End If

    ''// Azzeramento strutture per l'I/O da driver
    ZeroMemory bin, Len(bin)
    ZeroMemory bout, Len(bout)

    ''// Preparazione parametri struttura di richiesta al driver
    With bin
        .bDriveNumber = mvarCurrentDrive
        .cBufferSize = 512
        With .irDriveRegs
            If (mvarCurrentDrive And 1) Then
                .bDriveHeadReg = &HB0
            Else
                .bDriveHeadReg = &HA0
            End If
            .bCommandReg = &HEC
            .bSectorCountReg = 1
            .bSectorNumberReg = 1
        End With
    End With

    ''// Richiesta al driver
    DeviceIoControl hdh, DFP_RECEIVE_DRIVE_DATA, _
                bin, Len(bin), bout, Len(bout), br, 0

    ''// Formazione stringa di risposta
    ''// da buffer di uscita
    ''// L'ordine dei byte e' invertito
    s = ""
    For ix = hddfr To hddfr + hddln - 1 Step 2
        If bout.bBuffer(ix + 1) = 0 Then Exit For
        s = s & Chr(bout.bBuffer(ix + 1))
        If bout.bBuffer(ix) = 0 Then Exit For
        s = s & Chr(bout.bBuffer(ix))
    Next ix

    ''// Chiusura handle
    CloseHandle hdh

    ''// Restituzione informazione richiesta
    CmnGetHDData = Trim(s)

End Function

我找到了!下面是等效的 VB.NET 代码。它并不完全是 VB6 代码的转换版本,但做了同样的事情。享受!

Public Class HDDInfo
#Region " Declatrations "
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer
<System.Runtime.InteropServices.DllImport("kernel32.dll")> _
Private Shared Function CloseHandle(ByVal hObject As Integer) As Integer
End Function
<System.Runtime.InteropServices.DllImport("kernel32.dll")> _
Private Shared Function DeviceIoControl(ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, <[In](), Out()> ByVal lpInBuffer As SENDCMDINPARAMS, ByVal lpInBufferSize As Integer, <[In](), Out()> ByVal lpOutBuffer As SENDCMDOUTPARAMS, ByVal lpOutBufferSize As Integer, _
 ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Integer
End Function
Private Const FILE_SHARE_READ As Short = &H1
Private Const FILE_SHARE_WRITE As Short = &H2
Private Const GENERIC_READ As Integer = &H80000000
Private Const GENERIC_WRITE As Integer = &H40000000
Private Const OPEN_EXISTING As Short = 3
Private Const CREATE_NEW As Short = 1
Private Const VER_PLATFORM_WIN32_NT As Integer = 2
Private Const DFP_RECEIVE_DRIVE_DATA As Integer = &H7C088
Private Const INVALID_HANDLE_VALUE As Integer = -1
#End Region
#Region " Classes "
<StructLayout(LayoutKind.Sequential, Size:=8)> _
Private Class IDEREGS
    Public Features As Byte
    Public SectorCount As Byte
    Public SectorNumber As Byte
    Public CylinderLow As Byte
    Public CylinderHigh As Byte
    Public DriveHead As Byte
    Public Command As Byte
    Public Reserved As Byte
End Class
<StructLayout(LayoutKind.Sequential, Size:=32)> _
Private Class SENDCMDINPARAMS
    Public BufferSize As Integer
    Public DriveRegs As IDEREGS
    Public DriveNumber As Byte
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> _
    Public Reserved As Byte()
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> _
    Public Reserved2 As Integer()
    Public Sub New()
        DriveRegs = New IDEREGS()
        Reserved = New Byte(2) {}
        Reserved2 = New Integer(3) {}
    End Sub
End Class
<StructLayout(LayoutKind.Sequential, Size:=12)> _
Private Class DRIVERSTATUS
    Public DriveError As Byte
    Public IDEStatus As Byte
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _
    Public Reserved As Byte()
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _
    Public Reserved2 As Integer()
    Public Sub New()
        Reserved = New Byte(1) {}
        Reserved2 = New Integer(1) {}
    End Sub
End Class
<StructLayout(LayoutKind.Sequential)> _
Private Class IDSECTOR
    Public GenConfig As Short
    Public NumberCylinders As Short
    Public Reserved As Short
    Public NumberHeads As Short
    Public BytesPerTrack As Short
    Public BytesPerSector As Short
    Public SectorsPerTrack As Short
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> _
    Public VendorUnique As Short()
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=20)> _
    Public SerialNumber As Char()
    Public BufferClass As Short
    Public BufferSize As Short
    Public ECCSize As Short
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
    Public FirmwareRevision As Char()
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=40)> _
    Public ModelNumber As Char()
    Public MoreVendorUnique As Short
    Public DoubleWordIO As Short
    Public Capabilities As Short
    Public Reserved1 As Short
    Public PIOTiming As Short
    Public DMATiming As Short
    Public BS As Short
    Public NumberCurrentCyls As Short
    Public NumberCurrentHeads As Short
    Public NumberCurrentSectorsPerTrack As Short
    Public CurrentSectorCapacity As Integer
    Public MultipleSectorCapacity As Short
    Public MultipleSectorStuff As Short
    Public TotalAddressableSectors As Integer
    Public SingleWordDMA As Short
    Public MultiWordDMA As Short
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=382)> _
    Public Reserved2 As Byte()
End Class
<StructLayout(LayoutKind.Sequential)> _
Private Class SENDCMDOUTPARAMS
    Public BufferSize As Integer
    Public Status As DRIVERSTATUS
    Public IDS As IDSECTOR
    Public Sub New()
        Status = New DRIVERSTATUS()
        IDS = New IDSECTOR()
    End Sub
End Class
#End Region
#Region " Methods and Functions "
Private Shared Function SwapChars(ByVal chars As Char()) As String
    For i As Integer = 0 To chars.Length - 2 Step 2
        Dim t As Char
        t = chars(i)
        chars(i) = chars(i + 1)
        chars(i + 1) = t
    Next
    Dim s As New String(chars)
    Return s
End Function
Public Shared Function GetHDDInfoString() As String
    Dim serialNumber As String = " ", model As String = " ", firmware As String = " "
    Dim handle As Integer, returnSize As Integer = 0
    Dim driveNumber As Integer = 0
    Dim sci As New SENDCMDINPARAMS()
    Dim sco As New SENDCMDOUTPARAMS()

    If Environment.OSVersion.Platform = PlatformID.Win32NT Then
        handle = CreateFile("\\.\PhysicalDrive" & "0", GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
    Else
        handle = CreateFile("\\.\Smartvsd", 0, 0, 0, CREATE_NEW, 0, 0)
    End If
    If handle <> INVALID_HANDLE_VALUE Then
        sci.DriveNumber = CByte(driveNumber)
        sci.BufferSize = Marshal.SizeOf(sco)
        sci.DriveRegs.DriveHead = CByte((&HA0 Or driveNumber << 4))
        sci.DriveRegs.Command = &HEC
        sci.DriveRegs.SectorCount = 1
        sci.DriveRegs.SectorNumber = 1
        If DeviceIoControl(handle, DFP_RECEIVE_DRIVE_DATA, sci, Marshal.SizeOf(sci), sco, Marshal.SizeOf(sco), _
         returnSize, 0) <> 0 Then
            serialNumber = SwapChars(sco.IDS.SerialNumber)
            model = SwapChars(sco.IDS.ModelNumber)
            firmware = SwapChars(sco.IDS.FirmwareRevision)
        End If
        CloseHandle(handle)
    End If
    Return model.Trim & " " & serialNumber.Trim
End Function
#End Region
End Class
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 HDD Serial # VB6 代码转换为 VB.NET 代码 的相关文章

  • String.Format - 它如何工作以及如何实现自定义格式字符串

    With String Format 例如可以格式化DateTime对象以许多不同的方式 每次我寻找所需的格式时 我都需要在互联网上搜索 我几乎总能找到一个可以使用的例子 例如 String Format 0 MM dd yyyy Date
  • 从 VB.NET 应用程序填写 PDF 表单

    我的任务是在 VB Net 中创建一个 Windows 应用程序 要求之一是从 MSSQL 数据库读取数据 并将某些值放入 PDF 表单中 如何使用 VB Net 将数据放入预先存在的 PDF 文件中 另外 是否可以将PDF文件作为资源放入
  • 检查 listbox1 中是否已存在某个项目

    在 form1 中 我有两个列表框 listbox1 listbox2 加载按钮和保存按钮 此代码会将 listbox1 selecteditem 写入 txt 文件 然后 loadbutton 将加载信息 但在 listbox2 中我希望
  • 运行 SomeActiveX.Exe /regserver 的 API 等效项

    我需要以编程方式注册 ActiveX exe 而 Shell SomeActiveX Exe regserver 是不够的 有人知道等效的 API 吗 您可以使用DLL注册服务器 http msdn microsoft com en us
  • windows XP中如何设置默认编码?

    我尝试使用 StreamReader 打开文件并设置编码 但我希望它采用默认 Windows 编码 我如何更改我的 Windows 编码 区域和语言选项控制面板项目 高级选项卡 影响整个计算机
  • WPF DataGrid 排序后滚动到顶部

    我有一个使用数据网格的 Net 4 0 WPF 应用程序 目前 按列排序后 网格的滚动位置保持在排序前的位置 对于此应用程序 我需要在任何排序后滚动到网格顶部 我尝试过像这样处理排序事件 Private Sub myDataGrid Sor
  • NASM:如何正确访问SSD驱动器?

    我需要使用 NASM 16 位代码访问 SSD 驱动器 访问普通硬盘时 需要设置寄存器AX DX CX来选择柱面 磁道 扇区 扇区数 AH 选择读扇区功能 DL 选择驱动器号 CH 选择气缸 DH 选择磁盘上的一侧 CL 选择步入正轨的部门
  • VB.net 应用程序保留以前的版本

    我有一个正在发布的 Visual Basic 项目 并且每次都会增加版本号 当我安装新版本时 它会打开 但一旦应用程序重新启动 它似乎就会恢复到以前的版本 我不知道为什么 尝试更新发布应用程序时所需的最低版本 转到应用程序属性 gt 发布
  • 回发 Asp.Net 上的动态用户控件

    我创建了一个项目 user control 它有一个文本框 按钮等 它将有意收集用户想要的项目总数 我在 page load 上动态创建了几个 user control 实例 如果您单击项目数量的添加按钮 它将添加到会话变量中 但是 当用户
  • 从 RichTextBox 复制文本及其格式

    如何将 RichTextBox 中的文本及其格式复制到写字板或网络浏览器 就像复制纯文本一样 您可以使用Clipboard SetText method http msdn microsoft com en us library 6eahs
  • 计算文本框中换行的行数

    我在文本框中有一行文本 并且换行为多行 如何计算文本框中换行的行数 你可以使用String Split int lineCount txt Text Split new n r StringSplitOptions None Length
  • 使用 VB.NET 覆盖文本文件中的特定行

    我需要执行以下操作 更改文本文件中的行 Path c this certain path 用这条线 Path c that other newer path 这些路径的长度肯定会不同 因此我需要替换引号中的内容 或者完全擦除该行并输入一个新
  • 如何在自定义用户控件(.Net 4、Winforms)上使用项目集合编辑器?

    我创建了一个UserControl其中包含一个自定义ToolStrip Control 在使用时UserControl在整个应用程序中 ToolStrip控件不能直接访问 因为它逻辑上嵌入在UserControl 因此 要访问的项目Tool
  • 如果图像包含特定颜色则

    是否有一种简单的方法来检查图像是否包含特定的 RGB 颜色 例如 Dim img As Image Image FromFile C image png If img contains color red toRGB then 我认为检查这
  • 将 System.Array 从 .Net 编组到 vb6

    我有一个 Net 组件 它有一个 COM 可见类 该类具有返回 System Array 的方法 它实际上返回一个字符串数组 但返回类型声明为 System Array 不要问我 为什么 我知道我可以将返回类型声明为 string 这样就可
  • Gridview 错误:对 Bind 的调用格式不正确

    我有以下 gridview 代码
  • 读取 .ini 文件 vb.net?

    我有一个具有读取 ini 文件功能的项目 我无法显示我想要的 ini 文件的内容 我的代码读取 ini 文件 Public Function GetSettingItem ByVal File As String ByVal Identif
  • 运行命令行进程并在该进程仍在运行时获取输出?

    如何运行命令行进程并在该进程仍在运行时获取输出 我的意思是使用自己的进度条运行 CLI 进程 可执行文件本身需要很长时间才能完成操作 所以我想从自己的进程中获取进度信息来显示我的应用程序中的进度 否则我不这样做在进程完成之前没有任何信息来显
  • 如何使用 Regsvr32 注册 .NET COM DLL?

    我有一个使用 COM DLL 的 VB6 应用程序 该DLL是用C 编写的 在 C 项目属性中 我检查了 Register for COM interop 选项 VB6 应用程序在我的开发机器上运行良好 C 代码完全遵循以下格式 CodeP
  • 管理软件的演示版本[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我有一个用VB6编写的软件产品 它是一个付费软件产品 有1个月的演示版本 演示版本没有单独的安装文件 输入产品密钥后 软件会将演示版本

随机推荐

  • android EditText,键盘textWatcher问题

    我正在开发一个 Android 应用程序 我有一个 EditText 用户可以在其中输入数字 我想使用不同的货币格式 例如 来格式化数字 并且我想即时执行此操作 即当用户输入每个数字时 而不是按下回车键时 我用谷歌搜索了一下 发现文本观察器
  • Oracle XE 11.2 中 PostgreSQL 的 array_agg 的等效项[重复]

    这个问题在这里已经有答案了 我有一个 Oracle 11g XE 数据库 我有一个查询结果集 ID Category 1 Cat1 1 Cat2 2 Cat3 2 Cat4 我想获得与所有相关类别在同一行中的不同 id 以逗号分隔 如下所示
  • 如何使用 Doctrine 2 中的 QueryBuilder 创建带有 SELECT 子查询的 LEFT JOIN?

    我需要限制 LEFT JOIN 结果 所以我必须使用子查询 有人可以给我一些建议 我该如何使用 Doctrine 2 来做到这一点吗 我现在拥有的是 qb this gt em gt createQueryBuilder return qb
  • 有什么方法可以防止损坏角度组件吗?

    我们知道 Angular 中有一个方法 ngOnDestroy 它在销毁组件时运行 但我想知道有什么方法可以防止它被销毁吗 The 可以停用Guard 可以访问活动组件的实例 因此您可以实现已更改 检查是否有更改 并在离开前有条件地要求用户
  • Django:如何向表单上的输入字段添加任意 html 属性?

    我有一个使用模板呈现的输入字段 如下所示 div class field form city div 其呈现为 div class field div
  • PHP:在本地主机中发送邮件

    我想通过本地托管的 php 代码发送电子邮件 当我运行此代码时 出现以下错误 Warning mail a href function mail function mail a Failed to connect to mailserver
  • PostgreSQL:如何优化数据库以存储和查询巨大的图表

    我在配备 1GB RAM 和 Mac OS X 10 5 8 的 1 83 GHz Intel Core Duo Mac Mini 上运行 PostgreSQL 8 3 我的 PostgreSQL 数据库中存储了一个巨大的图表 它由 160
  • 如何解决 python 中的未来警告 -> % (min_groups, self.n_splits)), warning) ?

    当我在程序中运行mean acc 方法时 出现 min groups self n splits 警告 错误 def mean acc models RandomForestClassifier n estimators 200 max d
  • 相机 ISO 设置/快门速度

    我正在寻找一种方法来改变我的 Evo 4G 相机的感光度 我知道这不是相机的快门速度 因为它是数码相机 下一个最相关的方面是 ISO 设置 但 Android SDK 没有办法操作它 有人知道另一种选择吗 即场景模式 曝光或效果 param
  • 如何将UTF8字符串转换为字节数组?

    The charCodeAt函数返回字符的 unicode 代码 但我想获取字节数组 我知道 如果字符码超过 127 则该字符存储在两个或更多字节中 var arr for var i 0 i
  • 为什么 VBA 中的每个类都有一个 Application 属性?

    我想澄清一下为什么每堂课 或几乎每个班级 在 VBA 中 当您滚动浏览对象浏览器时 有一个Application财产 MSDN 说 当不带对象限定符使用时 此属性返回一个 代表 Microsoft Excel 应用程序的应用程序对象 当与对
  • url重写后如何知道原来的url?

    我有 url 重写规则 将 www domain2 com 重定向到 domain1 com 根目录下的子文件夹 我们将此文件夹称为子项目 在我的控制器中 我需要构造一个指向原始未修改路径的 URL 但 Request Url 属性 如 A
  • 如何回滚特定迁移?

    我有迁移文件 db migrate 20100905201547 create blocks rb 我如何具体回滚该迁移文件 rake db rollback STEP 1 如果您要回滚的迁移是最后应用的迁移 这是一种执行此操作的方法 您可
  • 在不同端口上启动瘦服务器

    我是个新手哦 我有一个 ruby on Rails 应用程序 今天我可以通过命令正常启动应用程序 sudo thin start d 我们创建了一个新的测试数据库 一个是干净的数据库 另一个用于测试 因此可能会弄乱 在database ym
  • 使用seaborn clustermap提取层次聚类中的簇行

    我正在使用seaborn clustermap 中的分层聚类来对我的数据进行聚类 这可以很好地可视化热图中的集群 但是 现在我想提取分配给不同集群的所有行值 这是我的数据的样子 import pandas as pd load DataFr
  • 有没有比 fread() 更快的方法来读取大数据?

    嗨 首先我已经在堆栈和谷歌上搜索并找到了这样的帖子 快速读取非常大的表作为数据框 虽然这些很有帮助并且得到了很好的回答 但我正在寻找更多信息 我正在寻找读取 导入高达 50 60GB 的 大 数据的最佳方法 我目前正在使用fread 函数来
  • Qt如何更改特定QComboBox项目的突出显示颜色

    我正在尝试使 QComboBox 的突出显示透明 此 QComboBox 的颜色也会根据所选索引而变化 这是迄今为止我最好的解决方案 switch comboBox gt currentIndex case 0 comboBox gt se
  • 将两个内联块左右对齐在同一行上

    如何对齐两个内联块 使一个位于左侧 另一个位于同一行的右侧 为什么这么难 有没有像 LaTeX 的 hfill 这样的东西可以消耗它们之间的空间来实现这一点 我不想使用浮动因为使用内联块我可以排列基线 当窗口对于它们两个来说都太小时 使用内
  • 没有这样的文件来加载 Rails 3 的捆绑程序错误

    我有一个 Rails 3 应用程序可供部署 我还没有设置 VPS 主机 因为我计划在前几个月将所有内容都放在共享主机上 Problem cd myapp 捆绑检查 结果 The Gemfile s dependencies are sati
  • 将 HDD Serial # VB6 代码转换为 VB.NET 代码

    我从 VC 项目中获取了一段很酷的代码 它无需使用 WMI 即可获取硬盘驱动器的完整信息 因为 WMI 有其自身的问题 我请求那些熟悉 API 函数的人尝试将这个 VB6 代码转换为 VB NET 或 C 并帮助很多非常需要这个实用程序类的