Compare commits
	
		
			2 Commits
		
	
	
		
			8348865ce8
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 43cd24e650 | ||
|  | caec99a51b | 
| @@ -1,3 +1,3 @@ | ||||
| # TCPCommander-DesktopServer | ||||
| # TCPController-DesktopServer | ||||
|  | ||||
|  [Archived Code] TCP Server that allows you to control your windows computer from a mobile client. | ||||
|  [Archived Code] TCP Server that allows you to control your windows computer from a mobile client. | ||||
|   | ||||
							
								
								
									
										154
									
								
								src/Form1.cs
									
									
									
									
									
								
							
							
						
						
									
										154
									
								
								src/Form1.cs
									
									
									
									
									
								
							| @@ -40,8 +40,6 @@ namespace TCPCommander | ||||
|         public static UdpClient UDP_client; | ||||
|  | ||||
|         public static string IPstring; | ||||
|  | ||||
|         //IPAddress[] localIP; | ||||
|          | ||||
|         [DllImport("user32.dll")] | ||||
|         public static extern bool GetCursorPos(out Point lpPoint); | ||||
| @@ -154,11 +152,6 @@ namespace TCPCommander | ||||
|              | ||||
|         } | ||||
|  | ||||
|         //NatDiscoverer discoverer; | ||||
|         //NatDevice device; | ||||
|         //IPAddress ip; | ||||
|         //CancellationTokenSource cts; | ||||
|         //NatDevice UPNPdevice; | ||||
|         public async void PortForward(bool forward, bool alert = false) | ||||
|         { | ||||
|             if (!forward) | ||||
| @@ -174,12 +167,10 @@ namespace TCPCommander | ||||
|                 var discoverer = new NatDiscoverer(); | ||||
|                 var device = await discoverer.DiscoverDeviceAsync(); | ||||
|                 await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, int.Parse(TCP_PortTextBox.Text), int.Parse(TCP_PortTextBox.Text), "TCPCommander Server Map"));//"Inner Router")); | ||||
|                 //await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1700, 1800, "Outer Router")); | ||||
|  | ||||
|                 var sb = new StringBuilder(); | ||||
|                 var ip = await device.GetExternalIPAsync(); | ||||
|  | ||||
|                 //sb.AppendFormat("\nAdded mapping: {0}:{1} -> 127.0.0.1:{2}\n", ip, TCP_PortLabel.Text, TCP_PortLabel.Text); | ||||
|                 sb.AppendFormat("\n+------+-------------------------------+--------------------------------+------------------------------------+-------------------------+"); | ||||
|                 sb.AppendFormat("\n| PROT | PUBLIC (Reacheable)           | PRIVATE (Your computer)        | Description                        |                         |"); | ||||
|                 sb.AppendFormat("\n+------+----------------------+--------+-----------------------+--------+------------------------------------+-------------------------+"); | ||||
| @@ -204,28 +195,6 @@ namespace TCPCommander | ||||
|                 Console.ReadLine(); | ||||
|             } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|             //try | ||||
|             //{ | ||||
|  | ||||
|             //    discoverer = new NatDiscoverer(); | ||||
|             //    device = await discoverer.DiscoverDeviceAsync(); | ||||
|             //    ip = device.GetExternalIPAsync().Result; | ||||
|             //    Debug.WriteLine("Your External IP: " + ip); | ||||
|             //    cts = new CancellationTokenSource(10000); | ||||
|             //    UPNPdevice = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts); | ||||
|             //    await UPNPdevice.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1234, 4321, "UPnP Server Map")); | ||||
|             //    Task<IEnumerable<Mapping>> MappingDevice = device.GetAllMappingsAsync(); | ||||
|             //    Debug.WriteLine("MappingDevice.Result: " + MappingDevice.Result.ToList()[0]); | ||||
|             //} | ||||
|             //catch (Exception ex) | ||||
|             //{ | ||||
|             //    Debug.WriteLine("Error Occured: " + ex.GetType().ToString() + " : " + ex.Message); | ||||
|             //} | ||||
|         } | ||||
|  | ||||
|         public void ResetServer(bool ServerIsStarted) | ||||
| @@ -247,7 +216,7 @@ Client has been detected as being disconnected! | ||||
|                 worker.WorkerSupportsCancellation = true; | ||||
|                 worker.CancelAsync(); | ||||
|  | ||||
|                 worker.Dispose(); // dont know if this actually disposes the thing, but it seems to run the code above, so its fine! | ||||
|                 worker.Dispose();  | ||||
|                 LogAdd("Client Disconnected"); | ||||
|                 LogAdd("Restarting Server"); | ||||
|             } | ||||
| @@ -282,14 +251,12 @@ Server has been shutdown by the user and is now offline! | ||||
|                 worker.DoWork -= ListenToClient; | ||||
|                 worker.RunWorkerCompleted -= Worker_RunWorkerCompleted; | ||||
|  | ||||
|                 worker.Dispose(); // dont know if this actually disposes the thing, but it seems to run the code above, so its fine! | ||||
|                 worker.Dispose();  | ||||
|                 LogAdd("Server Shut Down By Host"); | ||||
|                 LogAdd("Worker Temporarily Deactivated"); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         //Point mousePoint; | ||||
|         //Point tempMousePoint; | ||||
|         BackgroundWorker worker; | ||||
|         public /*async*/ void Initialize() | ||||
|         { | ||||
| @@ -298,26 +265,11 @@ Server has been shutdown by the user and is now offline! | ||||
|                 IPstring = GetLocalNetworkIPV4(); | ||||
|                 IPLabel.Text = "IP: " + IPstring; | ||||
|  | ||||
|                 //localIP = Dns.GetHostAddresses(Dns.GetHostName()); | ||||
|                 //foreach (IPAddress address in localIP) //OLD DEPRICATED METHOD | ||||
|                 //{ | ||||
|                 //    if (address.AddressFamily == AddressFamily.InterNetwork) | ||||
|                 //    { | ||||
|                 //        IPstring = address.ToString(); | ||||
|                 //        IPstring = "192.168.1.5"; | ||||
|                 //        Debug.WriteLine(IPstring); | ||||
|  | ||||
|                 //    } | ||||
|                 //} | ||||
|  | ||||
|                 //Debug.WriteLine("CONNECT USING: " + IPstring); | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 Debug.WriteLine("Error Occured: " + ex.GetType().ToString() + " : " + ex.Message); | ||||
|                 LogAdd("Exception Thrown: " + ex.GetType() + ":" + ex.Message); | ||||
|             } //isnt even catching... | ||||
|         } | ||||
|  | ||||
|  | ||||
| @@ -355,7 +307,7 @@ Started listening requests at: {0}:{1} | ||||
|                 Console.WriteLine("Connected toTCP_client!" + " \n"); | ||||
|  | ||||
|  | ||||
|                 Console.WriteLine("Client: " + (TCP_client.Client.RemoteEndPoint as IPEndPoint).Address + ":" + (TCP_client.Client.RemoteEndPoint as IPEndPoint).Port); //IMPORTANT FOR GETTINGTCP_client IP AND PORT!!! | ||||
|                 Console.WriteLine("Client: " + (TCP_client.Client.RemoteEndPoint as IPEndPoint).Address + ":" + (TCP_client.Client.RemoteEndPoint as IPEndPoint).Port); | ||||
|                 LogAdd("Client: " + (TCP_client.Client.RemoteEndPoint as IPEndPoint).Address + ":" + (TCP_client.Client.RemoteEndPoint as IPEndPoint).Port + " Connected to the Server"); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
| @@ -370,12 +322,11 @@ Started listening requests at: {0}:{1} | ||||
|                 LogAdd("Exception Thrown: " + ex.GetType() + ":" + ex.Message); | ||||
|             } | ||||
|  | ||||
|             while (TCP_client.Connected /*&& !e.Cancel*/) | ||||
|             while (TCP_client.Connected) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     //const int bytesize = 1024 * 1024; | ||||
|                     int bytesize = 1024; //1024 * 1024 is way too much for the text based transfering! | ||||
|                     int bytesize = 1024; | ||||
|                     byte[] buffer = new byte[bytesize]; | ||||
|                     string networkRead =TCP_client.GetStream().Read(buffer, 0, bytesize).ToString(); | ||||
|                     string data = ASCIIEncoding.ASCII.GetString(buffer); | ||||
| @@ -383,7 +334,7 @@ Started listening requests at: {0}:{1} | ||||
|  | ||||
|                     LogAdd("Incoming Data: " + data); | ||||
|  | ||||
|                     if (data.ToUpper().Contains("{TEST}")) //toupper isnt really needed but is added just incase i forget to in the other program, also may remove later | ||||
|                     if (data.ToUpper().Contains("{TEST}")) | ||||
|                     { | ||||
|                         sendData(getBytes("{TEST_RESPOND}"),TCP_client.GetStream()); | ||||
|                         Console.WriteLine("DETECTED \"TEST\""); | ||||
| @@ -448,15 +399,11 @@ Started listening requests at: {0}:{1} | ||||
|                         sendData(getBytes("{PC_LOCK_STATUS}" + PCLocked.ToString().ToLower() + "{/PC_LOCK_STATUS}"),TCP_client.GetStream()); | ||||
|                         LogAdd("Getting & Sending PC Lock Status"); | ||||
|                     } | ||||
|                     //else if (data.ToUpper().Contains("PING")) | ||||
|                     //{ | ||||
|                     //    Ping(); | ||||
|                     //} | ||||
|                 } | ||||
|                 catch (Exception ex) | ||||
|                 { | ||||
|                     Debug.WriteLine("Exception WHILE Listening: " + ex.Message); | ||||
|                    TCP_client.GetStream().Close(); //changedTCP_client.Dispose to being afterTCP_client.Close because that seems to make more sense. Also need to restart the server instead of just closing theTCP_client. | ||||
|                    TCP_client.GetStream().Close();  | ||||
|                    TCP_client.Close(); | ||||
|                    TCP_clientIsOpen = false; | ||||
|                     LogAdd("Exception Thrown: " + ex.GetType() + ":" + ex.Message); | ||||
| @@ -469,10 +416,7 @@ Started listening requests at: {0}:{1} | ||||
|              | ||||
|             Debug.WriteLine("a screenshot was taken"); | ||||
|  | ||||
|             var bitmap = SaveScreenshotWithMousePointer();//SaveScreenshot(); | ||||
|             //var bitmap = SaveScreenshot(); | ||||
|             //bitmap = new Bitmap(bitmap, new Size(854, 480));//new Size(1024, 576));//new Size(512, 288)); //new Size(640, 360)); //new Size(1280, 720)); | ||||
|             //bitmap = new Bitmap(bitmap, new Size(1920, 1080)); | ||||
|             var bitmap = SaveScreenshotWithMousePointer(); | ||||
|             bitmap = new Bitmap(bitmap, new Size(1280, 720)); | ||||
|  | ||||
|             var stream = new MemoryStream(); | ||||
| @@ -480,7 +424,6 @@ Started listening requests at: {0}:{1} | ||||
|             Debug.WriteLine("Getting stream size: " + stream.Length); | ||||
|  | ||||
|             sendData(stream.ToArray(),TCP_client.GetStream()); | ||||
|             //UDP_client.Send(stream.ToArray(), (int)stream.Length, UDP_ipEP); | ||||
|  | ||||
|             bitmap.Dispose(); | ||||
|             LogAdd("Taking & Sending Screenshot"); | ||||
| @@ -501,11 +444,6 @@ Started listening requests at: {0}:{1} | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         //void Test() | ||||
|         //{ | ||||
|         //    Debug.WriteLine("test ran"); | ||||
|         //} | ||||
|  | ||||
|         void Shutdown() | ||||
|         { | ||||
|             sendData(getBytes("{BEGAN_SHUTDOWN}"),TCP_client.GetStream()); | ||||
| @@ -515,16 +453,6 @@ Started listening requests at: {0}:{1} | ||||
|             Process.Start(psi); | ||||
|         } | ||||
|  | ||||
|         //void Ping() | ||||
|         //{ | ||||
|         //    Debug.WriteLine("Ping Ran"); | ||||
|         //    sendData(getBytes("{PING}:{" + (((DateTime.Now.Minute * 60) + DateTime.Now.Second * 1000) + DateTime.Now.Millisecond).ToString() + "}:{PING}"),TCP_client.GetStream()); | ||||
|  | ||||
|         //    Debug.WriteLine(getBetween("{PING}:{" + (((DateTime.Now.Minute * 60) + DateTime.Now.Second * 1000) + DateTime.Now.Millisecond).ToString() + "}:{PING}", "{PING}:{", "}:{PING}")); | ||||
|  | ||||
|  | ||||
|         //} | ||||
|  | ||||
|         #region Screenshot Capture | ||||
|         public static class User32 | ||||
|         { | ||||
| @@ -752,7 +680,7 @@ Started listening requests at: {0}:{1} | ||||
|                     UDP_client.Close(); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception) { } //no need to log if we just gonna kill it anyways | ||||
|             catch (Exception) { } | ||||
|  | ||||
|             if (TCP_listener != null) | ||||
|             { | ||||
| @@ -841,16 +769,6 @@ Started listening requests at: {0}:{1} | ||||
|  | ||||
|         private void TCP_PortTextBox_KeyUp(object sender, EventArgs e) | ||||
|         { | ||||
|             //if (string.IsNullOrWhiteSpace(TCP_PortTextBox.Text) || string.IsNullOrEmpty(TCP_PortTextBox.Text)) | ||||
|             //{ | ||||
|             //    return; | ||||
|             //} | ||||
|  | ||||
|             //if (!(UDP_PortTextBox.TextLength > 0)) | ||||
|             //{ | ||||
|             //    StartButton.Enabled = false; | ||||
|             //    return; | ||||
|             //} | ||||
|  | ||||
|             if (TCP_PortTextBox.TextLength > 0 && UDP_PortTextBox.TextLength > 0) | ||||
|             { | ||||
| @@ -863,11 +781,6 @@ Started listening requests at: {0}:{1} | ||||
|             } | ||||
|             else | ||||
|                 StartButton.Enabled = false; | ||||
|  | ||||
|             //if (!((int.Parse(TCP_PortTextBox.Text) < 1 || int.Parse(TCP_PortTextBox.Text) > 65535) || (int.Parse(UDP_PortTextBox.Text) < 1 || int.Parse(UDP_PortTextBox.Text) > 65535))) | ||||
|             //{ | ||||
|             //    StartButton.Enabled = true; | ||||
|             //} | ||||
|         } | ||||
|  | ||||
|         private void UDP_PortTextBox_KeyPress(object sender, KeyPressEventArgs e) | ||||
| @@ -885,19 +798,7 @@ Started listening requests at: {0}:{1} | ||||
|  | ||||
|         private void UDP_PortTextBox_KeyUp(object sender, EventArgs e) | ||||
|         { | ||||
|             //if (string.IsNullOrWhiteSpace(UDP_PortTextBox.Text) || string.IsNullOrEmpty(UDP_PortTextBox.Text)) | ||||
|             //{ | ||||
|             //    return; | ||||
|             //} | ||||
|  | ||||
|             //if (!(TCP_PortTextBox.TextLength > 0)) | ||||
|             //{ | ||||
|             //    StartButton.Enabled = false; | ||||
|             //    return; | ||||
|             //} | ||||
|  | ||||
|             //Debug.WriteLine($"TCP {TCP_PortTextBox.TextLength} : UDP {UDP_PortTextBox.TextLength}"); | ||||
|  | ||||
|              | ||||
|             if (TCP_PortTextBox.TextLength > 0 && UDP_PortTextBox.TextLength > 0) | ||||
|             { | ||||
|                 if (int.Parse(TCP_PortTextBox.Text) > 0 && int.Parse(TCP_PortTextBox.Text) < 65536 && int.Parse(UDP_PortTextBox.Text) > 0 && int.Parse(UDP_PortTextBox.Text) < 65536) | ||||
| @@ -909,11 +810,6 @@ Started listening requests at: {0}:{1} | ||||
|             } | ||||
|             else | ||||
|                 StartButton.Enabled = false; | ||||
|  | ||||
|             //if (!((int.Parse(UDP_PortTextBox.Text) < 1 || int.Parse(UDP_PortTextBox.Text) > 65535) || (int.Parse(TCP_PortTextBox.Text) < 1 || int.Parse(TCP_PortTextBox.Text) > 65535))) | ||||
|             //{ | ||||
|             //    StartButton.Enabled = true; | ||||
|             //} | ||||
|         } | ||||
|  | ||||
|  | ||||
| @@ -961,35 +857,5 @@ Started listening requests at: {0}:{1} | ||||
|             } | ||||
|             //f2.LogTextBox.ScrollToCaret(); | ||||
|         } | ||||
|  | ||||
|         //public static void DisplayIPAddresses() //maybe keep | ||||
|         //{ | ||||
|         //    StringBuilder sb = new StringBuilder(); | ||||
|  | ||||
|         //    // Get a list of all network interfaces (usually one per network card, dialup, and VPN connection) | ||||
|         //    NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); | ||||
|  | ||||
|         //    foreach (NetworkInterface network in networkInterfaces) | ||||
|         //    { | ||||
|         //        // Read the IP configuration for each network | ||||
|         //        IPInterfaceProperties properties = network.GetIPProperties(); | ||||
|  | ||||
|         //        // Each network interface may have multiple IP addresses | ||||
|         //        foreach (IPAddressInformation address in properties.UnicastAddresses) | ||||
|         //        { | ||||
|         //            // We're only interested in IPv4 addresses for now | ||||
|         //            if (address.Address.AddressFamily != AddressFamily.InterNetwork) | ||||
|         //                continue; | ||||
|  | ||||
|         //            // Ignore loopback addresses (e.g., 127.0.0.1) | ||||
|         //            if (IPAddress.IsLoopback(address.Address)) | ||||
|         //                continue; | ||||
|  | ||||
|         //            sb.AppendLine(address.Address.ToString() + " (" + network.Name + ")"); | ||||
|         //        } | ||||
|         //    } | ||||
|  | ||||
|         //    MessageBox.Show(sb.ToString()); | ||||
|         //} | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										115
									
								
								src/Form3.cs
									
									
									
									
									
								
							
							
						
						
									
										115
									
								
								src/Form3.cs
									
									
									
									
									
								
							| @@ -17,14 +17,12 @@ using Microsoft.Win32; | ||||
| using KeyboardHookMain; | ||||
| using System.Security.Permissions; | ||||
| //This project is using JSON.NET | ||||
| namespace TCPCommander //need to make login form (form1), form for keybinding (form3), form for attempts and at what time (form4). (ALSO: Encrypt the keybind thingy but the logs can be left alone)  | ||||
| namespace TCPCommander //need to make login form (form1), form for keybinding (form3), form for attempts and at what time  | ||||
| { | ||||
|     public partial class Form3 : Form //Something may be causing the taskbar from hiding, if it happens again try to remove it. | ||||
|     public partial class Form3 : Form | ||||
|     { | ||||
|         public static bool isLocked = false; | ||||
|  | ||||
|         //private KeyboardHook.LowLevelKeyboardListener _listener; | ||||
|         //KeyboardHook2.KeyboardHookClass.i | ||||
|         private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); | ||||
|         private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); | ||||
|         private const UInt32 SWP_NOSIZE = 0x0001; | ||||
| @@ -32,7 +30,7 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|         private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; | ||||
|         [DllImport("user32.dll")] | ||||
|         [return: MarshalAs(UnmanagedType.Bool)] | ||||
|         public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); //THIS WINDOWS FN IS CAUSING THE TASKBAR FROM DISAPPEARING!!! NEED TO FIX IMMEDIATELY WHEN CAN! | ||||
|         public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); | ||||
|  | ||||
|         [DllImport("user32.dll")] | ||||
|         [return: MarshalAs(UnmanagedType.Bool)] | ||||
| @@ -58,41 +56,21 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|             base.WndProc(ref m); | ||||
|         } | ||||
|  | ||||
|         //Could be helpful, just not needed atm. | ||||
|         //void ActivateApp(string processName) | ||||
|         //{ | ||||
|         //    Process[] p = Process.GetProcessesByName(processName); | ||||
|  | ||||
|         //    // Activate the first application we find with this name | ||||
|         //    if (p.Count() > 0) | ||||
|         //        SetForegroundWindow(p[0].MainWindowHandle); | ||||
|         //} | ||||
|  | ||||
|         public Form3() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|         } | ||||
|  | ||||
|         //MouseMessageFilter mmf; | ||||
|  | ||||
|         Form[] z; | ||||
|         private void Form1_Load(object sender, EventArgs e) | ||||
|         { | ||||
|  | ||||
|             //BlockInput(true); | ||||
|             AutoScaleMode = AutoScaleMode.Font; | ||||
|             //this.Opacity = 0.0; //is called seperately | ||||
|             WindowState = FormWindowState.Maximized; | ||||
|             notifyIcon1.Icon = SystemIcons.Shield; | ||||
|  | ||||
|             SystemEvents.DisplaySettingsChanging += SystemEvents_DisplaySettingsChanging; | ||||
|  | ||||
|             //mmf = new MouseMessageFilter(); | ||||
|             //notifyIcon1.ContextMenuStrip = contextMenu1; //removed contextmenu so dk if needed? | ||||
|  | ||||
|             //MenuItem3.Enabled = false; //Make enabled when logged into admin page with logs and attempts. | ||||
|  | ||||
|             //Application.ApplicationExit += Application_ApplicationExit; dont think necessary | ||||
|         } | ||||
|  | ||||
|         int screenCount; | ||||
| @@ -104,8 +82,6 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|  | ||||
|                 for (int a = 0; a < z.Length; a++) | ||||
|                 { | ||||
|                     //Debug.WriteLine(z.Length); | ||||
|                     //Debug.WriteLine(a); | ||||
|                     if (z[a] != null) | ||||
|                     { | ||||
|                         z[a].Close(); | ||||
| @@ -115,9 +91,6 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|                 z = new Form[screenCount - 1]; | ||||
|                 for (int a = 0; a < z.Length; a++) | ||||
|                 { | ||||
|                     //Debug.WriteLine(Application.OpenForms.Count); | ||||
|  | ||||
|  | ||||
|                     z[a] = new Form(); | ||||
|                     z[a].FormBorderStyle = FormBorderStyle.None; | ||||
|                     z[a].BackColor = Color.Black; | ||||
| @@ -131,29 +104,14 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         //private void MenuItem3_Click(object sender, EventArgs e) | ||||
|         //{ | ||||
|         //    f3.ChangeKeybind(); | ||||
|         //Add Keybinder Here! //Open Keybinder in Admin Panel (dont make a new form) | ||||
|         //} | ||||
|  | ||||
|  | ||||
|         private void MenuItem4_Click(object sender, EventArgs e) | ||||
|         { | ||||
|             Application.Exit(); | ||||
|         } | ||||
|  | ||||
|         private void Timer1_Tick(object sender, EventArgs e) //THE TIMER IS CURRENTLY DISABLED CAUSE OF THE IMPLEMENTATION OF THE KEYBOARD HOOK | ||||
|         private void Timer1_Tick(object sender, EventArgs e)  | ||||
|         { | ||||
|             //if (Control.ModifierKeys == Keys.LWin || Control.ModifierKeys == Keys.RWin || Control.ModifierKeys == Keys.ControlKey || Control.ModifierKeys == Keys.Escape) | ||||
|             //{ | ||||
|             //    SetForegroundWindow(this.Handle); | ||||
|             //} | ||||
|  | ||||
|             //if (Control.ModifierKeys == Keys.Alt || Control.ModifierKeys == Keys.ControlKey) | ||||
|             //{ | ||||
|             //    SetForegroundWindow(this.Handle); | ||||
|             //} | ||||
|          | ||||
|         } | ||||
|  | ||||
|         public bool PreFilterMessage(ref Message m) | ||||
| @@ -166,8 +124,7 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|         public void LockPC() | ||||
|         { | ||||
|             this.Show(); | ||||
|             SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); //PLACES THE LOCKED PC MENU IN FRONT WHEN ENABLED, BUT WAS CHANGED FOR this.BringToFront(); BECAUSE IT CAUSES THE TASKBAR TO GLITCH OUT UNTIL THE PROGRAM IS CLOSED. | ||||
|             //Application.OpenForms["Form1"].BringToFront(); | ||||
|             SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);  | ||||
|  | ||||
|             Cursor.Hide(); | ||||
|  | ||||
| @@ -180,7 +137,7 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|              | ||||
|             this.Opacity = 1; | ||||
|  | ||||
|             notifyIcon1.Visible = true;  //This is working fsr look into... Looks like a windows thing. | ||||
|             notifyIcon1.Visible = true;  | ||||
|             notifyIcon1.BalloonTipTitle = ("Computer Lock"); | ||||
|             notifyIcon1.BalloonTipText = ("Your computer has been locked."); | ||||
|             notifyIcon1.ShowBalloonTip(5000); | ||||
| @@ -205,16 +162,8 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|                     z[a].SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             //KeyboardHookMain.KeyboardHook.LockedDownKeyboardKeyPressed += KeyboardHook_LockedDownKeyboardKeyPressed; //not needed really | ||||
|             //BlockInputMtd(TimeSpan.FromMilliseconds(10000)); | ||||
|         } | ||||
|  | ||||
|         //private void KeyboardHook_LockedDownKeyboardKeyPressed(object sender, KeyboardLockDownKeyPressedEventArgs e) | ||||
|         //{ | ||||
|         //    Debug.WriteLine("Key Pressed"); | ||||
|         //} | ||||
|  | ||||
|         public void UnlockPC() | ||||
|         { | ||||
|             this.Hide(); | ||||
| @@ -229,7 +178,7 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|  | ||||
|             notifyIcon1.BalloonTipTitle = "Computer Lock"; | ||||
|             notifyIcon1.BalloonTipText = "Your computer has been unlocked."; | ||||
|             notifyIcon1.ShowBalloonTip(5000); //This is working on an off as us 7/29/19 maybe just a bug during the session. | ||||
|             notifyIcon1.ShowBalloonTip(5000); | ||||
|             isLocked = false; | ||||
|  | ||||
|             for (int a = 0; a < z.Length; a++) | ||||
| @@ -265,11 +214,11 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|             { | ||||
|                 if (ShutdownBlockReasonDestroy(this.Handle)) | ||||
|                 { | ||||
|                     Debug.WriteLine("Shutdown abortion aborted."); | ||||
|                     Debug.WriteLine("Shutdown Reset"); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     Debug.WriteLine("Shutdown abortion couldn't be aborted."); | ||||
|                     Debug.WriteLine("Shutdown couldn't be reset"); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
| @@ -278,36 +227,15 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         //public static void BlockInputMtd(TimeSpan span) //BLOCKS INPUT SO HOOK CAN'T SEE IT, NEED TO FIND A WAY TO DETECT KEY PRESS WITHOUT LETTING KEY THROUGH. DELAY JUST WONT WORK. | ||||
|         //{ | ||||
|         //    try | ||||
|         //    { | ||||
|         //        BlockInput(true); | ||||
|         //        Thread.Sleep(span); | ||||
|         //    } | ||||
|         //    finally | ||||
|         //    { | ||||
|         //        BlockInput(false); | ||||
|         //    } | ||||
|  | ||||
|         //} | ||||
|  | ||||
|         private void Form1_Paint(object sender, PaintEventArgs e) | ||||
|         { | ||||
|             Pen p = new Pen(Color.White); //Add this to form2 and form3. Make thickness for all corners as it is only for the top ones. | ||||
|             Pen p = new Pen(Color.White); / | ||||
|             p.Width = 5; | ||||
|             Graphics g = e.Graphics; | ||||
|             g.DrawRectangle(p, new Rectangle(label1.Location.X - 5, label1.Location.Y - 5, label1.Width + 10, label1.Height + 10)); | ||||
|             g.DrawRectangle(p, new Rectangle(label2.Location.X - 5, label2.Location.Y - 5, label2.Width + 10, label2.Height + 10)); | ||||
|         } | ||||
|  | ||||
|         //private void Application_ApplicationExit(object sender, EventArgs e) | ||||
|         //{ | ||||
|         //    SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; | ||||
|         //    SystemEvents.SessionEnded -= SystemEvents_SessionEnded; | ||||
|         //    Application.ApplicationExit -= Application_ApplicationExit; | ||||
|         //} | ||||
|  | ||||
|         private void Form1_FormClosing(object sender, FormClosingEventArgs e) | ||||
|         { | ||||
|             notifyIcon1.BalloonTipClosed += (s, args) => | ||||
| @@ -319,25 +247,4 @@ namespace TCPCommander //need to make login form (form1), form for keybinding (f | ||||
|             }; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     //[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] | ||||
|     //public class MouseMessageFilter : IMessageFilter | ||||
|     //{ | ||||
|     //    public void EnableMouse() | ||||
|     //    { | ||||
|     //        Application.RemoveMessageFilter(this); | ||||
|     //    } | ||||
|     // | ||||
|     //    public void DisableMouse() | ||||
|     //    { | ||||
|     //        Application.AddMessageFilter(this); | ||||
|     //    } | ||||
|  | ||||
|         //public bool PreFilterMessage(ref Message m) //wanted to add cause its cool, but doesnt work and can degrade performance. Only thing that can occur is the user pressing the notify balloon tip | ||||
|         //{ | ||||
|         //    if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true; | ||||
|         //    if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true; | ||||
|         //    return false; | ||||
|         //} | ||||
|     //} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user