如题当服务里面的一个事件触发时跳出一个WinForm。谢谢。

解决方案 »

  1.   

    windows服务,在计算机管理里面有的
      

  2.   

    如果是WINDOWS服务 可以参考
    http://blog.csdn.net/zgke/archive/2009/01/11/3751917.aspx
      

  3.   

    你可以先将winfrom 窗体 创建成windows 应用程序,然后 在服务中调用它
      

  4.   

    好像只能起进程,不能直接实例化form的
      

  5.   


                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";
                //// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
                 p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                p.StandardInput.WriteLine(" cd c:\");// 向cmd.exe输入command
                //p.StandardInput.WriteLine("exit");
                ////p.WaitForExit();
                p.WaitForExit(10000);
                ////string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
                p.Close();
      

  6.   

    这样的代码只能在本地实现。你本地启一个web程序,然后new一个winform是可以的。但是其他人访问你这个web是不可能出那个winform的。这是.net代码安全所限定死的。涉及到的相关知识可以去看.NET Code Security
      

  7.   

    Sandy945的方法星期一试试看,谢谢!
    jamesfay说到的其他人访问暂时还涉及不到,也要谢谢你提醒!!
    谢谢大家
      

  8.   

    Form1 frm = new Form1();
    frm.Show();
      

  9.   

    Sandy945的方法试了一下,进程里是启动了另外的程序
    但是只是在进程里看到了,桌面上看不到
      

  10.   

    p.StartInfo.CreateNoWindow = true;
    注释 或者设置false 都可以
      

  11.   

    楼上灰太郎大哥,还是还进程里,就是不到桌面上来
    我的系统是XP SP3
    .NET版本指定的是2.0
      

  12.   


    private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
    {
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo.FileName = "cmd.exe";
    //// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口

    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.CreateNoWindow = false;
    p.Start();
    p.StandardInput.WriteLine(@" cd c:\");
    // 向cmd.exe输入command
    //p.StandardInput.WriteLine("exit");
    ////p.WaitForExit();
    p.WaitForExit(10000);
    ////string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出 //p.StartInfo.usesh p.Close(); // System.Diagnostics.Process oProcess = new Process(); }
      

  13.   

    我这里环境是03 可以弹出窗口,之前这段代码也在xp sp3的机器上运行过 是可以弹出窗口的
    你换个机器试下公司把邮箱封了 -_- ~
      

  14.   

     可以讓服務啟動一個EXE程序
      

  15.   

    服务的属性中 登录选项卡中选中 允许服务于桌面互交
    是可以了,
    谢谢。另外问一问在哪里可以默认设置这个“允许服务于桌面互交”
    卸载服务时提示
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil/u d:\WindowsService1.exe
    系统找不到指定的路径。
      

  16.   

    http://hi.baidu.com/telnet2008/blog/item/c01d49fb8cb68f274e4aeaea.html
      

  17.   

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /u d:\WindowsService1.exe 
    or
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil -u d:\WindowsService1.exe 
      

  18.   

    谢谢灰太郎,谢谢红太郎,谢谢喜羊羊。以下是我总结的几个要点
    1、服务安装选项 帐户类型选 LocalSystem2、================安装.BAT开始
    @echo off
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil d:\WindowsService1.exe
    @echo "设置允许与桌面进行交互方式允许"
    sc config service1 type= interact type= own
    @echo "正在重新启动服务..."
    sc start service1
    @echo "启动服务成功!"echo 安装完成
    pause
    ================安装.BAT结束3.==============卸载.BAT
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil d:\WindowsService1.exe /u
    echo 卸载完成
    pause
      

  19.   

    如果你是执行bat 文件来安装的话,就别写 绝对路径 d:\WindowsService1.exe 
    写相对路径 就是把.bat文件放在和.exe 文件一个文件夹内安装
    @echo off 
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil WindowsService1.exe 
    @echo "设置允许与桌面进行交互方式允许" 
    sc config service1 type= interact type= own 
    @echo "正在重新启动服务..." 
    sc start service1 
    @echo "启动服务成功!" echo 安装完成 
    pause 
    ================安装.BAT结束 3.==============卸载.BAT 
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil WindowsService1.exe /u 
    echo 卸载完成 
    pause 
      

  20.   

    设置服务登陆名称为 Administrator