1

I want to grant a permission to my service to user/everyone. I can use subinacl to grant such permissions but am not usre how to code for it in the Installer class ?

And also if I want to grant permission to every user on the comp, can I use "Everyone" as user?

What is the system doesn't have any users - I mean on XP without any users, then how to handle the same.

Please help me at the earliest. Any help is highly appreciated.

EDIT : To grant permission I found this : http://ss64.com/nt/subinacl.html and this . I tried on cmd and it worked. I wrote the following to make it happen :

        WshShell shell = new WshShellClass();
        object wf = IWshRuntimeLibrary.WshWindowStyle.WshHide;
        //object ws = IWshRuntimeLibrary.
        if (allusers)
            shell.Run("subinacl /SERVICE \"OpenVPNService\" /Grant=Everyone=TO", ref wf, true);
        else
            shell.Run("subinacl /SERVICE \"OpenVPNService\" /Grant="+ Environment.UserName +"=TO", ref wf, true);
        shell = null;

The last parameter is giving problem. I needto pass a ref obj only. And it represents to show the window or not. Check Here I get error "Argument 3: cannot convert from 'bool' to 'ref object'. Any idea what to give in 3rd parameter.

Tvd
  • 4,463
  • 18
  • 79
  • 125

2 Answers2

0

Setting Username and Password to null will mean "every user" in case of every account except "User" (I mean: LocaSystem, LocalService, NetworkService). Or so MSDN says:

http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceprocessinstaller.account.aspx

http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx

For example:

namespace WindowsService
{
    [RunInstaller(true)]
    public class WindowsServiceInstaller : Installer
    {
        public WindowsServiceInstaller()
        {
            ServiceProcessInstaller serviceProcessInstaller = 
                               new ServiceProcessInstaller();
            ServiceInstaller serviceInstaller = new ServiceInstaller();

            serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Username = null;
            serviceProcessInstaller.Password = null;

            serviceInstaller.DisplayName = "My New C# Windows Service";
            serviceInstaller.StartType = ServiceStartMode.Automatic;

            serviceInstaller.ServiceName = "My Windows Service";

            this.Installers.Add(serviceProcessInstaller);
            this.Installers.Add(serviceInstaller);
        }
    }
}
Arie
  • 5,251
  • 2
  • 33
  • 54
  • Arie, the service I am usign is a third party service to which I can't do anything. I just make sure that it is installed on the comp before installing my application. So I don't think the above can be of use to me. The Service is custom installed so its 1 access entry in Registry is also not done that I can change. – Tvd Oct 21 '11 at 10:02
  • I found this http://stackoverflow.com/questions/961719/change-windows-service-user-programmatically – Arie Oct 21 '11 at 10:21
  • Arie, that code also needs permission - have a look at @tunger's post. I have added code that I have worked on. Am Stuck on it. – Tvd Oct 21 '11 at 11:00
0

I used Process and got things done successfully. Thanks to all.

Tvd
  • 4,463
  • 18
  • 79
  • 125