公文一键排版系统基本完成,准备继续完善SysInfo,增加用户帐户信息,其中涉及到Win32_Account结构,其C++定义如下:
[Dynamic, Provider("CIMWin32"), UUID("{8502C4CC-5FBB-11D2-AAC1-006008C78BC7}"), AMENDMENT] class Win32_UserAccount : Win32_Account { uint32 AccountType; string Caption; string Description; boolean Disabled; string Domain; string FullName; datetime InstallDate; boolean LocalAccount; boolean Lockout; string Name; boolean PasswordChangeable; boolean PasswordExpires; boolean PasswordRequired; string SID; uint8 SIDType; string Status; };
由于WMI使用的是UniCode(WCHAR),所以我们在MASM32中要将以上成员属性AccountType、Caption……按DW UniCode(WCHAR)来定义,如下:
AccountType dw 'A','c','c','o','u','n','t','T','y','p','e', 0, 0 Caption dw 'C','a','p','t','i','o','n', 0, 0 Description dw 'D','e','s','c','r','i','p','t','i','o','n', 0, 0 Disabled dw 'D','i','s','a','b','l','e','d', 0, 0 Domain dw 'D','o','m','a','i','n', 0, 0 FullName dw 'F','u','l','l','N','a','m','e', 0, 0 InstallDate dw 'I','n','s','t','a','l','l','D','a','t','e', 0, 0 LocalAccount dw 'L','o','c','a','l','A','c','c','o','u','n','t', 0, 0 Lockout dw 'L','o','c','k','o','u','t', 0, 0 Name dw 'N','a','m','e', 0, 0 PasswordChangeable dw 'P','a','s','s','w','o','r','d','C','h','a','n','g','e','a','b','l','e', 0, 0 PasswordExpires dw 'P','a','s','s','w','o','r','d','E','x','p','i','r','e','s', 0, 0 PasswordRequired dw 'P','a','s','s','w','o','r','d','R','e','q','u','i','r','e','d', 0, 0 SID dw 'S','I','D', 0, 0 SIDType dw 'S','I','D','T','y','p','e', 0, 0 Status dw 'S','t','a','t','u','s', 0, 0
虽然MASM32 在QEDITOR 的 Conversions里提供了Text to DW UNICODE菜单项功能,但这个菜单项还不能实现自动从类中提出成员属性名称并转换为MASM32的DW UNICODE字符串的格式,所以我们还是先得手工将AccountType、Caption……提取出来。
成员少还行,成员多的话就太麻烦了。
于是用HTML+JavaScript写了一个简单的转换工具,运行效果如下:
完整代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content="PurpleEndurer"> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>ANSI String 2 MASM32 DW UniCode String</title> </head> <body> <table> <caption> <P style="color:purple;font:18pt bold;">ANSI String 2 MASM32 DW UniCode String <input type="button" value="转换" onclick="tran()"></P> </caption> <tr> <td> <P align="center">ANSI 字符串</P> </td> <td> <P align="center">MASM32 DW UniCode String</P> </td> </tr> <tr> <td> <textarea id="taAnsi" rows="50" cols="40" align="left"> uint32 AccountType; string Caption; string Description; boolean Disabled; string Domain; string FullName; datetime InstallDate; boolean LocalAccount; boolean Lockout; string Name; boolean PasswordChangeable; boolean PasswordExpires; boolean PasswordRequired; string SID; uint8 SIDType; string Status; </textarea> </td> <td> <textarea id="taUni" rows="50" cols="90"></textarea> </td> </tr> </table> <script> //功能:删除字符串中的所有空格 //记录:20230726创建 String.prototype.eliminateSpace = function() { return this.replace(/\s*/g,""); } //去除首尾空格 String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); /*var t = this.replace(/(^\s*)|(\s*$)/g, ""); return t =t.replace(/(^ *)|( *$)/g, ""); */ } //功能:将ANSI字符串转换成MASM32 Unicode字符串 //记录:20230811建 //输入:s=ANSI字符串 //输出:MASM32 DW Unicode字符串 function ansiStr2UniStr(s) { var r = s.split(''); //document.write(r+"<br>"); return " dw '" + r.join("','") + "', 0, 0"; }//ansiStr2UniStr(s) function getItem(a) { var s = a.split(' '); var j = 0; while (j < s.length) { if (''==s[j].eliminateSpace()) { s.pop(); } else { j++; } }//while return s; } //getItem(a) var taAnsi = document.getElementById('taAnsi'); var taUni = document.getElementById('taUni'); function tran() { var a = taAnsi.value.replace('\t',' ').split('\n'); for (var i = 0; i < a.length; i++) { a[i] = a[i].trim(); if (';'==a[i][a[i].length-1]) { a[i]=a[i].substr(0,a[i].length-1); } a[i] = getItem(a[i]); if (1< a[i].length) { taUni.value += a[i][1] + ansiStr2UniStr(a[i][1]) + "\n"; } }//for }//tran() </script> </body> </html>