0

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?

everton
  • 7,579
  • 2
  • 29
  • 42
Alex
  • 91
  • 1
  • 8

1 Answers1

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++.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216