VMware {code} Community
vinayan3
Contributor
Contributor

Reading Environment variables problem

Hi,

I am using ReadVariable with the option VIX_GUEST_ENVIRONMENT_VARIABLE and I am getting blank values. I am logged in as the Administrator.

Note, the two environment variables I can retrieve with no problem are TEMP, and TEMP.

However, I can't retrieve variables like WINDIR, PATH, COMSPEC, and even SYSTEMDIR. I have tried to put the environment variables into section for this user in the advanced pane of my computer. Through the VIX inteface I only get blank values. I can retrieve them all on the command line within the VM with no problems

Is there a limitation of VIX?

Thanks,

Vinay

0 Kudos
8 Replies
fixitchris
Hot Shot
Hot Shot

That is kind of weird. I get the same results.

Also, when you write a VIX_GUEST_ENVIRONMENT_VARIABLE, it does not show up in computer/advanced. But it is available to VIX.

Odd...

http://www.vmware.com/support/developer/vix-api/vix16_reference/lang/com/functions/ReadVariable.html

0 Kudos
vinayan3
Contributor
Contributor

Bump.

Update:

I still have not had a resolution on this issue. I called up VMWare technical support and they told me to email them with the problem. I used this form:

https://www.vmware.com/contact/contactus.html?department=customer_service&ref=http%3A//support.vmwar...

If I get any feedback I will let everyone know.

0 Kudos
fixitchris
Hot Shot
Hot Shot

0 Kudos
dblock
Enthusiast
Enthusiast

I've created VMWareTools part of the VMWareTasks library that implements wrapper functions that make this kind of stuff simple. Specifically ReadFile, ReadFileLines, ReadFileBytes, RunCommandInGuest that returns StdOut and StdErr output and GetEnvironmentVariables.

using System;

using System.Collections.Generic;

using Vestris.VMWareLib;

using Vestris.VMWareLib.Tools.Windows;

VMWareVirtualHost virtualHost = new VMWareVirtualHost();

virtualHost.ConnectToVMWareWorkstation();

VMWareVirtualMachine virtualMachine = virtualHost.Open("C:\Virtual Machines\xp\xp.vmx");

virtualMachine.PowerOn();

virtualMachine.WaitForToolsInGuest();

virtualMachine.LoginInGuest("Administrator", "password");

Shell guestShell = new Shell(poweredVirtualMachine);

Dictionary<string, string> guestEnvironmentVariables = guestShell.GetEnvironmentVariables();

Console.WriteLine(guestEnvironmentVariables);

Uploaded 1.2 daily build.

[[^|http://vmwaretasks.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25219|New Window]]

Much easier! I'd be glad to hear about other feature requests for covering common VMWare tasks scenarios.

0 Kudos
fixitchris
Hot Shot
Hot Shot

Pretty effective !

0 Kudos
Centurion2xx6
Contributor
Contributor

I have the same issue: vmrun.exe readVariable method returns only TEMP and TMP variable values. It returns empty string for all other variables.

This happens on one VM (Windows 7 64-bit), while on other VMs it works as expected...

What I noticed:

- On problematic VM there is only one process vmtoolsd.exe ("C:\Program Files\VMware\VMware Tools\vmtoolsd.exe")

- On other VMs there are two processes vmtoolsd.exe:

           a. vmtoolsd.exe ("C:\Program Files\VMware\VMware Tools\vmtoolsd.exe")

           b. vmtoolsd.exe ("C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" -n vmusr)

I've tried to launch vmtoolsd.exe with this parameter, but the process doesn't appear.

Have you figured out why this happens/how to fix this?

0 Kudos
lemke
VMware Employee
VMware Employee

Results will depend on the guest user being used, and whether or not you use interactiveSession.  interactiveSession isn't exposed by vmrun, but can be used if you use VIX directly.  Its also possible you've hit a (fixed) bug, since we had issues with Windows env variables a few years back.  We'd need some version details to know.

vmtoolsd with -n vmusr means someone is logged into the console, so a second, user-mode copy of tools is running.  This copy runs as the logged-in user, and handles drag&drop and other UI related things.  The other copy of vmtoolsd is running as SYSTEM, and as such will only see things SYSTEM sees (like most env variables).  The SYSTEM copy also has no access to the desktop.

0 Kudos
Centurion2xx6
Contributor
Contributor

VMware Tools version on "problematic" VM was older than on other VMs. Upgrade to a newer version of VMware Tools solved the issue.

Thank you much for pointing me to the cause and vmtoolsd process role explanation!

0 Kudos