How does software like Spy++ get the information? - windows

I'm working on a software for test automation. To get it working it need's to "have a look" on the desktop and all open windows. It needs to know which windows are open and what controls they consist of. So it has to do something similar to what Spy++ is doing (Spy++ from Visual Studio).
Does anyone know how Spy ++ get's all the information?
Are there any Windows Methods one can call to retrieve information about open windows?

You can use EnumWindows to get all top level windows. Within the lpEnumFunc you can call FindWindowEx to get child windows/controls of each top level window and then any other interesting function that gives you information you need, e.g. GetClassName, GetClassInfo, GetClientRect etc. etc. Take a look here for more

It's called a windows hook. Checkout the Win32 API SetWindowHookEx.
There are different types of hooks, they reside in a DLL and that DLL function is called by Windows for the type of windows messages of a specific thread or all threads in the same desktop.
Please also see my related answer on Windows hooks here.

Related

How to hide terminal shell on server application like Warp in Windows?

I have a small warp server project on Windows that listen to a particular port and do something whenever I send a command to it by REST (for example: POST http://10.10.10.1:5000/print). It's a small client for printing PDF / receipt directly from another computer.
It works. But my problem is when I had to package the whole project, the Rust compiler give me an executable file (.exe). The application displays a terminal window when I run it. I want this terminal to be hidden somehow.
I try to run the program as a windows service (by using NSSM). It doesn't work for me since I had to access the printer. Windows doesn't allow my app to access any devices or any other executable as a windows service. (The reasons are explained here: How can I run an EXE program from a Windows Service using C#?)
So I plan to run my app as a tray-icon application so user can control or close the app. (https://github.com/olback/tray-item-rs)
Unfortunately, I still cannot hide the app's terminal window.
Another solution that I found is hstart (https://www.ntwind.com/software/hstart.html). But I would like to use this as "the last resort" solution since many antivirus/windows defender mark it as a malware.
Do anyone know how to hide or get rid of it ?
After lot of searching, It turns out to be easier than I thought. Just add
#![windows_subsystem = "windows"]
on top of your main.rs file. (for rust > 1.18) and the terminal is gone.
These control the /SUBSYSTEM flag in the linker. For now, only
"console" and "windows" are supported.
When is this useful? In the simplest terms, if you're developing a
graphical application, and do not specify "windows", a console window
would flash up upon your application's start. With this flag, it
won't.
https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute
https://blog.rust-lang.org/2017/06/08/Rust-1.18.html
https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170

Windows explorer monitors directory changes in a tricky way?

I have a sandbox system redirecting file modifications by hooking Ntxxx file system APIs. An interesting thing is, if i move files in Notepad->File/Open dialog in my sandbox, e.g. from desktop\a.txt to desktop\b\a.txt, the a.txt file on real desktop just disappears, and it comes back after i refresh real desktop by pressing F5. actually there is no change in desktop folder at all, because all changes are directed. I know that most apps use API like ReadDirectoryChanges to monitor changes, but apparently explorer is doing something different. I tried tools like https://directorymonitor.com/, they did not observe any changes on desktop. I guess SHFileOperation internally interact with explorer somehow, but who knows details and how can i prevent this notification? It is really strange for users to see a file disappearing while it is actually still there.
windows calls windows_storage!SHChangeNotify instead of that one in shell32. Why does Windows have two copies of same API, are they different?

How to record the event that an attachment from Outlook has been clicked to run or downloaded to the disk?

I am developing a solution to monitor security events on Windows.
Two of the events to monitor are:
an attachment from an email (Outlook) has been clicked to run or downloaded to the disk
a link from an email has been clicked
Does anyone have experience in how to achieving these two things?
There are at least two ways I can think of to do this.
Outlook Extension
The easiest is to write a script. The MailItem.BeforeAttachmentRead lets you see what the user is going to open/save, and even allows you to cancel it if you find it suspect. You can also use several other related event hooks to customize the experience (check the docs). No hardcore kernel-level programming is required.
Kernel Hook
You could also implement a generic file hook that runs in the background and reports activity from the Outlook executable, but this is probably more cumbersome than it needs to be. The Windows API allows you to monitor when files are created, but you wouldn't be able to see specifically when an attachment is previewed (as far as I could determine from the docs).
Either way, you can then deploy your package through a Group Policy Object so that it can be invisibly installed without the user's knowledge. Once installed, you can choose to log those attachments through the usual channels, such as an Event Log that can be viewed in the Event Viewer.

Windows 7 Taskbar Widget or Toolbar

My Lenovo laptop has two task bar type programs that show the network status and battery status. I have been trying to search for what these types of widgits are called. Unfortuantly my google-foo is only returning results for minimizing programs to the system tray.
I am not even sure if these are system tray apps or taskbar apps. but either way, please help me find a API reference or even better a tutorial.
I want to make a Work Week Widgit, that displays the current work week number on this widget. I program mostly in python, but am willing to learn another language just to make this tool.
They are known as Desktop Bands, also known as DeskBands. Note that Desktop Bands are not recommended starting in Windows 7. Note also that since they are shell extensions, they must be written in native code.

How to get a list of all open NSWindow from all running application?

Is there a way to get list of open or visible NSWindow from mac desktop?
Note that not all windows are necessarily NSWindows, and that NSWindow only provides an interface to windows in your own address space.
The supported way to access every window is the CGWindow API. Take a look at the Son of Grab sample code to see how it's done.
You can use the accessibility API (accessibility must be enabled under System Preferences for it to work) to get information on windows (and other UI elements) from other processes. This question might be just what you're looking for.
ALL running applications? No. You can only get the NSWindows of your own app. You may be able to use Universal Access or Core Graphics APIs to get some information about windows of other apps, but not full access.

Resources