简体   繁体   中英

Using Vix API to get VM's domain and users' list

I'm trying to use the Vix API and i'm trying to receive some information of the virtual machines i'm working on. The information i need is the domain to which the VM is connected, and the list of users that are registered (ie, have access) to the specific VM. I tried using 'google' and the documentation ( https://www.vmware.com/support/developer/vc-sdk/visdk2xpubs/ReferenceGuide/ ) but i can't find how to get this information. Tried to allocate a few objects that might contain the the domain, but it didn't help.

I'm not sure if this will help you, but below is an extract from a small Delphi project (which uses the same Vix COM/OLE interface as vbScript) which retrieves the current user name from the Environment of a Win7 VM. Hopefully the code would be straightforward to translate to vbScript or VBA. Obviously, you can retrieve the value of any other Environment variable, such as the User Domain, in a similar way.

I've had quite a thorough look through the Vix COM API and have not found anything which would retrieve a list of available login IDs for a VM. So, if I had to do this, I'd write a small utility app to run in the VM to get them. (You may know already, but it's straightforward to run an app in the VM via the Vix interface.)

Code

type  
  TForm1 = class(TForm)
    [...]
    VixLib : IVixLib;
    Job : IJob;
    Host : IHost;
    VM : IVM;
    Err : Int64;
    vWaitParams : OleVariant;
    vResults : OleVariant;
    vValue : OleVariant;
    Msg : String;
  end;
[...]
procedure TForm1.GetUserName;
begin
  // Prior to calling this code, you need to have successfully called
  // LogInGuest on the VM via Vix
  // change USERNAME to USERDOMAIN in the following line to get the domain
  Job := VM.ReadVariable(VIX_GUEST_ENVIRONMENT_VARIABLE, 'USERNAME', 0, Nil);
  vWaitParams := VarArrayOf([VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING]);
  Err := Job.Wait(vWaitParams, vValue);
  if Err <> 0 then
    raise Exception.Create('Error %d', [Err]);

  Msg := vValue[0];
  Caption := Msg;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM