欢迎光临 Enjoy IT (ITECN.NET) 登录 | 注册 | 帮助

UU'S T&T

TIPS AND TROUBLESHOOTS FOR WINDOWS

公告

  • 本Blog站点上的任何言论仅代表个人观点,与其所在的公司没有任何关系。本Blog站点的内容是按原样提供的,作者与其公司并不对其提供任何种类的担保。此外还否认所有暗示的保证,包括但不局限于在任何试销性或某一特定用途的适用性方面的暗示保证。由于本站内容的使用或性能表现带来的全部风险将由使用者自己承担。任何由于使用或无法使用本站内容而带来的损失(包括但不局限于商业利润、业务中断、业务信息或其他财产上的损失),即使在 本站作者曾经被提醒可能出现这些损失的情况下,本站 及其作者或涉及内容创建的任何其他人等对任何上述的损失概不负责。
    ·本BLOG的内容均属技术交流之用,本人对所发表的文章、图片、随笔保留一切权利。
    如文章、图片、随笔转载请注明:
    作者姓名:尤扬
    文章来源URL:
    http://blogs.itecn.net/blogs/youyang
    同时请通过EMAIL通知本人:
    youyang1983◎hotmail.com
    ·如果通过EMAIL与我联系,并最终解决的问题,我将发表于本BLOG进行技术分享,如果涉及隐私或有特殊要求请于EMAIL中说明!
    本人联系方式:
    MSN ID:youyang1983◎hotmail.com(常用)
    QQ ID:85836514
    EMAIL:v-yayou@microsoft.com
    ·技术就是无条件共享


    2005年7月 Microsoft MVP for Windows-Shell\User
    2006年7月 Microsoft MVP for Windows-Shell\User
    2007年7月 Microsoft MVP for Windows-Shell\User

Microsoft

朋友的网站

当Administrator变成Administrador

呵呵,钓了大家一天,现在公布正确答案,

首先,大家看看标题,Administrador?,是我拼错了吗?(t->d)

不是,在西班牙文的Windows Vista中,英文的Administrator账户就是用Administrador来标识的(类似的还有俄文,德文系统)

那么我们的Batch就会遇到一个致命的问题,比如:

Net User Administrator /active:yes

这条语句,在西班牙文的系统上面就会执行失败,原因很简单,因为西班牙文的系统用Administrador代表Build-In administrator账户。

因此,在上一篇文章中的C#代码实际上是起到了一个名称翻译的作用,

其原理是,通过WMI的Win32_UserAccount 类

p.mpInterWMIPath = new ManagementPath(\\\\.\\root\\cimv2:Win32_UserAccount);

获得当前系统的所有账户实例,然后通过枚举每个实例的SID属性判断其是否为需要的账户,

因为Build-In Administrator的最后的SID是500, Guest是501。

上篇文章的工具应该怎么用来支持LOC语言的系统呢?

上面的代码可以通过VS.NET或者C#编译器进行编译,之后形成一个叫做USERS.exe的文件。

那么具体的解决方案如下:

1. 调用这个Users.exe将西班牙文系统上面的Build-in Administrator 账户写到一个TXT文件中,比如如下的Batch

@ECHO OFF

USERS.EXE Administrator > LOCNAME.txt

2. 使用For语句,从LOCNAME.txt文件中读取解析之后的Administrator名称(Administrador),比如如下的Batch

@ECHO OFF

for /f %%H IN (LOCNAME.txt) DO Net User %%H /active:yes

注意,上面的脚本都使用同一个工作文件夹。

当然,上一篇文章的代码只是一个Demo,因为不能将工作中的代码外泄的规定,所以只能写一个Mini版的,但基本的原理就是如上的东西了,

希望对大家工作有帮助。

Posted: 2007年6月19日 12:21 作者 youyang

评论

ghjconan 说:

呵呵,我贴上一段vbs脚本代码,和大家一起分享好了

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount",,48)

For Each objItem in colItems

If InStr(objitem.sid,"500") <> 0 Then

WScript.Echo objitem.name

End If

Next

WScript.Quit

# 六月 19, 2007 14:54

ahpeng 说:

挺不错的。

同时非常感谢楼上ghjconan兄弟的分享

# 六月 19, 2007 15:24

youyang 说:

To,ghjconan

嗯,不错,

不过,你的VBS里面有性能问题,

问题在于,你的For循环没有在Hit目标之后即使结束,也就是Exit For,

http://www.microsoft.com/technet/scriptcenter/resources/qanda/may05/hey0504.mspx

这篇文章中,对这种问题作了非常到位的解释:

So how can you tell whether or not a user account exists in an NT 4 domain? Well, one way to do this is the good old-fashioned, brute force way: you retrieve all the accounts and check each one. And the easiest way to do that is in a For Each loop:

Set objComputer = GetObject("WinNT://fabrikam,domain")

For Each objItem in objComputer

   If objItem.Name = "kenmyer" Then

       Wscript.Echo "Account found."

   End If

Next

There’s nothing wrong with this approach, and - depending on your needs - you might have no choice but to methodically slog your way through the entire collection of accounts. The only problem is that this can be very slow; on a test domain with about 30,000 accounts it took well over 2 minutes for our script to complete. If the account you’re looking for happens to be the very last account in the collection there’s not much you can do about that. But what if the account you’re looking for happens to be the very first item in the collection? In that case you’re going to immediately find what you’re looking for but then have to wade through 29,999 more accounts just so you can complete the For Each loop.

Well, unless you explicitly exit the loop that is:

Set objComputer = GetObject("WinNT://fabrikam,domain")

For Each objItem in objComputer

   If objItem.Name = "kenmyer" Then

       Wscript.Echo "Account found."

       Exit For

   End If

Next

# 六月 19, 2007 19:17

ghjconan 说:

嗯,平时写脚本也不大考虑性能的问题,只追求能实现想要的东西就可以了……

这次受教了,以后会注意的^^

# 六月 19, 2007 20:41

wxbbk.ha 说:

^^都是牛人.,,,向你们学习....

# 六月 20, 2007 8:33

zglloo 说:

那么 这两者只不过是词不同 含义相同!

# 六月 26, 2007 21:18
禁止匿名发表评论