掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ハードウェアの取り外しについて (ID:72448)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
いろいろ調べているうちに、C++で書かれたソースコード 見つけました。VC6 でしたが、VS2008でリコンパイルも 問題なくできました http://www.techtalkz.com/microsoft-device-drivers/250734-remove-usb-device-c-3.html で、APIですが・・・ USBメモリが、単体で1ドライブとして割り付けられたもの では、管理者権限は必要なく、CM_Request_Device_EjectW で、リムーブできます。 逆にセキュアなUSBメモリでは、CD-ROMとリムーバブルに 見える(複数ドライブに割り付けられたもの)では、 CM_Query_And_Remove_SubTreeW で、先頭ドライブを設定 することでリムーブできました。 ※ 上記URLのスースコードを変更してます。 参考コード(修正点) bool IsRemovable = ((DriveType & DRIVE_REMOVABLE) != 0); for ( long tries=1; tries<=3; tries++ ) { // sometimes we need some tries... VetoNameW[0] = 0; // CM_Query_And_Remove_SubTree doesn't work for restricted users //res = CM_Query_And_Remove_SubTreeW(DevInstParent, &VetoType, VetoNameW, MAX_PATH, CM_REMOVE_NO_RESTART); // CM_Query_And_Remove_SubTreeA is not implemented under W2K! //res = CM_Query_And_Remove_SubTreeW(DevInstParent, NULL, NULL, 0, CM_REMOVE_NO_RESTART); // with messagebox (W2K, Vista) or balloon (XP) // res = CM_Request_Device_EjectW(DevInstParent, &VetoType, VetoNameW, MAX_PATH, 0); //res = CM_Request_Device_EjectW(DevInstParent, NULL, NULL, 0, 0); // with messagebox (W2K, Vista) or balloon (XP) if ( IsRemovable ) { res = CM_Request_Device_EjectW(DevInstParent, &VetoType, VetoNameW, MAX_PATH, 0); } else { res = CM_Query_And_Remove_SubTreeW(DevInstParent, &VetoType, VetoNameW, MAX_PATH, CM_REMOVE_NO_RESTART); } bSuccess = (res==CR_SUCCESS && VetoType==PNP_VetoTypeUnknown); if ( bSuccess ) { break; } Sleep(500); // required to give the next tries a chance! } 以上。
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.