title: How can I execute code after a user entered credentials but before a connection to the domain controller is established?
body: <p>I'm currently moving a small office environment to Amazon Web Services (AWS). There are several domain joined computers in an office and a domain controller (DC) in an AWS Virtual Private Cloud (VPC).</p>
  
  <p>A VPN connection to the VPC costs 0.05$ per connection hour and as the office is very irregularly occupied I wish to establish this connection on demand to save costs.</p>
  
  <p>My thoughts were to activate this VPN connection using the AWS API everytime after a user entered its credentials. This requires me to synchronously execute code after the user submits his credentials and before Windows is trying to connect to the DC in the cloud (as this will fail when no connection is established).</p>
  
  <p>Is there a way to synchronously hook in between these two steps (1. Submitting credentials, 2. Connecting to DC) and execute code?</p>
  
  <p>Signing code using certificates should not be a problem.
  Any other method which allows to create this VPN connection before a user enters his credentials would also be fine, like an event which is triggered as soon as the mouse is moved/key is hit/Windows 10 curtain is lifted/...</p>