Listing 1:

 

$wsl_ip = (wsl hostname -I).trim()
netsh interface portproxy add v4tov4 listenport=2222 connectport=2222 connectaddress=$wsl_ip
netsh interface portproxy add v4tov4 listenport=80 connectport=80 connectaddress=$wsl_ip
netsh interface portproxy add v4tov4 listenport=443 connectport=443 connectaddress=$wsl_ip
netsh advfirewall firewall add rule name="Open Port 2222 for WSL2" dir=in action=allow protocol=TCP localport=2222
netsh advfirewall firewall add rule name="Open Port 80 for webserver WSL2" dir=in action=allow protocol=TCP localport=80
netsh advfirewall firewall add rule name="Open Port 443 for secure webserver WSL2" dir=in action=allow protocol=TCP localport=443

Listing 2:

Set ws = CreateObject("Wscript.Shell") 
ws.run "wsl -u root service ssh start", vbhide
ws.run "wsl -u root service apache2 start", vbhide