'Raw disk access on Windows 8 [duplicate]
I have a problem with raw disk access in Windows. I wrote program in Java, which works with USB flash device, reads its MBR and etc. Device is opened as RandomAccessFile.
If i open NetBeans and execute by program as usual user i have exception
Exception in thread "main" java.io.FileNotFoundException: \\.\PhysicalDrive2 (Отказано в доступе)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:241)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:122)
at main.USBFlashDevice.<init>(Main.java:90)
at main.Main.main(Main.java:196)
Java Result: 1
If i do it as admin, everything is OK.
What can i do to execute program and edit MBR when i work as usual user on somebody's PC?
Solution 1:[1]
What can i do to execute program and edit MBR when i work as usual user on somebody's PC?
You can't.
- Writing to the raw disc device is a potentially dangerous operation. It could effectively trash the file system.
- Even raw disk read access allows you to read files that are denied by normal Windows access control.
It is therefore mandatory that any program that accesses raw disk has admin privilege. The operating system insists on this. Note: this applies to all multi-user operating systems, not just Windows.
You have to run the program with admin privilege. An if you are really asking how to do that ... your question is off topic. Try asking on "superuser.com".
But I should also say that:
Writing this kind of stuff is dangerous and probably a bad idea. Use an existing utility; e.g. one provided by Microsoft or a reputable 3rd-party software provider.
If you (really) need to write this yourself, doing it in Java is probably a poor choice. Most people would use C or C++.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
