I have noticed that when I run the following command

Pushd \\RemoteMachine\C$ && java.exe -version

I get the java version of the computer I am on. However when I run the pushd command with a search option like the command below I get the actual information found on that computer.

Pushd \\RemoteMachine\C$ && dir /s java.exe

Why is this the case? Is it possible to run java.exe -version on a remote PC and have it output that computers information on my screen?

link|improve this question

What Pushd are you using? The built-in Pushd command just pushes a file path onto a stack for later retrieval. – Darth Android Jun 13 '11 at 14:44
feedback

3 Answers

up vote 0 down vote accepted

When you run java.exe in your example, the shell only searches the current directory (i.e. \\RemoteMachine\C$) but not its subdirectories. (In other words, it's more like dir java.exe without the /s.)

Since there is no such file in the remote machine's C:\, the next step is to search the directories specified in your %PATH% environment variable (which normally only contains local directories).

To solve your problem, specify the full path to java.exe. You don't even need to use pushd:

C:\> "\\RemoteMachine\C$\Program Files\Java\jre6\bin\java.exe" -version
link|improve this answer
feedback

PsExec by SysInternals does exactly what you need it to. Your example would be:

psexec \\RemoteMachine java.exe -version
link|improve this answer
I cant use outside programs like PsExec or that would be perfect. I figured out a way around it but cant supply my own answer yet. After I pushd I need to cd \location of java.exe\. Then I can run -version and it displays correctly – harper89 Jun 13 '11 at 14:41
feedback

Although PsExec would get the job done I am unable to use that.

I am able to perform the command java.exe -version on the remote machine by changing the directory once I used pushd.

Pushd \\RemoteComputer\C$
cd "Program Files\Java\jre6\bin"
Java.exe -version

Or all at once

Pushd \\RemoteComputer\C$ && cd "Program Files\Java\jre6\bin" && java.exe -version && popd
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.