WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Machine Administrator Userid

For various reasons it may become necessary to determine the Userid of the primary Administrator account on a machine. By default the userid is Administrator, but this account can be renamed.
You can always build the SID for the Administrator account 100% reliably even if the account has been renamed because this account always has a RID value of 500. What you need to do is to get the machine SID for the workstation so that you can build the Administrator's SID. From there, you can simply do a lookup on that SID to get the account name that is associated with it.

Here's the simple little script that does this for you:

AddExtender('wwwnt34i.dll')

MachineSID = wntLsaPolGet('','AccountDomain',2)

AdministratorSID = StrCat(MachineSID, "-500")

AdministratorName = wntAcctInfo('',AdministratorSID,2,0)

This works regardless of the localized language version of Windows that you are using. For example, the name of the Administrator account changes in the German language versions of Windows, so you can't assume that it will be "Administrator". The NT extender does some tasks internally where groups like "Administrators" and "Everyone" need to be manipulated, and it uses this same method to build the SID values because the account names may vary. The SID value is the one thing that will always work regardless of what the account name currently is.


Article ID:   W16043
File Created: 2004:03:30:15:42:30
Last Updated: 2004:03:30:15:42:30