Search code examples
nant

Nant run exec task under different user


It is possible to run Exec task with different domain and user ?

I need to restart iis on 10 load balancers , can this be achieved with Nant exe task ?

For now I have script like

<exec programm='iisreset'>
  <arg line='${balancer}'/>
  <arg line='/restart' />

 </exec>

This is working on Integration environment (Since the same domain) , and on test it fails with Acces Denied..

Thanks


Solution

  • You could use the command runas in you exec call and use the the /netonly argument for remote access to your balancers.

    I guess this could look something like this:

    <exec program="runas">
      <arg line="/netonly" />
      <arg line="${'/user:' + domain + '\' + username}" />
      <arg line="${'&quot;iisreset ' + balancer + ' /restart&quot;'}" />
    </exec>
    

    This could work for you but I am not sure how you are going to give him the password automatically. You could run runas with /savecred in your cmd once though. But be careful about saving your passwords...

    Note that I could not test this as I don't have the required environment to do so.

    Source: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true