How to run a command in vmware using vmrun, command is (echo %PROGRAMFILES%)

8.2k Views Asked by At

How to run a command in vmware using vmrun, command is (echo %PROGRAMFILES%) on the guest machine.. and the guest machine should return a value of the command result... how to do this??? please suggest

3

There are 3 best solutions below

3
On

Have a look at the vmrun commands here. You need the Guest OS Command runScriptInGuest.

I have not checked the command , but it should look like this. Please verify it.

vmrun -T server -h https://xps:8333/sdk -u user -p mypassword -gu administrator -gp guestpaswd 
  runScriptInGuest "[Vol1] win2008-1/win2008-1.vmx" "echo %PROGRAMFILES%"
0
On

I had to use runProgramInGuest capture the output to a file copy the file back to my host and use it Thats the soln I used.

0
On

I needed to do something similar and found this unanswered question. Here's my solution.

@ECHO OFF

REM Set up abbreviations that we'll be using a lot.
SET VMRUN="C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe" -T ws -gu Administrator -gp password
SET VMX="C:\Users\whoever\Documents\Virtual Machines\Windows\Windows.vmx"
SET GUEST_COMSPEC="C:\WINDOWS\system32\cmd.exe"

REM Tried to do this in one line, but couldn't figure out the quoting.
%VMRUN% CreateTempfileInGuest %VMX% >%TEMP%\GuestTmp.txt || GOTO :CantCreate
FOR /F "delims=;" %%F IN ( %TEMP%\GuestTmp.txt ) DO SET GTEMP=%%F

REM The batch file is a one-liner that echos the variable into a file.
REM It could be generated dynamically and copied to the guest
REM but I didn't want to complicate things any further.
%VMRUN% runProgramInGuest %VMX% %GUEST_COMSPEC% "/c C:\echo-ProgramFiles.bat %GTEMP%"
%VMRUN% CopyFileFromGuestToHost %VMX% %GTEMP% %TEMP%\GuestOut.txt
%VMRUN% DeleteFileInGuest %VMX% %GTEMP%

REM Do something with the result and delete the temp files.
TYPE %TEMP%\GuestOut.txt
DEL %TEMP%\GuestOut.txt %TEMP%\GuestTmp.txt
GOTO :EOF

:CantCreate
REM Provide details on any problems.
TYPE %TEMP%\GuestTmp.txt 1>&2
DEL %TEMP%\GuestTmp.txt
EXIT 100

And here's the batch file on the guest host. As you can see, it's pretty simple. I couldn't get redirection to work in runProgramInGuest (probably didn't experiment enough) so I just pass the file as a command line argument.

@echo %PROGRAMFILES% >%1