title: How to build RUNAS /NETONLY functionality into a (C#/.NET/WinForms) program?
body: <p>Our workstations are not members of the domain our SQL Server is on.  (They're not actually on a domain at all - don't ask).</p>
  
  <p>When we use SSMS or anything to connect to the SQL Server, we use RUNAS /NETONLY with DOMAIN\user.  Then we type in the password and it launches the program.  (RUNAS /NETONLY does not allow you to include the password in the batch file).</p>
  
  <p>So I've got a .NET WinForms app which needs a SQL connection, and the users have to launch it by running a batch file which has the RUNAS /NETONLY command-line and then it launches the EXE.</p>
  
  <p>If the user accidentally launches the EXE directly, it cannot connect to SQL Server.</p>
  
  <p>Right-clicking on the app and using the "Run As..." option doesn't work (presumably because the workstation doesn't really know about the domain).</p>
  
  <p>I'm looking for a way for the application to do the RUNAS /NETONLY functionality internally before it starts anything significant.</p>
  
  <p>Please see this link for a description of how RUNAS /NETONLY works: <a href="http://www.eggheadcafe.com/conversation.aspx?messageid=32443204&amp;threadid=32442982" rel="noreferrer">http://www.eggheadcafe.com/conversation.aspx?messageid=32443204&amp;threadid=32442982</a></p>
  
  <p>I'm thinking I'm going to have to use <code>LOGON_NETCREDENTIALS_ONLY</code> with <code>CreateProcessWithLogonW</code></p>