高分求.NET服务弹出WinForm 如题当服务里面的一个事件触发时跳出一个WinForm。谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 windows服务,在计算机管理里面有的 如果是WINDOWS服务 可以参考http://blog.csdn.net/zgke/archive/2009/01/11/3751917.aspx 你可以先将winfrom 窗体 创建成windows 应用程序,然后 在服务中调用它 好像只能起进程,不能直接实例化form的 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(); 这样的代码只能在本地实现。你本地启一个web程序,然后new一个winform是可以的。但是其他人访问你这个web是不可能出那个winform的。这是.net代码安全所限定死的。涉及到的相关知识可以去看.NET Code Security Sandy945的方法星期一试试看,谢谢!jamesfay说到的其他人访问暂时还涉及不到,也要谢谢你提醒!!谢谢大家 Form1 frm = new Form1();frm.Show(); Sandy945的方法试了一下,进程里是启动了另外的程序但是只是在进程里看到了,桌面上看不到 p.StartInfo.CreateNoWindow = true;注释 或者设置false 都可以 楼上灰太郎大哥,还是还进程里,就是不到桌面上来我的系统是XP SP3.NET版本指定的是2.0 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(); } 我这里环境是03 可以弹出窗口,之前这段代码也在xp sp3的机器上运行过 是可以弹出窗口的你换个机器试下公司把邮箱封了 -_- ~ 可以讓服務啟動一個EXE程序 服务的属性中 登录选项卡中选中 允许服务于桌面互交是可以了,谢谢。另外问一问在哪里可以默认设置这个“允许服务于桌面互交”卸载服务时提示C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil/u d:\WindowsService1.exe系统找不到指定的路径。 http://hi.baidu.com/telnet2008/blog/item/c01d49fb8cb68f274e4aeaea.html C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /u d:\WindowsService1.exe orC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil -u d:\WindowsService1.exe 谢谢灰太郎,谢谢红太郎,谢谢喜羊羊。以下是我总结的几个要点1、服务安装选项 帐户类型选 LocalSystem2、================安装.BAT开始@echo offC:\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.==============卸载.BATC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil d:\WindowsService1.exe /uecho 卸载完成pause 如果你是执行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 设置服务登陆名称为 Administrator winform combobox问题 c#验证码识别是通过哪些方法 询问 SuppressFinalize 方法[并忙解释] 请教各位,如何用C#或者js判断某个值是否是百分比(率)? PDF插入视频,编程实现 最佳匹配算法,求大牛 net2005中在添加数据源时,提示"该项不适于在指定状态下使用"错误(在线等,急) Web Service中与数据库相连的问题 回答任意一个都可以拿分:1.注册表中如何设置自己为开机就启动;2.如何复制自己 监视某一个assembly在运行中的状态 怎样用C#把JSON数据转换为list或数组 数据库操作错误问题
http://blog.csdn.net/zgke/archive/2009/01/11/3751917.aspx
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();
jamesfay说到的其他人访问暂时还涉及不到,也要谢谢你提醒!!
谢谢大家
frm.Show();
但是只是在进程里看到了,桌面上看不到
注释 或者设置false 都可以
我的系统是XP SP3
.NET版本指定的是2.0
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(); }
你换个机器试下公司把邮箱封了 -_- ~
是可以了,
谢谢。另外问一问在哪里可以默认设置这个“允许服务于桌面互交”
卸载服务时提示
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
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
写相对路径 就是把.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