i got all these help from msdn. can u help me by getting the group to which the
****
in form1
add a coomand button1
Option Explicit
Private Sub Command1_Click()
PerformACESample
End Sub
in standard module
Option Explicit
' API calls used within this sample. Refer to the MSDN for more
' information on how/what these APIs do.
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function LookupAccountName Lib "advapi32.dll" Alias _
"LookupAccountNameA" (lpSystemName As String, _
ByVal lpAccountName As String, Sid As Any, cbSid As Long, _
ByVal ReferencedDomainName As String, _
cbReferencedDomainName As Long, peUse As Long) As Long
Public Sub PerformACESample()
Dim lResult As Long ' Result of various API calls.
Dim I As Integer ' Used in looping.
Dim bUserSid(255) As Byte ' This will contain your SID.
Dim sSystemName As String ' Name of this computer system.
Dim lSystemNameLength As Long ' Length of string that contains
' the name of this system.
Dim lLengthUserName As Long ' Max length of user name.
Dim sUserName As String * 255 ' String to hold the current user
' name.
Dim lUserSID As Long ' Used to hold the SID of the
' current user.
Dim sDomainName As String * 255 ' Domain the user belongs to.
Dim lDomainNameLength As Long ' Length of domain name needed.
Dim lSIDType As Long ' The type of SID info we are
' getting back.
' The first action taken is acquiring the name of the user
' who is currently logged onto this system. Take the user's
' name and grab its companion SID for future use.
' Use the GetUserName API to find out who is currently logged onto
' this system. Preset the length of the string to hold the
' returned user name from the "GetUserName" API.
lLengthUserName = 255
sUserName = Space(lLengthUserName)
' Call GetUserName to find out who is logged onto this system.
lResult = GetUserName(sUserName, lLengthUserName)
' Return value of zero means the call failed; test for this before
' continuing.
If (lResult = 0) Then
MsgBox "Error: Unable to Retrieve the Current User Name"
Exit Sub
End If
' You now have the user name of the person who is logged onto this
' system. Using that information, get the SID of the user. (Refer
' to the MSDN for more information on SIDs and their
' function/purpose in the operating system.) Get the SID of this
' user by using the LookupAccountName API. In order to use the SID
' of the current user account, call the LookupAccountName API
' twice. The first time is to get the required sizes of the SID
' and the DomainName string. The second call is to actually get
' the desired information.
lResult = LookupAccountName(vbNullString, sUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)
' Now set the sDomainName string buffer to its proper size before
' calling the API again.
sDomainName = Space(lDomainNameLength)
' Call the LookupAccountName again to get the actual SID for user.
lResult = LookupAccountName(vbNullString, sUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)
MsgBox "Domain name is " & sDomainName
' Return value of zero means the call to LookupAccountName failed;
' test for this before you continue.
If (lResult = 0) Then
MsgBox "Error: Unable to Lookup the Current User Account: " _
& sUserName
Exit Sub
End If
End Sub
*******************************************************************************
regards
sunil
Quote:
-----Original Message-----
Hi,
Take a look at Win32_UserAccount, in the WMI.
Have a reference to Microsoft WMI Scripting 1.1.
------------
Public Function GetDomain(FullName As String) As String
Dim objs As WbemScripting.SWbemObjectSet
Dim obj As WbemScripting.SWbemObject
Set objs = GetObject("winmgmts:").ExecQuery("SELECT * FROM
Win32_UserAccount WHERE FullName ='" & FullName & "'")
For Each obj In objs
' Debug.Print obj.FullName & " on " & obj.Domain
GetDomain = obj.Domain
Exit For
Next obj
End Function
------------------
? GetDomain("Michel Walsh")
REALMS
Hoping it may help,
Vanderghast, Access MVP
> I used this cheap trick. The DOS environment variable has this value
stored
> in USERDOMAIN or MachineDomain variables. They have to be always there in
> the environment, so you are sure that it will always work.
> >Hello all,
> > I am searching for a way to know the domain name to wich a user is
> >currently logged on.
> >Is there someone that could help me ?
> >Thanks in advance
> >yanick
.