Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining SID 1

Status
Not open for further replies.

mpastore

Programmer
Mar 12, 2003
568
US
Does anyone have code to obtain the user SID based on domain/uid?

I have found a VB example from but would like a VFP equivalent.

Thanks

Mike Pastore

Hats off to (Roy) Harper
 
Take the code below, cut-n-paste it into a prg and run it from within VFP. Modify to suit your needs. (Special Note: The user must have the WMI Core Components installed on their machine in order for this to work.)

Code:
LOCAL lcDomain, lcComputer, lcUser

*!* Replace these variables with your own values
*!* I am using the Wscript Network object just for
*!* this example
oWshNetwork = CreateObject("WScript.Network")
lcDomain = oWshNetwork.UserDomain
lcComputer = oWshNetwork.ComputerName
lcUser = oWshNetwork.UserName

?"DOMAIN: " + lcDomain
?"COMP NAME: " + lcComputer
?"USERNAME: " + lcUser
lcUser = "Administrator"
lcSID = GetSID(lcDomain, lcComputer, lcUser)

?"SID: " + lcSID + IIF(Right(lcSID, 4) = "-500", " (Default Admin Account)", "")


Function GetSID(tcDomain, tcComputer, tcUser)
	LOCAL loWMI, loUserAccount
	loWMI=GetObject("winmgmts://" + tcDomain + "/root/cimv2")
	loUserAccount = loWMI.Get("Win32_UserAccount.Domain='" + tcComputer + "'" + ",Name='" + tcUser + "'")
	Return(loUserAccount.SID)
Endfunc

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Thanks for feedback...

Can you explain this portion?

loWMI=GetObject("winmgmts://" + tcDomain + "/root/cimv2")

Mike Pastore

Hats off to (Roy) Harper
 
thanks for the lead, I'll look into it.

Mike Pastore

Hats off to (Roy) Harper
 
mpastore,

You may want to have a look at the following (seems like you could use the pointers to retrieve what you need and WMI would not be required, though I haven't looked into it very much)


...the author of that site is a member here...sometimes he will drop in.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Here's the version I got to work on my network:

CLEAR

LOCAL lcDomain, lcComputer, lcUser

*!* Replace these variables with your own values
*!* I am using the Wscript Network object just for
*!* this example
oWshNetwork = CreateObject("WScript.Network")
lcDomain = oWshNetwork.UserDomain
lcComputer = oWshNetwork.ComputerName
lcUser = oWshNetwork.UserName

?"DOMAIN: " + lcDomain
?"COMP NAME: " + lcComputer
?"USERNAME: " + lcUser
lcUser = "administrator"
lcSID = GetSID(lcDomain, lcComputer, lcUser)
?lcSID

Function GetSID(tcDomain, tcComputer, tcUser)
LOCAL loWMI, loUserAccount
loWMI=GetObject("winmgmts://" + tcDomain) && + "/root/cimv2")
loUserAccount = loWMI.Get("Win32_UserAccount.Domain='" + tcDomain + "'" + ",Name='" + tcUser + "'")
Return(loUserAccount.SID)
Endfunc

Mike Pastore

Hats off to (Roy) Harper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top