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
Asked
Active
Viewed 7,995 times
3 Answers
1
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

samwyse
- 2,760
- 1
- 27
- 38
0
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%"

Reuben
- 5,556
- 10
- 43
- 55
-
I have tried this and it doesnt work.. this is what I did below "C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrun.exe" -gu localname -gp password runScriptInGuest "C:\\Users\\Administrator\\Documents\\Virtual Machines\\Windows 8 32_ws\\Windows 8 32_ws.vmx" "C:\\windows\\system32\\cmd.exe" "/c echo %PROGRAMFILES%" – user2511126 Jan 28 '14 at 12:15
-
basically I need to run this command and capture the output of the command back in the host... I am not sure if this could be possible using vmrun commands – user2511126 Jan 28 '14 at 12:17
-
I can confirm that runScriptInGuest does not work properly in Windows (at least not what I'm using -- Windows 7 with VMWare 9). And yes, runProgramInGuest, executing a BAT file that was previously copied to the guest, is the solution, as demonstrated by samwyse's answer. – Vern Jensen Apr 15 '15 at 20:26
0
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.

user2511126
- 620
- 1
- 14
- 31