« 不都合な真実 | Main | バンテージ・ポイント »

March 06, 2008

Windows Vistaでデバイスアクセス

例えば、Windows VistaでUSB接続されたハードディスクにアクセスするアプリケーションを作成する場合、Visual C++ではCreateFile()を使用しデバイスのハンドルを取得しようとして失敗する場合があります。(というか、私は失敗しました)
で、原因の一つとして有力なのがUAC(User Account Control)と呼ばれるセキュリティ機能でしょう。通常はUACが有効であり、Adminアカウントでログオンしているだけではデバイスへのアクセス権が与えられないようです。
そこで、UACを無効にします。「ユーザーアカウント制御の有効化または無効化」から「ユーザーアカウント制御の有効化または無効化」のチェックを外しPCを再起動すればOK。
これでUSB接続したハードディスクのハンドルを取得出来るようになります。

次に、論理と物理の問題があります。CreateFileの第一引数であるlpFileNameですね。論理とは「¥¥.¥C」で物理とは「PHYSICALDRIVE0」を渡します。ココで、第二引数である dwDesiredAccess と第三引数 dwShareMode の設定がいい加減だと、物理でのハンドル取得に失敗したり、ディスクへのWriteコマンドエラーの原因となります。

CreateFile(lpFileName = \\\\.\\PhysicalDrive0
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE
lpSecurityAttributes = NULL
dwCreationDisposition = OPEN_EXISTING
dwFlagsAndAttributes = NULL
hTemplateFile = NULL );

ですね。

あとはDeviceIoControl()にハンドルやら何やらを渡してあげて、エラー処理を作ってあげれば何とかなりそうな気がしますね。ってか動いてますが...。(Λ。Λ)

|

« 不都合な真実 | Main | バンテージ・ポイント »

Comments

Hey there just wanted to give you a brief heads up and let you know a few of the images aren't loading properly. I'm not sure why but I think its a linking issue. I've tried it in two different browsers and both show the same results.

Posted by: Eternity Warriors 3 hack | November 10, 2014 at 11:28 PM

Usually I don't read post on blogs, however I wish to say that this write-up very compelled me to try and do it! Your writing taste has been surprised me. Thanks, quite nice post.

Posted by: fix my iphone calgary | March 07, 2015 at 05:14 PM

Excellent blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol

Posted by: frontline commando ww2 mod | April 30, 2015 at 04:57 PM

Thanks in favor of sharing such a good idea, article is pleasant, thats why i have read it entirely

Posted by: Lester | May 10, 2015 at 09:47 PM

My brother recommended I might like this web site. He was totally right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks!

Posted by: celebritymaxhealth.com | May 11, 2015 at 11:44 AM

I'll immediately grasp your rss feed as I can't in finding your e-mail subscription hyperlink or newsletter service. Do you have any? Please permit me understand so that I could subscribe. Thanks.

Posted by: bomb me hack | May 11, 2015 at 11:07 PM

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?

Posted by: east legend hacker | May 12, 2015 at 03:15 AM

Very nice post. I simply stumbled upon your blog and wished to say that I have really loved surfing around your weblog posts. After all I will be subscribing on your feed and I'm hoping you write again very soon!

Posted by: Myles | May 16, 2015 at 01:39 AM

Hurrah, that's what I was looking for, what a information! present here at this blog, thanks admin of this web site.

Posted by: Pansy | May 16, 2015 at 02:18 AM

Hi there! I know this is kinda off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having trouble finding one? Thanks a lot!

Posted by: Collette | May 19, 2015 at 05:32 AM

Whether you're a die hard poker fan, or just enjoy playing a bit of Hold'em every now and then; you will enjoy this free poker game for your mobile phone where you are introduced to seven different poker styles. ' Very few platforms give the developers as much opportunity to exercise his or her creativity like Android does. Of course, there are also the games and graphics and those may be one of the big selling points of Windows Phone 7.

Posted by: gang nations hack tool | May 21, 2015 at 05:12 AM

Thousands of liver active enzymes are found in the algae which is good for food absorption.

Posted by: kik hacker real | July 29, 2015 at 07:30 PM

Greetings from California! I'm bored at work so I decided to browse your site on my iphone during lunch break. I really like the knowledge you provide here and can't wait to take a look when I get home. I'm surprised at how fast your blog loaded on my cell phone .. I'm not even using WIFI, just 3G .. Anyhow, fantastic site!

Posted by: http://Kisdpodcast.Killeenisd.Org/ | August 19, 2015 at 12:20 AM

Post a comment



(Not displayed with comment.)




TrackBack

TrackBack URL for this entry:
http://app.cocolog-nifty.com/t/trackback/80479/40308594

Listed below are links to weblogs that reference Windows Vistaでデバイスアクセス:

« 不都合な真実 | Main | バンテージ・ポイント »