Screenshot Blockieren?

  • VB.NET
  • .NET (FX) 4.0

Es gibt 24 Antworten in diesem Thema. Der letzte Beitrag () ist von Mokki.

    Screenshot Blockieren?

    Hallo, ich habe mich folgendes gefragt: Unzwar ist es möglich einen Screenshot von Programmen zu blockieren? Ich meine jetzt nicht die DRUCK taste, sondern Anwendungen(z.b. Trojaner) können ja auch Screenshots machen. Kann man dies Irgendwie verhinder? Im netz habe ich einiges gelesen das es nicht möglich wäre, dem kann ich aber nicht ganz zustimmen, denn die User Administration Control von Windows Blockiert während des Popups die Screenshot funktion, auch für jegliche anwendungen. Ich frage mich nun, gibt es da eine API die man darüber ansprechen kann?
    Hi,

    ich hab das selbst noch nicht versucht, aber schau dir das hier mal an ---> LINK
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Also damit kann ich nur die Drucktaste verhindern, aber nicht wenn eine Anwendung ein Screenshot Tätigt.

    Schamash schrieb:

    Hi,

    ich hab das selbst noch nicht versucht, aber schau dir das hier mal an ---> LINK



    Hmm irgendwie hilft das auch nicht wirklich weiter, also wenn ich z.b. ein Screenshot tätigen möchte während die UAC aufplopt kommt die Fehlermeldung.

    Mokki schrieb:

    Sollte hierdrin beschrieben sein:stackoverflow.com/questions/65…t-screenshot-from-program

    Lg Mokki
    Bilder
    • 1234.png

      34,99 kB, 853×315, 178 mal angesehen
    Also ich habe da jetzt was, hab es auch getestet. Nur kann ich kein C#, muss es also versuchen in VB umzuschreiben. ggf. kann ja jemand helfen der beide Sprachen kann :)

    Es wird mit dieser Funktion ein neuer Desktop erstellt. Dabei wird folgendes Blockiert:
    - Screenshots jeglicher art(Ob vom Programm oder mit der Drucktaste)
    - Keylogger Block

    C#-Quellcode

    1. using System;
    2. using System.Drawing;
    3. using System.Runtime.InteropServices;
    4. using System.Threading.Tasks;
    5. using System.Windows.Forms;
    6. namespace SecureDesktop
    7. {
    8. class Program
    9. {
    10. [DllImport("user32.dll")]
    11. public static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
    12. [DllImport("user32.dll")]
    13. private static extern bool SwitchDesktop(IntPtr hDesktop);
    14. [DllImport("user32.dll")]
    15. public static extern bool CloseDesktop(IntPtr handle);
    16. [DllImport("user32.dll")]
    17. public static extern bool SetThreadDesktop(IntPtr hDesktop);
    18. [DllImport("user32.dll")]
    19. public static extern IntPtr GetThreadDesktop(int dwThreadId);
    20. [DllImport("kernel32.dll")]
    21. public static extern int GetCurrentThreadId();
    22. enum DESKTOP_ACCESS : uint
    23. {
    24. DESKTOP_NONE = 0,
    25. DESKTOP_READOBJECTS = 0x0001,
    26. DESKTOP_CREATEWINDOW = 0x0002,
    27. DESKTOP_CREATEMENU = 0x0004,
    28. DESKTOP_HOOKCONTROL = 0x0008,
    29. DESKTOP_JOURNALRECORD = 0x0010,
    30. DESKTOP_JOURNALPLAYBACK = 0x0020,
    31. DESKTOP_ENUMERATE = 0x0040,
    32. DESKTOP_WRITEOBJECTS = 0x0080,
    33. DESKTOP_SWITCHDESKTOP = 0x0100,
    34. GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
    35. DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
    36. DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP),
    37. }
    38. static void Main(string[] args)
    39. {
    40. // old desktop's handle, obtained by getting the current desktop assigned for this thread
    41. IntPtr hOldDesktop = GetThreadDesktop(GetCurrentThreadId());
    42. // new desktop's handle, assigned automatically by CreateDesktop
    43. IntPtr hNewDesktop = CreateDesktop("RandomDesktopName", IntPtr.Zero, IntPtr.Zero, 0, (uint)DESKTOP_ACCESS.GENERIC_ALL, IntPtr.Zero);
    44. // switching to the new desktop
    45. SwitchDesktop(hNewDesktop);
    46. // Random login form: used for testing / not required
    47. string passwd = "";
    48. // running on a different thread, this way SetThreadDesktop won't fail
    49. Task.Factory.StartNew(() =>
    50. {
    51. // assigning the new desktop to this thread - so the Form will be shown in the new desktop)
    52. SetThreadDesktop(hNewDesktop);
    53. Form loginWnd = new Form();
    54. TextBox passwordTextBox = new TextBox();
    55. passwordTextBox.Location = new Point(10, 30);
    56. passwordTextBox.Width = 250;
    57. passwordTextBox.Font = new Font("Arial", 20, FontStyle.Regular);
    58. loginWnd.Controls.Add(passwordTextBox);
    59. loginWnd.FormClosing += (sender, e) => { passwd = passwordTextBox.Text; };
    60. Application.Run(loginWnd);
    61. }).Wait(); // waits for the task to finish
    62. // end of login form
    63. // if got here, the form is closed => switch back to the old desktop
    64. SwitchDesktop(hOldDesktop);
    65. // disposing the secure desktop since it's no longer needed
    66. CloseDesktop(hNewDesktop);
    67. Console.ReadLine();
    68. }
    69. }
    70. }



    //EDIT

    Konnte es mit einem Konverter und bisschen handarbeit es doch noch einigermaßen hinbekommen, diese erstelle form wird allerdings nicht angezeigt, weiß jemand wieso nicht?

    Spoiler anzeigen

    VB.NET-Quellcode

    1. ​Imports System.Runtime.InteropServices
    2. Imports System.Threading.Tasks
    3. Imports System.Drawing
    4. Imports System.Windows.Forms
    5. Module Module1
    6. <DllImport("user32.dll")> _
    7. Public Function CreateDesktop(ByVal lpszDesktop As String, ByVal lpszDevice As IntPtr, ByVal pDevmode As IntPtr, ByVal dwFlags As Integer, ByVal dwDesiredAccess As UInteger, ByVal lpsa As IntPtr) As IntPtr
    8. End Function
    9. <DllImport("user32.dll")> _
    10. Private Function SwitchDesktop(ByVal hDesktop As IntPtr) As Boolean
    11. End Function
    12. <DllImport("user32.dll")> _
    13. Public Function CloseDesktop(ByVal handle As IntPtr) As Boolean
    14. End Function
    15. <DllImport("user32.dll")> _
    16. Public Function SetThreadDesktop(ByVal hDesktop As IntPtr) As Boolean
    17. End Function
    18. <DllImport("user32.dll")> _
    19. Public Function GetThreadDesktop(ByVal dwThreadId As Integer) As IntPtr
    20. End Function
    21. <DllImport("kernel32.dll")> _
    22. Public Function GetCurrentThreadId() As Integer
    23. End Function
    24. Private Enum DESKTOP_ACCESS As UInteger
    25. DESKTOP_NONE = 0
    26. DESKTOP_READOBJECTS = &H1
    27. DESKTOP_CREATEWINDOW = &H2
    28. DESKTOP_CREATEMENU = &H4
    29. DESKTOP_HOOKCONTROL = &H8
    30. DESKTOP_JOURNALRECORD = &H10
    31. DESKTOP_JOURNALPLAYBACK = &H20
    32. DESKTOP_ENUMERATE = &H40
    33. DESKTOP_WRITEOBJECTS = &H80
    34. DESKTOP_SWITCHDESKTOP = &H100
    35. GENERIC_ALL = (DESKTOP_READOBJECTS Or DESKTOP_CREATEWINDOW Or DESKTOP_CREATEMENU Or DESKTOP_HOOKCONTROL Or DESKTOP_JOURNALRECORD Or DESKTOP_JOURNALPLAYBACK Or DESKTOP_ENUMERATE Or DESKTOP_WRITEOBJECTS Or DESKTOP_SWITCHDESKTOP)
    36. End Enum
    37. Sub Main()
    38. ' old desktop's handle, obtained by getting the current desktop assigned for this thread
    39. Dim hOldDesktop As IntPtr = GetThreadDesktop(GetCurrentThreadId())
    40. ' new desktop's handle, assigned automatically by CreateDesktop
    41. Dim hNewDesktop As IntPtr = CreateDesktop("RandomDesktopName", IntPtr.Zero, IntPtr.Zero, 0, CUInt(DESKTOP_ACCESS.GENERIC_ALL), IntPtr.Zero)
    42. ' switching to the new desktop
    43. SwitchDesktop(hNewDesktop)
    44. ' Random login form: used for testing / not required
    45. Dim passwd As String = ""
    46. ' running on a different thread, this way SetThreadDesktop won't fail
    47. ' assigning the new desktop to this thread - so the Form will be shown in the new desktop)
    48. Task.Factory.StartNew(Function() SetThreadDesktop(hNewDesktop)).Wait()
    49. Dim loginWnd As New Form()
    50. Dim passwordTextBox As New TextBox()
    51. passwordTextBox.Location = New Point(10, 30)
    52. passwordTextBox.Width = 250
    53. passwordTextBox.Font = New Font("Arial", 20, FontStyle.Regular)
    54. loginWnd.Controls.Add(passwordTextBox)
    55. Application.Run(loginWnd)
    56. AddHandler loginWnd.FormClosing, Function(sender, e)
    57. passwd = passwordTextBox.Text
    58. End Function
    59. ' waits for the task to finish
    60. ' end of login form
    61. ' if got here, the form is closed => switch back to the old desktop
    62. SwitchDesktop(hOldDesktop)
    63. ' disposing the secure desktop since it's no longer needed
    64. CloseDesktop(hNewDesktop)
    65. Console.ReadLine()
    66. End Sub
    67. End Module

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Mr. Johny“ ()

    Des ist für Konsolenanwendungen geschrieben. Ev. deshalb...

    Zu meinem Link: Hast du alles gelesen(damit mein ich auch die Kommentare)? Ich denk nicht wirklich...
    Aber die Lösung oben ist ja aich super.

    Lg Mokki
    ​Smartnotr - ein intelligentes Notizprogramm
    zum Thread

    Mr. Johny schrieb:

    weiß jemand wieso nicht?

    Dein VB-StartNew ist ein hohler Vogel, der C#-StartNew ist eine lange anonyme Funktion.
    Vielleicht machst Du aus der anonymen Funktion eine richtige, da verstehst Du auch die Abläufe besser.Gemeint ist der Inhalt der geschweiften Klammern:

    C#-Quellcode

    1. Task.Factory.StartNew(() =>
    2. {
    3. // ... dies hier
    4. }
    Das wird bei Dir erst aufgerufen, wenn der Desktop bereits läuft.
    ====
    Das

    VB.NET-Quellcode

    1. Application.Run(loginWnd)
    ist auch eine Zeile zu weit hoch geraten.
    ====
    @Mokki Diese App kann man auch einfach abbechen, indem der Dialog geschlossen wird. Da müsste schon noch getestet werden, ob das Passwort korrekt ist.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @Mokki Sorry, ich hab Deinen Link nicht verfolgt, ich nahm an, @Mr. Johny 's Code käme von da.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Hier für diejenigen die es für VB haben möchten.

    Spoiler anzeigen

    VB.NET-Quellcode

    1. ​Imports System.Runtime.InteropServices
    2. Imports System.Threading.Tasks
    3. Imports Microsoft.Win32
    4. Module SecureDesktop
    5. <DllImport("user32.dll")> _
    6. Public Function CreateDesktop(ByVal lpszDesktop As String, ByVal lpszDevice As IntPtr, ByVal pDevmode As IntPtr, ByVal dwFlags As Integer, ByVal dwDesiredAccess As UInteger, ByVal lpsa As IntPtr) As IntPtr
    7. End Function
    8. <DllImport("user32.dll")> _
    9. Private Function SwitchDesktop(ByVal hDesktop As IntPtr) As Boolean
    10. End Function
    11. <DllImport("user32.dll")> _
    12. Public Function CloseDesktop(ByVal handle As IntPtr) As Boolean
    13. End Function
    14. <DllImport("user32.dll")> _
    15. Public Function SetThreadDesktop(ByVal hDesktop As IntPtr) As Boolean
    16. End Function
    17. <DllImport("user32.dll")> _
    18. Public Function GetThreadDesktop(ByVal dwThreadId As Integer) As IntPtr
    19. End Function
    20. <DllImport("kernel32.dll")> _
    21. Public Function GetCurrentThreadId() As Integer
    22. End Function
    23. Private Enum DESKTOP_ACCESS As UInteger
    24. DESKTOP_NONE = 0
    25. DESKTOP_READOBJECTS = &H1
    26. DESKTOP_CREATEWINDOW = &H2
    27. DESKTOP_CREATEMENU = &H4
    28. DESKTOP_HOOKCONTROL = &H8
    29. DESKTOP_JOURNALRECORD = &H10
    30. DESKTOP_JOURNALPLAYBACK = &H20
    31. DESKTOP_ENUMERATE = &H40
    32. DESKTOP_WRITEOBJECTS = &H80
    33. DESKTOP_SWITCHDESKTOP = &H100
    34. GENERIC_ALL = (DESKTOP_READOBJECTS Or DESKTOP_CREATEWINDOW Or DESKTOP_CREATEMENU Or DESKTOP_HOOKCONTROL Or DESKTOP_JOURNALRECORD Or DESKTOP_JOURNALPLAYBACK Or DESKTOP_ENUMERATE Or DESKTOP_WRITEOBJECTS Or DESKTOP_SWITCHDESKTOP)
    35. End Enum
    36. Friend Function StartSecureWindow(ByVal frm As Form)
    37. ' old desktop's handle, obtained by getting the current desktop assigned for this thread
    38. Dim hOldDesktop As IntPtr = GetThreadDesktop(GetCurrentThreadId())
    39. ' new desktop's handle, assigned automatically by CreateDesktop
    40. Dim hNewDesktop As IntPtr = CreateDesktop("RandomDesktopName", IntPtr.Zero, IntPtr.Zero, 0, CUInt(DESKTOP_ACCESS.GENERIC_ALL), IntPtr.Zero)
    41. ' switching to the new desktop
    42. SwitchDesktop(hNewDesktop)
    43. ' Random login form: used for testing / not required
    44. Dim passwd As String = ""
    45. ' running on a different thread, this way SetThreadDesktop won't fail
    46. ' assigning the new desktop to this thread - so the Form will be shown in the new desktop)
    47. Task.Factory.StartNew(Function()
    48. SetThreadDesktop(hNewDesktop)
    49. AddHandler frm.FormClosing, Function(sender, e)
    50. Application.Exit()
    51. End Function
    52. Application.Run(frm)
    53. End Function).Wait()
    54. ' waits for the task to finish
    55. ' end of login form
    56. ' if got here, the form is closed => switch back to the old desktop
    57. SwitchDesktop(hOldDesktop)
    58. ' disposing the secure desktop since it's no longer needed
    59. CloseDesktop(hNewDesktop)
    60. Process.GetCurrentProcess().Kill()
    61. 'Console.ReadLine()
    62. End Function
    63. End Module

    Mr. Johny schrieb:

    für VB
    Geht das auch in Option Strict On?
    Wie muss das aufgerufen werden?
    Waas passiert mit dem Passwort?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @Mokki Im vorigen Code wurde das noch verwendet, @Mr. Johny hat inzwischen viel editiert und m.E. zuviel weggenommen oder ausgelagerten Code nicht gepostet.
    Die Variable passwd wird nicht verwendet.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Die Variable wurde davor nur verwendet um aus einer Passwortform die Eingabe in eine Variable zu speichern u. danach die Variable zu vergessen. Und die Passwortform wurde nur deshalb erstellt damit eine Form auf dem neune Desktop liegt.

    Lg Mokki
    ​Smartnotr - ein intelligentes Notizprogramm
    zum Thread

    Mokki schrieb:

    verwendet
    Das ist mir vollständig bewusst.
    @Mr. Johny war so frei, seinen unvollständigen und somit verstümmelten Off-Code in Post #13 als fertige Lösung anzubieten. Das habe ich hinterfragt.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Also, ich habe das mit der passwordform entfernt, da es aus einem Beispiel Projekt stammt wo demonstriert werden soll das der Secure Desktop vor Keylogger sicher ist. Ich habe den Code so angepasst das man ihn als Module in seine Anwendung einbauen kann und eine belibige Form seiner Wahl in den Secure Desktop starten kann.