File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes General Computing and the fly likes Get PhysicalDrive name from logical windows name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Get PhysicalDrive name from logical windows name?" Watch "Get PhysicalDrive name from logical windows name?" New topic
Author

Get PhysicalDrive name from logical windows name?

peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
Hi Ranchers

Is it possible to get the PhysicalDrive name of a disk from the windows drive naming convention? i.e i want to find what PhysicalDriveX that d:volume is on??

i want to pass a command to grubInst.exe from my java app but grubinist only works with physical disks..... and i really don't want to add a bootloader to the wrong disk...

any pointers?

many thanks

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1021
    
    5

Hi Peter

I think the following method in the FileSystemView class may be what you need: getSystemDisplayName

An example of its use would be:
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7795
    
  21

peter hammond wrote:i want to pass a command to grubInst.exe from my java app but grubinist only works with physical disks..... and i really don't want to add a bootloader to the wrong disk...
any pointers?

Yes: Why are you doing this from Java?

grub is a platform-dependent command - and not Windows - so the fact that you're even running it as a .exe raises a few alarm bells; let alone via Java. It's also (normally) an administration command, so you'll presumably have to give whatever program you're running it from superuser rights, which doesn't sound too swift to me. I'm an old sysadmin, and I'd be very leery about anything like that running on one of my machines.

Couldn't you just write a script?

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
thanks guys

sorry for the late reply i got called a way to work overseas last minute...

@James

thanks i have added that in to get the names but i also needed to tie it in with a physical location also, while i was away i mentioned it to a guy who said it can also be done with a script im still yet to research it but he mentioned to search for
Win32_DiskDrive.DeviceID

not sure what it will come back with i have never used a script before to do stuff..

@winston

i have a javaFX for loading up multiple bootable images for work on USB drives and i use grub with syslinux to install the MBR and PBR on the USB via nice FX app...

instead of running the grubinist through windows as a Runtime should it be run via a script? as isnt it still doing the same thing? (NOTE i only run that once as only want to install a new MBR on USB drive)

And yes i have JNA to elevate the command to sys admin rights...
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7795
    
  21

peter hammond wrote:i have a javaFX for loading up multiple bootable images for work on USB drives and i use grub with syslinux to install the MBR and PBR on the USB via nice FX app...
instead of running the grubinist through windows as a Runtime should it be run via a script? as isnt it still doing the same thing? (NOTE i only run that once as only want to install a new MBR on USB drive)
And yes i have JNA to elevate the command to sys admin rights...

Right. So your poor sysadmin (and if that's you, fine; but I certainly wouldn't recommend it for a public system) has to deal with an exe he knows nothing about, which is run via an FX app, which presumably then runs the command via something like Runtime.exec() to execute a command that isn't even native to the OS it's running on. Do you see the potential problems? The actual command (grub) is so many layers removed from the actual thing you run it from that your poor sysadmin really has no idea what's going on. And what's more, he has to grant superuser rights (presumably) to ALL the intervening wrappers. Or at the very least, to the thing he probably knows least about.

And lastly, you're using it to do stuff (re-writing MBRs) that is potentially disastrous.
Just a quick question: What's to stop you running this on your C: drive?

Now I'm probably old-fashioned, but if someone came to me with a proposal like that, it would go straight in my out-tray with a big red "REJECTED" stamp on it unless they ALSO could provide me with a procedure guaranteed to prevent misuse, along with evidence of lots of standard logging.

Winston
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Certainly not a “beginning” topic. Moving to another forum: let's try general computing.
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
no not a system admin, i just wrote a standalone FX program to resolve a issue where we have multiple users that need to be able to boot various images to access restricted desktops via a USB Key dongle....

the app i am talking about is standalone and runs on windows only and its a way to install grub and syslinux on the user keys automatically for them so they dont do it on the wrong drive...

that is the sole reason i have asked here how to get the physical name for the usb drive to be used...... as i have the below to give the user only access to removable media locally..



when i pass the string to Runtime,exec() i want to be sure i get the drive correct.. the end user will never be able to select the wrong drive....

this



counter is my temp solution to get the HD number it will never be harddisk 0 as thats the primary HDD that would be bad....

but i have been researching VBS script on google as i mentioned earlier and think i found a solution but just working on making it into a nicer list for me to work on, posted below incase someone else finds the same issue when matching the logical with physical..



not sure if if follow correctly with your references to system admin?? should i be doing it incorrectly im happy to change it to to be safe or better practices as everyday is a learning day,,,
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7795
    
  21

peter hammond wrote:not sure if if follow correctly with your references to system admin?? should i be doing it incorrectly im happy to change it to to be safe or better practices as everyday is a learning day,,,

OK, maybe I should back up: is this for your system or for any system? If it's just for your system then you can do pretty much anything you like, because if you crash it, you only have yourself to blame. But if this is for use on ANY system, then there will be a vetting procedure to go through that will (or darn well should) involve their system administrators.

Personally, I don't like the idea of anyone EXCEPT ME running something like grub on one of my systems, because of the potential damage it can do.

I guess I'm also still not quite sure what problem you're trying to solve. If you want to be able to run different OS's from a single machine, surely you could use something like vBox, which is written specifically for stuff like that? (And it's a fabulous tool, BTW). However, as an admin, I'm not sure if I'd even want that being run by just anybody.

Winston
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
ok sure thanks for the replys.....

basically i wanted to get the output of the system running the APP so i can pass a double check that i will be adding the mbr on the correct drive....

wanted the below output.... had to use a script that someone else made but its just the ticket as couldnit find a java only way...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get PhysicalDrive name from logical windows name?