javawindowswindows-servicesprocrun

windows service access to network before logon


I wrote a windows service in Java, and it starts automatically (before user login to Windows). My problem is that it looks like the service has no access to the network before logon.

In the logs I see that before logon, I get: java.net.UnknownHostException. However, the same code works fine after logon.

I tried to define the service as "network service", it did not helped.

Can anyone please help?

BTW:

  1. There is no WiFi involved

  2. I looked how TeamViewer program works and I saw that they have some registry values in FirewallPolicy. and they defined their service as local system. Which made me think maybe it has something to do with the firewall settings, however I cannot find anything in the web about it.


Solution

  • I just managed to solve this. The issue was that the service started before there was access to the internet. Keep in mind that the network might be accessible but the internet isn't.

    I solved it by doing: (pseudo code)

    while (false) {
        check if http://www.example.com is accesible:
            if true - break
            if false - sleep for 3 seconds
    }
    ... (rest of the code)