Windows_service and run_as_user examples

Hey guys,

I have been trying to use Chef for install a windows service and also to configure the user/pass for the service. From the reading I did, I see there is a run_as_user and a run_as_password option. When I pass these properties, it seems to ignore them and continue on with the script. I was wondering if someone had some examples of how I should be doing this? Thank you very much for the help.

I’ve had trouble with the chef windows service in the past, so in my cookbooks, I’ve resorted to using raw powershell to call the sc.exe executable directly. Not quite as clean, but works flawlessly.

  powershell_script 'foobar Install' do
    guard_interpreter :powershell_script
    code <<-EOH
      sc.exe create #{foobar_service_name} displayname= '#{foobar_display_name}' obj= "#{node['domain']}\\#{foobar_user}" password= "#{foobar_password}" binPath= c:\\foobar.exe start= demand
    action :run
    not_if "Get-Service -Name '#{foobar_service_name}'"
    not_if "Get-Service -Name '#{foobar_display_name}'"

Cool thanks. I will do that.