• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
FtpCsharp
博客园    首页    新随笔    联系   管理    订阅  订阅

using BAT to setup windows service

First of all ,we must copy the ngen.exe and InstallUtil.exe to the windows service directory ,if we want to use the relative path

regist windows service Bat:            

                                                    InstallUtil    Test.exe  //the name of the service

                                                    net start "Test"       //start the service

unregist windows service Bat:          InstallUtil -u WindowsServiceFileupload.exe

(1)

    we double click the file,we can enter to the dos which could execute the command in the bat file

(2) 

     we use Process to start the bat file

there has a problem which the defualt directory is system32,so we must to point the abosulte path

%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe   "D:/Test.exe"

then the code :

            Process p = new Process();
            p.StartInfo.FileName =batFilePath;        

            p.Start();

            p.WaitForExit(30000);  join the thread

But what I want to say is it's no use in the develping like up ways!

what we want is using the relative ,so there give you a effective way

            Process p = new Process();
            p.StartInfo.FileName = batFilePath;

            p.StartInfo.WorkingDirectory = BasePath;        //point to the base diectory path    

            p.Start(); 

           p.WaitForExit(30000); 

the bat file we also can write as follow  which using the relative path

                                      InstallUtil    Test.exe  //the name of the service

                                      net start "Test"       //start the service

posted @ 2011-02-24 19:04  FtpCsharp  阅读(649)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3