in reply to Windows Server Authentication

The net command will tell you why it failed. Alter your code to ensure it has completed correctly, and to alert you of failures, at which point your program shouldn't progress further. You've not posted any errors messages experienced.