Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to mount in windows 7 through Java

 
jaibhim max
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it's mount and not mountvol
 
jaibhim max
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Maneesh,

its mount not mountvol.

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


Thanks,
jaibhim
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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



 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic