windows服务安装

string[] cmdline = { };

                    /*E:\test\WindowsServiceTest\MyWeb\bin*/
                    string path = Server.MapPath("/bin/");
                    string s = Server.MapPath("/bin/WindowsServiceTest.exe");
                    //AssemblyInstaller installer = new AssemblyInstaller();
                    //installer.Path = Server.MapPath("/bin/WindowsServiceTest.exe");

                    //installer.UseNewContext = true;
                    //installer.Install(null);
                    //installer.Commit(null);
                    //installer.Dispose();


                    #region
                    //TransactedInstaller transactedInstaller = new TransactedInstaller();
                    //AssemblyInstaller assemblyInstaller = new AssemblyInstaller(@"E:\test\WindowsServiceTest\MyWeb\bin\WindowsServiceTest.exe", cmdline);
                    //transactedInstaller.Installers.Add(assemblyInstaller);
                    //transactedInstaller.Install(new System.Collections.Hashtable());
                    #endregion

                    #region
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = "cmd.exe";
                    startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
                    startInfo.RedirectStandardInput = true;
                    startInfo.RedirectStandardOutput = true;
                    startInfo.RedirectStandardError = true;
                    startInfo.UseShellExecute = false;
                    startInfo.Verb = "RunAs";
                    Process p = new Process();
                    p.StartInfo = startInfo;

                    p.Start(); // 启动进程
                    //p.StandardInput.WriteLine(@"del D:\123.txt"); // Cmd 命令

                    p.StandardInput.WriteLine(@"e:"); // Cmd 命令                 
                    p.StandardInput.WriteLine(@"cd  E:\test\WindowsServiceTest\WindowsServiceTest\bin\Debug"); // Cmd 命令
                    p.StandardInput.WriteLine(@"installutil WindowsServiceTest.exe"); // Cmd 命令

                    p.StandardInput.WriteLine("exit"); // 退出

                    #endregion

 

posted @ 2015-11-11 09:16  nbu_djw  阅读(416)  评论(0编辑  收藏  举报