急需《在Win2000下弹出U盘的代码》,高分等待 1、在程序中,通过按钮直接把U盘弹出来。 2、获取系统中的所有U盘盘符(已实现,不过如果有更好的代码,请贴上来)

解决方案 »

  1.   

    http://www.book23.com/data/web5304/20050228/20050228__3530331.html
    我copy人家的代碼給你:絕對可用的,100% Delphi代碼!! 
    http://www.yeahware.com/download/eject.zip 
    選擇Show hidden device後在USB Mass Storage Device處就是Eject了!!! 關鍵代碼 function CM_Get_DevNode_Status(pulStatus: PULong; pulProblemNumber: PULong; 
    dnDevInst: DWord; ulFlags: ULong): DWord; stdcall; 
    external CfgMgr32ModuleName name 'CM_Get_DevNode_Status'; function CM_Request_Device_Eject(dnDevInst: DWord; out pVetoType: TPNPVetoType; 
    pszVetoName: PChar; ulNameLength: ULong; ulFlags: ULong): DWord; stdcall; 
    external SetupApiModuleName name 'CM_Request_Device_EjectA'; 
    if (CM_Get_DevNode_Status(@Status, @Problem, DeviceInfoData.DevInst, 0) <> CR_SUCCESS) then 
    begin 
    exit; 
    end; 
    VetoName[0] := #0; 
    case CM_Request_Device_Eject(DeviceInfoData.DevInst, VetoType, @VetoName, SizeOf(VetoName), 0) of 
    CR_SUCCESS: 
    begin 
    MessageBox(Handle, PChar(’Eject OK (Veto: ' + VetoName + ')'), 'Vetoed', MB_OK); end; 
    CR_REMOVE_VETOED: 
    begin 
    MessageBox(Handle, PChar('Failed to eject the Device (Veto: ' + VetoName + ')'), 'Vetoed', MB_OK); 
    end; 
    else 
    begin 
    MessageBox(Handle, PChar('Failed to eject the Device (' + SysErrorMessage(GetLastError) + ')'), 'Failure', MB_OK); 
    end; 
    end; 那個Eject原代碼是有Bug的,修正如下 添加 
    function TForm1.GetDevInfo(var hDevInfo: hDevInfo): boolean; 
    begin 
    // Get a handle to all devices in all classes present on system 
    hDevInfo := SetupDiGetClassDevs(nil, nil, 0, DIGCF_PRESENT or DIGCF_ALLCLASSES); 
    Result := hDevInfo <> Pointer(INVALID_HANDLE_VALUE); 
    end; 調用為: 
    procedure TForm1.FormCreate(Sender: TObject); 
    begin 
    if (not LoadSetupAPI) then 
    begin 
    ShowMessage('Could not load SetupAPI.dll'); 
    exit; 
    end; 
    DevInfo := nil; 
    ShowHidden := false; 
    // Get a handle to all devices in all classes present on system 
    if not GetDevInfo(DevInfo) then 
    begin 
    ShowMessage('GetClassDevs'); 
    exit; 
    end; 
    // Get the Images for all classes, and bind to the TreeView 
    ClassImageListData.cbSize := SizeOf(TSPClassImageListData); 
    if (not SetupDiGetClassImageList(ClassImageListData)) then 
    begin 
    ShowMessage('GetClassImageList'); 
    exit; 
    end; 
    ImageList.Handle := ClassImageListData.ImageList; 
    TreeView.Images := ImageList; 
    // Add the devices to the TreeView window. 
    EnumAddDevices(ShowHidden, TreeView, DevInfo); 
    end; procedure TForm1.mRefreshDisplayClick(Sender: TObject); 
    begin 
    if not GetDevInfo(DevInfo) then 
    begin 
    ShowMessage('GetClassDevs'); 
    exit; 
    end; 
    EnumAddDevices(ShowHidden, TreeView, DevInfo); 
    end; case CM_Request_Device_Eject(DeviceInfoData.DevInst, VetoType, @VetoName, SizeOf(VetoName), 0) of 
    CR_SUCCESS: 
    begin 
    MessageBox(Handle, 'Successful to eject the Device', 'Done', MB_OK); 
    if not GetDevInfo(DevInfo) then 
    begin 
    ShowMessage('GetClassDevs'); 
    exit; 
    end; 
    EnumAddDevices(ShowHidden, TreeView, DevInfo); 
    end;
      

  2.   

    链接无效了,能不能发到我的油箱里啊?谢谢了
    [email protected]
      

  3.   

    我一年多前写的东西,给转贴了好几次,然后没人记得我了
    郁闷的原来的连接,FAQ中的(估计你都没看FAQ的,汗~)http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=197585
    \http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=200977