コード例 #1
0
        static void Main()
        {
            try
            {
                Log.Main.Inform("Application version: " + AssemblyRoutines.GetAppVersion());

                string m = "Appication user: "******" (";
                if (WindowsUserRoutines.CurrentUserIsAdministrator())
                {
                    m += "administrator";
                    if (WindowsUserRoutines.CurrentUserHasElevatedPrivileges())
                    {
                        m += ", elevated privileges";
                    }
                    else
                    {
                        m += ", not elevated privileges";
                    }
                }
                else
                {
                    m += "not administrator";
                }
                Log.Main.Inform(m + ")");

                ServiceBase.Run(new Service());
            }
            catch (Exception e)
            {
                Log.Main.Error(e);
            }
        }
コード例 #2
0
 bool isAllowed()
 {
     if (WindowsUserRoutines.CurrentUserIsAdministrator())
     {
         return(true);
     }
     Message.Exclaim("This action is permitted for Administrators only.");
     return(false);
 }
コード例 #3
0
 bool isAllowed()
 {
     try
     {
         if (WindowsUserRoutines.CurrentUserIsAdministrator())
         {
             return(true);
         }
         throw new System.Security.SecurityException();
     }
     catch (Exception e)
     {
         if (e is System.Security.SecurityException)
         {
             Message.Exclaim("This action is permitted for Administrators only.");
         }
         else
         {
             LogMessage.Error(e);
         }
     }
     return(false);
 }
コード例 #4
0
        public static void Main(string[] args)
        {
            try
            {
                uint dwSessionId = WinApi.Wts.WTSGetActiveConsoleSessionId();
                MpegStream.Start(dwSessionId, "-f gdigrab -framerate 10 -f rtp_mpegts -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params aMg7BqN047lFN72szkezmPyN1qSMilYCXbqP/sCt srtp://127.0.0.1:5920");
                //Process mpeg_stream_process;
                //var processId = Win32Process.CreateProcessInConsoleSession("cmd");
                //mpeg_stream_process = Process.GetProcessById((int)processId);
                //ProcessRoutines.AntiZombieTracker.Track(mpeg_stream_process);

                //    try
                //    {
                //        var p = new Process();
                //        p.StartInfo.UseShellExecute = false;
                //        //const string file = "cmd.exe";
                //        const string file = @"psexec.exe";
                //        p.StartInfo.WorkingDirectory = Path.GetDirectoryName(file);
                //        p.StartInfo.FileName = Path.GetFileName(file);
                //        //proc.StartInfo.Domain = "WIN08";
                //        p.StartInfo.Arguments = "-i -d -s cmd";
                //        //p.StartInfo.UserName = "******";
                //        //var password = new System.Security.SecureString();
                //        //foreach (var c in "123")
                //        //    password.AppendChar(c);
                //        //p.StartInfo.Password = password;
                //        p.StartInfo.LoadUserProfile = false;
                //        p.Start();
                //    }
                //    catch (Exception e)
                //    {
                //        Console.WriteLine(e);
                //    }

                //MpegStream.Start("-f gdigrab -framerate 10 -f rtp_mpegts -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params aMg7BqN047lFN72szkezmPyN1qSMilYCXbqP/sCt srtp://127.0.0.1:5920");
                //Thread.Sleep(2000);
                //MpegStream.Stop();

                Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion());
                string m = "User: "******"(";
                if (WindowsUserRoutines.CurrentUserIsAdministrator())
                {
                    m += "administrator";
                    if (WindowsUserRoutines.CurrentUserHasElevatedPrivileges())
                    {
                        m += ", elevated privileges";
                    }
                    else
                    {
                        m += ", not elevated privileges";
                    }
                }
                else
                {
                    m += "not administrator";
                }
                Log.Main.Inform(m + ")");

                ProcessRoutines.RunSingleProcessOnly();

                Service.Running = true;

                Application.Run(SysTray.This);
            }
            catch (Exception e)
            {
                Message.Error(e);
            }
            finally
            {
                Environment.Exit(0);
            }
        }
コード例 #5
0
        internal static void sessionChanged(uint sessionId, bool active)
        {
            try
            {
                if (sessionId == 0 || !active)
                {
                    Log.Main.Inform("User logged off: " + currentUserName);
                    stopServingUser();
                    currentUserSessionId = 0;
                    currentUserName      = null;
                    return;
                }

                string userName = WindowsUserRoutines.GetUserNameBySessionId(sessionId);
                if (userName == currentUserName)
                {
                    return;
                }

                Log.Main.Inform("User logged in: " + userName);
                stopServingUser();
                currentUserSessionId = sessionId;
                currentUserName      = userName;
                if (string.IsNullOrWhiteSpace(currentUserName))
                {
                    Log.Main.Error("Session's user name is empty.");
                    return;
                }
                onNewUser_t = ThreadRoutines.StartTry(
                    () =>
                {
                    string service = Settings.General.GetServiceName();
                    IReadOnlyList <IZeroconfHost> zhs = ZeroconfResolver.ResolveAsync(service, TimeSpan.FromSeconds(3), 1, 10).Result;
                    if (zhs.Count < 1)
                    {
                        currentServerIp = Settings.General.TcpClientDefaultIp;
                        string m        = "Service '" + service + "' could not be resolved.\r\nUsing default ip: " + currentServerIp;
                        Log.Main.Warning(m);
                        UiApi.Message(MessageType.WARNING, m);
                    }
                    else if (zhs.Where(x => x.IPAddress != null).FirstOrDefault() == null)
                    {
                        currentServerIp = Settings.General.TcpClientDefaultIp;
                        string m        = "Resolution of service '" + service + "' has no IP defined.\r\nUsing default ip: " + currentServerIp;
                        Log.Main.Error(m);
                        UiApi.Message(MessageType.ERROR, m);
                    }
                    else
                    {
                        currentServerIp = zhs.Where(x => x.IPAddress != null).FirstOrDefault().IPAddress;
                        Log.Main.Inform("Service: " + service + " has been resolved to: " + currentServerIp);
                    }

                    IPAddress ip;
                    if (!IPAddress.TryParse(currentServerIp, out ip))
                    {
                        throw new Exception("Server IP is not valid: " + currentServerIp);
                    }
                    TcpServer.Start(Settings.General.TcpServerPort, ip);

                    string url = "http://" + currentServerIp + "/screenCapture/register?username="******"&ipaddress=" + TcpServer.LocalIp + "&port=" + TcpServer.LocalPort;
                    Log.Main.Inform("GETting: " + url);

                    HttpClient hc          = new HttpClient();
                    HttpResponseMessage rm = hc.GetAsync(url).Result;
                    if (!rm.IsSuccessStatusCode)
                    {
                        throw new Exception(rm.ReasonPhrase);
                    }
                    if (rm.Content == null)
                    {
                        throw new Exception("Response is empty");
                    }
                    string responseContent = rm.Content.ReadAsStringAsync().Result;
                    if (responseContent.Trim().ToUpper() != "OK")
                    {
                        throw new Exception("Response body: " + responseContent);
                    }
                    Log.Main.Inform("Response body: " + responseContent);
                },
                    (Exception e) =>
                {
                    Log.Main.Error(e);
                    TcpServer.Stop();
                    UiApi.Message(MessageType.ERROR, Log.GetExceptionMessage(e));
                },
                    () =>
                {
                    onNewUser_t = null;
                }
                    );
            }
            catch (Exception e)
            {
                Log.Main.Error(e);
            }
        }
コード例 #6
0
 static public string GetUserName()
 {
     return(WindowsUserRoutines.GetCurrentUserName3());
 }
コード例 #7
0
        public static void Start(string arguments)
        {
            if (mpeg_stream_process != null)
            {
                Log.Main.Warning("The previous MpegStream was not stopped!");
            }
            Stop();

            if (string.IsNullOrWhiteSpace(Settings.General.CapturedMonitorDeviceName))
            {
                Settings.General.CapturedMonitorDeviceName = MonitorRoutines.GetDefaultMonitorName();
                if (string.IsNullOrWhiteSpace(Settings.General.CapturedMonitorDeviceName))
                {
                    throw new Exception("No monitor was found.");
                }
            }
            WinApi.User32.RECT?an = MonitorRoutines.GetMonitorAreaByMonitorName(Settings.General.CapturedMonitorDeviceName);
            if (an == null)
            {
                Settings.General.CapturedMonitorDeviceName = MonitorRoutines.GetDefaultMonitorName();
                Log.Main.Warning("Monitor '" + Settings.General.CapturedMonitorDeviceName + "' was not found. Using default one '" + Settings.General.CapturedMonitorDeviceName + "'");
                an = MonitorRoutines.GetMonitorAreaByMonitorName(Settings.General.CapturedMonitorDeviceName);
                if (an == null)
                {
                    throw new Exception("Monitor '" + Settings.General.CapturedMonitorDeviceName + "' was not found.");
                }
            }
            WinApi.User32.RECT a      = (WinApi.User32.RECT)an;
            string             source = " -offset_x " + a.Left + " -offset_y " + a.Top + " -video_size " + (a.Right - a.Left) + "x" + (a.Bottom - a.Top) + " -show_region 1 -i desktop ";

            arguments   = Regex.Replace(arguments, @"-framerate\s+\d+", "$0" + source);
            commandLine = "ffmpeg.exe " + arguments;

            Log.Main.Inform("Launching:\r\n" + commandLine);

            mpeg_stream_process = new Process()
            {
                //EnableRaisingEvents = true,
            };
            mpeg_stream_process.StartInfo = new ProcessStartInfo("ffmpeg.exe", arguments)
            {
                ErrorDialog     = false,
                UseShellExecute = false,
                CreateNoWindow  = !Settings.General.ShowMpegWindow,
                //WindowStyle = ProcessWindowStyle.Hidden,
            };
            if (Settings.General.WriteMpegOutput2Log)
            {
                mpeg_stream_process.StartInfo.RedirectStandardOutput = true;
                mpeg_stream_process.StartInfo.RedirectStandardError  = true;

                string file0 = Log.WorkDir + "\\ffmpeg_" + DateTime.Now.ToString("yyMMddHHmmss");
                string file  = file0;
                for (int count = 1; File.Exists(file); count++)
                {
                    file = file0 + "_" + count.ToString();
                }
                file += ".log";
                TextWriter tw = new StreamWriter(file, false);
                tw.WriteLine("STARTED: " + DateTime.Now.ToString());
                tw.WriteLine(">" + commandLine);
                tw.WriteLine("\r\n");
                tw.Flush();
                mpeg_stream_process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
                {
                    lock (tw)
                    {
                        tw.WriteLine(e.Data);
                        tw.Flush();
                    }
                };
                mpeg_stream_process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
                {
                    lock (tw)
                    {
                        //tw.WriteLine("ERROR: " + e.Data);//ffmpeg all the data sends to Error
                        tw.WriteLine(e.Data);
                        tw.Flush();
                    }
                };
            }
            if (!mpeg_stream_process.Start())
            {
                throw new Exception("Cound not start the process: " + mpeg_stream_process.StartInfo.FileName + " " + mpeg_stream_process.StartInfo.Arguments);
            }
            if (Settings.General.WriteMpegOutput2Log)
            {
                mpeg_stream_process.BeginOutputReadLine();
                mpeg_stream_process.BeginErrorReadLine();
            }
            if (!WindowsUserRoutines.CurrentUserIsAdministrator())
            {
                throw new Exception("!CurrentUserIsAdministrator. User's name: " + WindowsUserRoutines.GetCurrentUserName3());
            }
            ProcessRoutines.AntiZombieTracker.This.Track(mpeg_stream_process);
        }