locked
Get the user roles for domainuser RRS feed

  • Question

  • Hello,

    We have a login vbscript for our server witch checks if a user is part of a certain group.

    We use the following function

    Private Function IsMember(groupName)
    	  flgIsMember = false
    	  Set userObj = GetObject("WinNT://" & net.UserDomain & "/" & net.UserName & ",user")
    	  For Each grp In userObj.Groups
    	    If lcase(grp.Name) = lcase(groupName) Then
    	      flgIsMember = true
    	      Exit For
    	    End If
    	  Next
    	  IsMember = flgIsMember
    	  Set userObj = nothing
    	End Function

    This is working for users who are directly connected with the domain, but not for users who are on a windows version without direct domain connection.

    The problem for those computers are that net.UserDomain returns the workstation name and net.Username the local username.

    Does anyone know how to get the correct username for the connection with the server? I can hardcode the net.UserDomain because it is only one server.

    I think I need to get it from the Windows Vault but I don't know how to retrieve data from the Vault.

    I can do it with a batch file but with a batch file I don't know how to get the usergroups from a domain like at vbscript.

    This is how I did it with a batch file, maybe I can call this batch script at my vbscript and get the return value back?:

    FOR /f "tokens=1-2,14" %%i IN ('cmdkey /list:myserver') DO (
    	::ECHO %%i - %%j - %%k
    	IF "%%i" == "User:" (
    		SET usrname=%%j
    	)
    )
    
    
    ECHO Username: %usrname%
    • Edited by Famous Wolluf Thursday, March 21, 2019 11:30 AM
    • Moved by Alex-KSGZ Tuesday, March 26, 2019 2:49 AM
    Thursday, March 21, 2019 11:27 AM

All replies

  • Hi,

    According to your description, your issue is more related about vbscript. And this forum is discussing and asking questions about the vb.net.
    Ask in the following forum.

    https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG&filter=alltypes&sort=firstpostdesc

    Thank you for your understanding.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 22, 2019 1:09 AM