C# I want to access Windows Form app parts DataGridView from an external process

Asked 1 years ago, Updated 1 years ago, 141 views

Title, no changes to existing Windows Form apps,
from external processes We are investigating how to access (enter and load if possible) any cells in DataGridView of the Windows Form app.

The environment is Windows 10 for OS and 4.5.2 for .NET.

With Windows Message, you can access TextBox and Button. I have confirmed it (using SendMessage as follows).

 [DllImport("user32.dll", SetLastError=true)]
    public static external int SendMessage (IntPtrWnd, int msg, intwParam, intlParam);

However, I do not know how to access any cells in DataGridView.
If you have any know-how around here, please let me know whether you can access it or not.
Thank you for your cooperation.

c# winforms

2022-09-29 21:29

3 Answers

It seems to have been made with a software called UWSC that automates Windows operations.
However, I am currently out of touch with the author, and the site seems to be in a state of collapse.

CSWU~What to do with compatible systems without UWSC
UWSC Dictionary

GETSTR|UWSC Dictionary

UString=GETSTR (ID, [Number, Type, Mouse Move])
Type
  STR_ACC_CELL(5)
    Get Cell Values in DataGridView

SENDSTR|UWSC Dictionary

SENDSTR (ID, String, [Number, Transmit Mode, ACC Designated])
ACC designation
  STR_ACC_CELL(5)
    Changing Cell Values in DataGridView

There is a similar article in the English version, and although there is no resolution mark, there are answers with prize points.
Getting full contents of a Datagrid using UIAutomation
UI Automation not working for DataGridView
Answer with prize points
The above reference site WPF UI Automation/TreeScope Enum

This article is more similar, but it uses the same software called AutoIt as UWSC.
However, there is no resolution mark here either.
C#-Read datagridview of some application

DataGrid, the predecessor of DataGridView, seems to be able to access it using a feature called UI Automation, but DataGridView is not directly supported.
It seems that the answers in the English version above are written that both of them can be done with some ingenuity.
Support for DataGrid controlled with UI automation and D with UI automationIt may be a combination of ataItem controlled support.

add
In an old Python article, there was an introduction to a tool that could be used interactively.
UI Automation/UI Automation Part 2
on Python How to check AutomationElement

Inspect
Visual UI Automation Verify
For example, VSC 2017 seems to be around here.

"C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64\inspect.exe"
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64\UIAVerify\VisualUIAVerifyNative.exe"

Under "Windows Kits", there are multiple folders with the same name, depending on the number of Windows versions, SDK versions, .NET versions, CPU bits, architecture, and so on.


2022-09-29 21:29

If your partner is a Windows Form app, how about Friendly?

https://github.com/Codeer-Software/Friendly

Originally designed to automate UI testing, you can "get/set the value of any control in the external process" depending on how you do it.

Install the following two items on NuGet and you can use them at a minimum.

  • Coder.Friendly
  • Coder.Friendly.Windows


2022-09-29 21:29

When updated to .NET Framework 4.8 released today, the DataGridView also appears to support, UI Automation.According to the announcement,

Currently the accessible hierarchy (UI Automation tree) shows the editing box tree element as a child of currently edited cell but not as a root child element of DataGridView.

Therefore, it was already handled, and in 4.8 it was improved so that the hierarchical structure of the cell being edited could be obtained correctly.

When I tried displaying it in Inspect.exe included in the Windows SDK, I was able to get the display even before the .NET update.

Therefore, it seems that the direct attack method is to get it with UI Automation.


2022-09-29 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.