Click here to Skip to main content
16,018,264 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My project can't shows lock screen after connection using tcp IP and Port even if the remote computer is already locked.


Do not shows lock screen after connection even if the remote computer is already unlocked then show screen.

What I have tried:

C#
TimeSpan TS = DateTime.Now - LastEventTime;
                   if (TS.TotalMinutes   > 10) KeepMachineAwake();
                   if (!this.Sleep && this.LoggedIn)
                   {
                       BinaryFormatter bFormat = new BinaryFormatter();
                       try
                       {
                           if (this.ScreenClientX != Screen.PrimaryScreen.Bounds.Width || this.ScreenClientY != Screen.PrimaryScreen.Bounds.Height) WriteScreenSize();
                           this.SleepCount = 0;
                           SendClipboard();
                           Bitmap screeny = new Bitmap(this.ScreenServerX + this.Padding, this.ScreenServerY + this.Padding, this.ImageResoloution);
                           Graphics theShot = Graphics.FromImage(screeny);
                           Stage = "Got Screen";
                           System.Drawing.Size Sz = new System.Drawing.Size(this.ScreenServerX + this.Padding, this.ScreenServerY + this.Padding);
                           theShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, this.Padding, this.Padding, Sz, CopyPixelOperation.SourceCopy);
                           this.IsMetro = Helper.IsMetro(screeny);
                           if (this.Scale)//In effect we reduce the size of the image that we are sending back to the client
                               screeny = ResizeImage(screeny, this.ScreenServerX / 2, this.ScreenServerY / 2);
                           Stage = "Copy Screen";
                           int X = 0; int Y = 0;
                           Color CursorColor = WinCursor.CaptureCursor(ref X, ref Y, theShot, this.ScreenServerX, this.ScreenServerY);
                           screeny.SetPixel(0, 0, CursorColor);
                           if (this.IsMetro)
                               screeny.SetPixel(0, 1, Color.Black);
                           else
                               screeny.SetPixel(0, 1, Color.Red);
                           {
                               if (this.Encrypted)
                               {//Send as a encrypted memory stream
                                   MemoryStream MS = Encrypt(screeny);
                                   bFormat.Serialize(CStream, MS);
                               }
                               else
                                   bFormat.Serialize(CStream, screeny);
}
Stage = "Serialize Screen";
                           SleepDelay();//Pause for a bit but wake up early if the client sends a mouse click or something so we can send the desctop back early
                           theShot.Dispose();
                           screeny.Dispose();
                       }
                       catch (Exception Ex1)
                       {}
Posted
Updated 7-Sep-24 21:12pm
v2
Comments
Dave Kreskowiak 9-Sep-24 8:51am    
Can I tell you how to do what I described below? No. I have no example code for what you're doing.
AB Masud 10-Sep-24 3:20am    
1. My server listener port(2000) App running. 2. Client connected to server like RDP but not using RDP protocol. Problem, when Server lock ,client disconnect display but tcp connect

1 solution

Assuming your "project" is some kind of Remote Desktop app, you have some work to do. The problem stems from you not knowing how Windows works.

Your app works only on the User Desktop, the Desktop the user interacts with and all the apps they launch can show their UI. Your app can see and get bits from the User Desktop all it wants. Each user has their own Desktop. This is how you can have multiple people remoting into a Windows Server and everybody can see only their own Desktop.

The problem is the Lock Screen is running on its own Desktop, which is owned by the system. Your app needs to be able to know which Desktop is being shown and how to get at it.

About Window Stations and Desktops - Win32 apps | Microsoft Learn[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900