注册 登录
编程论坛 VB.NET论坛

(已经解决)敬请各位高手解决vb.net(vs2010)如何使用现成的代码问题。谢谢。

HVB6 发布于 2017-06-25 20:03, 3035 次点击
以下代码是打开(vs2010)→新建项目→双击新建按钮:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class
以下代码是网上的:(问题:如何把以下的代码放入以上的代码中使用?谢谢。)
Imports System.Management
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim disk As ManagementBaseObject , strResult As String
    Dim diskClass = New ManagementClass("Win32_LogicalDisk") , disks As ManagementObjectCollection
    disks = diskClass.GetInstances()
  For Each disk In disks
     strResult = ""
     strResult += "磁盘名称:" & disk("Name") & vbCrLf
     strResult += "磁盘卷标:" & disk("VolumeName") & vbCrLf
      MsgBox(strResult)
  Next
End Sub



[此贴子已经被作者于2017-6-27 10:25编辑过]

6 回复
#2
shsmhq2017-06-26 10:44
'连抄你都不会,以下代码是抄完的结果。


'先命名空间,需要在项目里面先添加引用System.Management
Imports System.Management

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'点击代码内贴代码
        Dim disk As ManagementBaseObject, strResult As String
        Dim diskClass = New ManagementClass("Win32_LogicalDisk"), disks As ManagementObjectCollection
        disks = diskClass.GetInstances()
        For Each disk In disks
            strResult = ""
            strResult += "磁盘名称:" & disk("Name") & vbCrLf
            strResult += "磁盘卷标:" & disk("VolumeName") & vbCrLf
            MsgBox(strResult)
        Next
    End Sub
End Class

[此贴子已经被作者于2017-6-26 12:18编辑过]

#3
HVB62017-06-26 10:50
回复 2楼 shsmhq
运行不了,请您试试。谢谢。
#4
shsmhq2017-06-26 12:19
回复 3楼 HVB6
需要先在项目==添加引用,System.Management
#5
HVB62017-06-26 16:53
回复 4楼 shsmhq
木有,请给个截图。谢谢。
#6
shsmhq2017-06-27 08:37
以下是引用HVB6在2017-6-26 16:53:37的发言:

木有,请给个截图。谢谢。



请看下图:
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
#7
lalawo2017-07-06 11:00
哈哈,这是一步一步都教
1