使用Windows系统编程可以实现,呵呵这个是很容易的下次写个程序。你只要在任意驱动器上点击右键,里面会有一项“关闭光驱”呵呵,点击后,光驱即可关闭。

解决方案 »

  1.   

    mcisendstring "set CDAudio door open"
      

  2.   

    对,就用mcisendstring,将open换成close就可以关闭光驱。
      

  3.   

    Private Const MCI_OPEN = &H803
    Private Const MCI_OPEN_TYPE = &H2000&
    Private Const MCI_OPEN_SHAREABLE = &H100&
    Private Const MCI_SET = &H80D
    Private Const MCI_SET_DOOR_OPEN = &H100&
    Private Const MCI_CLOSE = &H804
    Private Type MCI_OPEN_PARMS
        dwCallback As Long
        wDeviceID As Long
        lpstrDeviceType As String
        lpstrElementName As String
        lpstrAlias As String
    End Type
    Private Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Long, ByVal uMessage As Long, ByVal dwParam1 As Long, ByRef dwParam2 As Any) As Long
    Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    Dim openParams As MCI_OPEN_PARMS
    Private Sub Form_Load()
        'KPD-Team 2001
        'URL: http://www.allapi.net/
        '[email protected]
        Dim lRet As Long
        'initialize the structure
        openParams.wDeviceID = 0
        openParams.lpstrDeviceType = "cdaudio"
        'get the device ID
        lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
        'check for error
        If lRet <> 0 Then
            'show error
            MsgBox GetMCIErrorString(lRet), vbCritical
        Else
            'open the door of the CD-ROM drive
            lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
            'check for errors
            If lRet <> 0 Then MsgBox GetMCIErrorString(lRet), vbCritical
        End If
        'clean up
        mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0&
    End Sub
    Private Function GetMCIErrorString(lErr As Long) As String
        'create a buffer
        GetMCIErrorString = Space$(255)
        'retrieve the error string
        mciGetErrorString lErr, GetMCIErrorString, Len(GetMCIErrorString)
        'strip off the trailing spaces
        GetMCIErrorString = Trim$(GetMCIErrorString)
    End Function
      

  4.   

    Option ExplicitPrivate Const MCI_OPEN = &H803
    Private Const MCI_OPEN_TYPE = &H2000&
    Private Const MCI_OPEN_SHAREABLE = &H100&
    Private Const MCI_SET = &H80D
    Private Const MCI_SET_DOOR_OPEN = &H100&
    Private Const MCI_CLOSE = &H804'×&Ocirc;&para;¨&Ograve;&aring;&Agrave;à&ETH;&Iacute;   MCI_OPEN_PARMS
    Private Type MCI_OPEN_PARMS
            dwCallback  As Long
            wDeviceID  As Long
            lpstrDeviceType  As String
            lpstrElementName  As String
            lpstrAlias  As String
    End Type
    Private Declare Function mciSendCommand Lib "winmm.dll" _
                                              Alias "mciSendCommandA" (ByVal wDeviceID As Long, _
                                                                       ByVal uMessage As Long, _
                                                                       ByVal dwParam1 As Long, _
                                                                       ByRef dwParam2 As Any) As Long
    Private Declare Function mciGetErrorString Lib "winmm.dll" _
                                      Alias "mciGetErrorStringA" (ByVal dwError As Long, _
                                                                  ByVal lpstrBuffer As String, _
                                                                  ByVal uLength As Long) As Long'Private Declare Function GetmciErrorString Lib "winmm.dll" _
    '                                  Alias "GetmciErrorStringA" (ByVal llRet As Long) As Long
    Dim openParams   As MCI_OPEN_PARMSPrivate Sub Command1_Click()
        'KPD-Team  2001
            'URL:  http://www.allapi.net/
            '[email protected]
            Dim lRet   As Long
            'initialize  the  structure
            openParams.wDeviceID = 0
            openParams.lpstrDeviceType = "cdaudio"
            'get  the  device  ID
            lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
            'check  for  error
            If lRet <> 0 Then
                    'show  error
                    MsgBox GetmciErrorString(lRet), vbCritical
            Else
                    'open  the  door  of  the  CD-ROM  drive
                    lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
                    'check  for  errors
                    If lRet <> 0 Then MsgBox GetmciErrorString(lRet), vbCritical
            End If
            'clean  up
            mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0&
    End Sub
      

  5.   

    我可能没说明白,我会用API控制光驱的开关,我的意思是如何在右击光驱盘符
    出现一个自定义的选项,比如关闭光驱。
      

  6.   

    我可能没说明白,我会用API控制光驱的开关,我的意思是如何在右击光驱盘符
    出现一个自定义的选项,比如关闭光驱。是不是要通过修改注册表
      

  7.   

    我可能没说明白,我会用API控制光驱的开关,我的意思是如何在右击光驱盘符
    出现一个自定义的选项,比如关闭光驱。是不是要通过修改注册表
      

  8.   

    要把“关闭光驱”项加入到资源管理器的弹出菜单中,实现起来相当困难,关系到外壳编程的知识。
    但是,你也可以通过修改注册表来实现类似的效果,不过这样会使在任何驱动器的右键菜单中都出现这个项,方法如下:
    在驱动器及系统文件图标上的弹出菜单: 运行regedit.exe,打开HKEY_CLASSES_ROOT\Folder\shell 如要删除一条,选择其下的一条主键,按Del删除。如要增加,在shell子键上按右键,选择新建主键,在其默认项内设置其标题, 然后在你新建的主键下再新建一条名为command的主键,在其默认项内设置你要运行的程序的完整路径。
    既然全部要在VB代码中实现,因此应当使用写注册表的API来进行此修改,同时,编译这个VB程序为可执行文件,一运行就mcisendstring "set cdaudio door closed",0&,0&,0&.即可。
      

  9.   

    mcisendstring "set CDAudio door open"
    mcisendstring "set CDAudio door close"