예제 #1
0
        private void btnInstall_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtPathService.Text.StartsWith(@"\\"))
                {
                    throw new
                        Exception("No se permiten rutas UNC para la instalacion del servicio. Especifique la ruta local del servicio");
                }
                if (txtServicename.Text == null || txtServicename.Text == "")
                {
                    throw new Exception("Especifique un nombre para el servicio");
                }
                if (txtServer.Text == null || txtServer.Text == "")
                {
                    throw new Exception("Especifique el nombre del servidor");
                }

                string mode = cbStartmode.SelectedItem.ToString();

                WIN32.Win32API.ServiceStartMode st =
                    (WIN32.Win32API.ServiceStartMode)Enum.Parse(typeof(WIN32.Win32API.ServiceStartMode), mode);

                WIN32.Win32API.ServiceReturnCode rt = new DotNet.Tools.WIN32.Win32API.ServiceReturnCode();

                if (ckuser.Checked)
                {
                    WIN32.Win32_Service sv = new DotNet.Tools.WIN32.Win32_Service(txtServer.Text);
                    rt = sv.Install(txtServer.Text, txtServicename.Text,
                        txtServicename.Text, txtPathService.Text,
                        st, txtUser.Text, txtPass.Text, null);
                }
                else
                {
                    WIN32.Win32_Service sv = new DotNet.Tools.WIN32.Win32_Service(txtServer.Text);
                    rt = sv.Install(txtServer.Text, txtServicename.Text,
                        txtServicename.Text, txtPathService.Text,
                        st, null, null, null);
                }

                if (rt != null) { MessageBox.Show("Resultado: " + rt.ToString()); }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
 private void Test7()
 {
     WIN32.WmiAccess w_acc = new DotNet.Tools.WIN32.WmiAccess();
     WIN32.Win32_Service w_serv = new DotNet.Tools.WIN32.Win32_Service(w_acc);
     w_serv.Install("SVAPL02-36", "DeployServer 2.0", "Deploy Server 2.0",
             @"D:\Services .NET\dotNET\DeployServerSVCHost\", DotNet.Tools.WIN32.Win32API.ServiceStartMode.Disabled,
             @"UI\DI_ROSSELLO2","KUKUXUMUXU007",null);
 }