如何在windows服务中打开文件
2013-01-31 09:33
423 查看
//windows服务默认是不支持与桌面进行交互的,所以就无法打开硬盘上的文件,比如播放音乐等。//需要在serviceProcessInstaller1的Committed事件中添加如下代码: ConnectionOptions myConOptions = new ConnectionOptions(); myConOptions.Impersonation = ImpersonationLevel.Impersonate; ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", myConOptions); mgmtScope.Connect(); ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + serviceInstaller1.ServiceName + "'"); ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam["DesktopInteract"] = true; ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null); //在你需要打开文件的代码处添加如下代码打开文件 System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "文件所在目录"; process.StartInfo.WorkingDirectory = "文件根目录"; process.Start();
转载于:http://www.cnblogs.com/love2wllw/archive/2010/05/15/1736339.html
相关文章推荐
- windows下编辑的文件在linux下打开后会有很多^M?什么原因,如何去掉?
- 如何重新找到在Windows Live Mail 中直接打开修改保存并且不小心关闭的文件
- 如何调用windows 的调色板 以及如何打开文件
- 如何恢复windows的exe文件的默认打开方式
- Windows 7下如何打开旧的 .HLP 帮助文件
- 在Windows/Linux中如何打开.sit/.hqx压缩文件
- 【Unity3d】自动版本构建: 如何在Windows平台下自动打开资源管理器并且选中指定文件
- Windows下如何用cmd自动打开/关闭Oracle的服务
- Windows文件系统过滤驱动中打开文件时如何避免重入
- 如何让程序出现windows标准对话框(如:打开文件时的对话框)式样的帮助?
- eml文件在windows 7及windows 8下如何打开
- Windows下如何打开.tar.bz2文件
- 如何取消Windows 默认文件打开方式
- 如何取消某个文件的默认打开方式使其恢复到原来windows无法打开的状态
- 如何用批处理文件(.bat)停止或启动windows的服务
- 在windows服务程序中打开带窗体的可执行文件
- windows如何打开Microsoft access table shortcut文件
- 如何恢复windows的exe文件的默认打开方式
- Windows下如何打开*.pages文件
- web站点和windows服务项目发布时如何排除指定文件