针对上述情况,在实际信息化实施中,我们实现了对于没有源码的CS系统一种另类解决方式.
1\建立标准用户信息表,在单独的数据库中;
2\维护各应用系统的用户信息与标准用户信息做对照;
3\创建统一验证平台登录界面进行系统验证;
4\获取欲进入系统的真正用户名\密码信息,使用钩子技术进行传递,完成用户名\密码输入和校验.
这只是一个简单的原理,根据需要,还可能要增加各系统与统一验证平台之间用户名\密码统一的工作.
附件有两个例子:有兴趣的朋友可以看一下.
WinAppHOOK.exe 为集成验证平台原型.
WinAppMaster.exe 为子系统原型.
这个原型的功能,可以通过 WinAppHOOK填充 WinAppMaster的文本框和点击WinAppMaster的按钮.
WinAppHOOK代码
1
using System;
2
using System.Text;
3
using System.Drawing;
4
using System.Collections;
5
using System.ComponentModel;
6
using System.Windows.Forms;
7
using System.Runtime.InteropServices;
8
9
namespace WinAppHOOK
10
{
11
public partial class frmMain : Form
12
{
13
public frmMain()
14
{
15
InitializeComponent();
16
}
17
18
private void btnSendClick_Click(object sender, EventArgs e)
19
{
20
IntPtr hwnd_win;
21
IntPtr hwnd_button;
22
23
hwnd_win = FindWindow("WindowsForms10.Window.8.app.0.378734a", "Main");
24
hwnd_button = FindWindowEx(hwnd_win, new IntPtr(0), "WindowsForms10.BUTTON.app.0.378734a", "OK");
25
26
const int BM_CLICK = 0x00F5;
27
Message msg = Message.Create(hwnd_button, BM_CLICK, new IntPtr(0), new IntPtr(0));
28
PostMessage(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
29
30
}
31
32
private void btnSendText_Click(object sender, EventArgs e)
33
{
34
const int WM_CHAR = 0x0102;
35
const int WM_GETTEXT = 0x000D;
36
const int WM_SETTEXT = 0x000C;
37
const int WM_CLICK = 0x00F5;
38
string text = "";
39
40
IntPtr ParenthWnd = new IntPtr(0);
41
IntPtr EdithWnd = new IntPtr(0);
42
43
ParenthWnd = FindWindow("WindowsForms10.Window.8.app.0.378734a", "Main");
44
45
//得到User Name这个子窗体,并设置其内容
46
EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, "WindowsForms10.EDIT.app.0.378734a", "");
47
if (!EdithWnd.Equals(IntPtr.Zero))
48
{
49
text = "User";
50
//调用SendMessage方法设置其内容
51
SendMessage(EdithWnd, WM_SETTEXT, (IntPtr)0, text);
52
}
53
54
//得到Password这个子窗体,并设置其内容
55
EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, "WindowsForms10.EDIT.app.0.378734a", "");
56
if (!EdithWnd.Equals(IntPtr.Zero))
57
{
58
text = "Password";
59
SendMessage(EdithWnd, WM_SETTEXT, (IntPtr)0, text);
60
}
61
62
}
63
64
[DllImport("user32.dll")]
65
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
66
67
[DllImport("user32.dll")]
68
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
69
70
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
71
public static extern IntPtr PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
72
73
[DllImport("User32.dll", EntryPoint = "SendMessage")]
74
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, string lParam);
75
76
77
}
78
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

WinAppMaster代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinAppMaster
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
MessageBox.Show("Master单击");
}
}
}