wood burning stoves 2.0*
The moose likes Java in General and the fly likes Unable to mount in windows 7 through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unable to mount in windows 7 through Java" Watch "Unable to mount in windows 7 through Java" New topic
Author

Unable to mount in windows 7 through Java

jaibhim max
Greenhorn

Joined: Nov 15, 2010
Posts: 21
Hi All,

I am using windows 7. If I run following command from command prompt

It mounts the network drive /d/jaibhim on my z: drive.

I want to achieve same result through Java. So I wrote following piece of code-


I get following error from the error stream- "'C:\Windows\System32\mount.exe' is not recognized as an internal or external command,"

Could you please guide me, where I am going wrong?


Thanks,
jaibhim
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Are you sure it's mount and not mountvol


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
jaibhim max
Greenhorn

Joined: Nov 15, 2010
Posts: 21
hi Maneesh,

its mount not mountvol.

mount.exe is present under C:\Windows\system32


Thanks,
jaibhim
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

My installation of Windows 7 does not recognize mount. It does recognize mountvol, though. I'd tend to believe Maneesh is right and your system is somewhat crooked; you should start using mountvol perhaps.

The error message you're getting might mean that the cmd.exe executed from Java does not have necessary permissions to run C:\Windows\System32\mount.exe (assuming it does exist at that location, as you report). Aren't you running the console as an Administrator when you're trying that from command line?
jaibhim max
Greenhorn

Joined: Nov 15, 2010
Posts: 21
Hi All,

I got the solution from my friend...It should look like as -



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

That looks odd. Yes, the entire mount command should be one argument - it's one of two arguments (the other /C) to cmd.exe. It's the first /C and the other cmd.exe I find odd. I think the following should be enough:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

I don't think there is any problem with parceling the arguments one way or the other. At the end the arguments in the array get concatenated together with space as a separator under Windows (or so I believe - Windows does not have that sophisticated shell interface as Unix).

However, the need to use sysnative looks highly suspicious. This is a way for a 32bit application to access 64bit version of the system32 directory, which is otherwise unavailable due to redirection. It also means that there is only 64bit version of mount.exe on the system, otherwise this would not be needed and the 32bit application would call mount.exe from 32bit version of system32 directory. This need not be a problem, if the application is to never be run on another system, but if the plans are to use it on other computers, it can run into a new problems of its own. Also, I believe that if run using 64bit JRE, it would fail, as sysnative is not recognized by 64bit apps (see this).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to mount in windows 7 through Java