hyperv2hosts icon indicating copy to clipboard operation
hyperv2hosts copied to clipboard

Doesn't update hosts file

Open damthemad opened this issue 2 years ago • 4 comments

Hi,

Nice tool but unfortunately it doesn't works for me.

I see that the program is triggered as a new line apparead in the file the first time i started an hyperv vm, but this is only a comment, and after other trials (shutdown and restart vm) nothing happenend.

the line who appeared is below :

[HYPERV2HOSTS] Updated at Tue Jan 31 18:48:44 2023

Windows 10/64

br

damthemad avatar Jan 31 '23 17:01 damthemad

It's indeed not working all the time. Two things to check:

    1. You need to run the tool as administrator.
    1. It finds the VM guest IP address by the following powershell command:
Get-VMNetworkAdapter -VMName linux | Select VMName, IPAddresses

If you run the command in powershell as administrator and it's not there, then something else is wrong.

PS, I just changed the hosts file format. The original order in line 99 was wrong.

aaalgo avatar Jan 31 '23 19:01 aaalgo

Hi,

The user which run the task is member of group admin

The powershell command returns nothing but this is normal as you pass an argument "-VMName linux" and my VM is not named "linux". if i change the argument with my vm name, the command is ok and returns VM's IP Address.

According to readme, i understand that this program should list all vms, so the name shouldn't be fixed. Do you mean that it is only functional for one unique vm whose name is linux ? It seems that's true since i can see this powershell command in source code (i can't compile ccp source code, no tools, and last time i did c++ was almost 20 years ago). Perhaps, coud you run "Get-VM | Get-VMNetworkAdapter | Select VMName, IPAddresses" and iterate on the results ?

br

damthemad avatar Feb 01 '23 09:02 damthemad

I've added a new release here: https://github.com/aaalgo/hyperv2hosts/releases/tag/1.0.2

You need to supply the guest name with the command line argument "-n vmname" or "--name vmname". If you want to change the hostname, you can use "--host-fmt vm_{}", where {} will be replaced with guest name.

I'm not sure if this will work. I chose C++ so I can build something standalone, but maybe a python script will be better for the purpose.

aaalgo avatar Feb 02 '23 01:02 aaalgo

It doen't work. I'v added --name xxxx (xxx = vm name) and always nothing in my host file. since i now know how to detect starting event, thanks to Readme, i will write my own tool. br

damthemad avatar Feb 03 '23 10:02 damthemad