How can I make sure Windows has established network connections on login before my program is run?


To reduce login time Windows does not wait for the network to be fully initialized at startup or login:

https://support.microsoft.com/en-us/help/305293/description-of-the-windows-fast-logon-optimization-feature


This means that programs run on startup may not be able to contact remote computers. To change this you must set the following DWORD value to 1 (create it if it doesn't exist):


HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\SyncForegroundPolicy