How to get the user or his rights?

Ken Ray kray at sonsothunder.com
Mon Mar 26 14:47:20 EDT 2012


On Mar 26, 2012, at 1:38 AM, Tiemo Hollmann TB wrote:

> Hi Bob,
> thanks for your hints.
> For windows standalones you can set the UAC Execution Level to "require
> Admin". So LC knows, who's logged in. I wonder, if we can retrieve this
> information from LC?

You can get the name of the user that is logged in by checking the environment variables $USERNAME (on Windows) and $USER (on Mac). As to the user's permission level, this is what I use (watch line wraps):


function stsIsAdminUser pName, pComputer
  put stsAdminUserList(pComputer) into tList
  return (pName is among the lines of tList)
end stsIsAdminUser

function stsAdminUserList pOpt_ComputerName
  switch (the platform)
    case "MacOS"
      put shell("dscl . read /groups/admin") into tData
      filter tData with "GroupMembership:*"
      put line 1 of tData into tList  -- strip other lines if there are any
      delete word 1 of tList
      replace space with CR in tList
      break
    case "Win32"
      put "Set objGroup = GetObject(" & q("WinNT://" & pOpt_ComputerName & "/administrators,group") & ")" & cr &  \
          "For Each objMember in objGroup.Members" & cr & \
          "If tAdminList =" &&  quote & quote && "Then" & cr & \
          "tAdminList = objMember.name" & cr & "Else" & cr & \
          "tAdminList = tAdminList + vbCrLf + objMember.name" & cr & \
          "End If" & cr & \
          "Next" & cr & \
          "result = tAdminList" into tScript
      
      do script tScript as "VBScript"
      put the result into tList
      break
  end switch
  return tList
end stsAdminUserList

Hope this helps,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/	




More information about the use-livecode mailing list