一直以来,在X7之前的版本如果需要获取当前电脑用户名,都是不能直接取得的,需要借助其他方法间接实现,一般有如下3种方法比较常用,各方法的优缺点如下:
A:通过后处理运行vbs脚本及buff缓冲器来获取当前电脑用户名。
缺点:效率低,容易引发脚本运行失败的问题,后处理变大,不能实时返回数据,需要通过buff来获取,不方便移植,功能相对单一。
B:通过后处理运行控制台程序获取当前电脑用户名。
缺点:不能实时返回相关数据
C:通过后处理运行dll文件来获取当前电脑用户名。
缺点:低版本受系统32bit,64bit影响,高版本无影响。
Mastercam X7版本之后,支持通过相关后处理新功能获取当前电脑用户名。
以下为新函数的使用说明。
函数名:sysinfo
用法:susername = sysinfo(1, 3)
以下为官方对sysinfo函数的详细说明
str1 = sysinfo(*val1, val2)
val1 = return 0 on failure, 1 if success
val2 = option for function (mode)
str1 = return string based on val2
Option 0 = NameUnknown - An unknown name type, really
Option 1 = NameFullyQualifiedDN - The fully-qualified distinguished name(for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com)
Option 2 = NameSamCompatible - A legacy account name (for example, Engineering\JSmith). The domain-only version includes trailing backslashes (\\)
Option 3 = NameDisplay - A "friendly" display name (for example, Jeff Smith). The display name is not necessarily the defining relative distinguished name (RDN)
Option 4 = NameUniqueId - A GUID string that the IIDFromString function returns (for example, {4fa050f0-f561-11cf-bdd9-00aa003a77b6})
Option 5 = NameCanonical - The complete canonical name (for example, engineering.microsoft.com/software/someone). The domain-only version includes a trailing forward slash (/)
Option 6 = NameUserPrincipal - The user principal name (for example, someone@example.com)
Option 7 = NameCanonicalEx - The same as NameCanonical except that the rightmost forward slash (/) is replaced with a new line character (\n), even in a domain-only case (for example, engineering.microsoft.com/software\nJSmith)
Option 8 = NameServicePrincipal - The generalized service principal name (for example, www/www.microsoft.com@microsoft.com)
Option 9 = NameDnsDomain - The DNS domain name followed by a backward-slash and the SAM user name
对于这个函数,输出用户名一般option参数选择3最为直接,当然还可以使用其他参数,在通过regex正则表达式来获取需要的字段。
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删