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.

Obtain user sid

 Keywords:  get user sid wntUserProps

Question:

Is there a winbatch function that can obtain a user's sid number given the user name.

Platform is NT4 Wkst. I'm hoping for something like getsid on NTResKit, but that utility doesn't exist on the computer that I'm writing the script for.

Answer:

The following will return the sid.

 
AddExtender("WWWNT34i.DLL")
SID=wntAcctInfo(server_name,account_name,1)
Message("SID for %account_name%:", SID)

Question:

Is there any way to obtain an NT username, if you have the SID? All the commands I've seen, goes the other way: Username to SID. I just need the reverse. Anyone know how to do so? Thanks

Answer:

That's an enhancement that is being added to the NT extender. This enhancement, along with some other SID related enhancements are in the 2002B release of the Win32 Network Extender. See the wntUserProps function.

In the meantime, this is something I use to determine who is logged on to a remote workstation. Maybe you can use it for your purposes.

Basically, all it does is pull the SID of all logged on users from HKU and matches it to a key under HKLM that provides the profile path for that user. The lowest level directory is the user's ID. I then parse out the username from that path.

Keep in mind that ".Default" is always present under HKU and is always first in the list. That's why a count of '1' means no one is logged on.

errormode(@off)
regclosekey(hnd)
hnd2 = RegConnect("\\%pcname%",@regusers)
errormode(@cancel)
hnd3=RegOpenKey(hnd2,"")
userlist = regquerykeys(hnd3)
numusers = itemcount(userlist,@tab)
RegCloseKey(hnd3)

if numusers == 1
   changestatus = strcat(printerips," No user logged on")
   boxdestroy(wbid)
   goto main
endif

errormode(@off)  ;careful with this one, turn it back on
regclosekey(hnd2)
hnd2 = RegConnect("\\%pcname%",@regmachine)
errormode(@cancel)
id = ""
for i = 2 to numusers
   loggedonuser = itemextract(i,userlist,@tab)
   hnd = regopenkey(hnd2,"SOFTWARE\Microsoft\Windows
   NT\CurrentVersion\ProfileList\%loggedonuser%")
   path = regqueryex(hnd,"[profileimagepath]",@tab,2)
   pathlen = strlen(path)
   backslash = strindex(path,"\",0,@backscan)
   idlen = pathlen - backslash

   if i == 2
      id = strsub(path,backslash + 1,idlen)
   else
      id = strcat(id," ,",strsub(path,backslash + 1,idlen))
   endif
next


Article ID:   W14884
File Created: 2002:05:22:11:24:14
Last Updated: 2002:05:22:11:24:14