Results 1 to 3 of 3

Thread: get and set Workgroup name [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    get and set Workgroup name [RESOLVED]

    Does anybody know how to get and set the Workgroupname, using API or any other way? Please help.
    Last edited by robbedaya; Sep 7th, 2003 at 03:43 AM.
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

  2. #2

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    To Set the workgroup:
    VB Code:
    1. 'in module'
    2. Public Declare Function NetJoinDomain Lib "Netapi32" _
    3.   (ByVal lpServer As Long, _
    4.    ByVal lpDomain As Long, _
    5.    ByVal lpAccountOU As Long, _
    6.    ByVal lpAccount As Long, _
    7.    ByVal lpPassword As Long, _
    8.    ByVal fJoinOptions As Long) _
    9. As Long
    10. Public Function SetWorkgroup(WorkgroupName As String) As Long
    11.  
    12.   Dim nRet As Long
    13.    
    14.   Const strAccount As String = vbNullChar
    15.   Const strPassword As String = vbNullChar
    16.  
    17.   WorkgroupName = WorkgroupName & vbNullChar
    18.   nRet = NetJoinDomain(ByVal 0&, StrPtr(WorkgroupName), ByVal 0&, StrPtr(strAccount), StrPtr(strPassword), NETSETUP_JOIN_UNSECURE)
    19.                        
    20.   SetWorkgroup = nRet
    21.  
    22. End Function

    and just call it like this
    VB Code:
    1. 'anywhere you want
    2. SetWorkgroup Workgroupname
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

  3. #3

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    to get the workgroup:
    VB Code:
    1. 'In module
    2. Type WKSTA_INFO_101
    3.    wki101_platform_id As Long
    4.    wki101_computername As Long
    5.    wki101_langroup As Long
    6.    wki101_ver_major As Long
    7.    wki101_ver_minor As Long
    8.    wki101_lanroot As Long
    9. End Type
    10.  
    11. Declare Function NetWkstaGetInfo& Lib "Netapi32" _
    12.    (strServer As Any, ByVal lLevel&, pbBuffer As Any)
    13. Declare Sub lstrcpyW Lib "kernel32" (dest As Any, ByVal src As Any)
    14. Declare Sub RtlMoveMemory Lib "kernel32" _
    15.    (dest As Any, src As Any, ByVal size&)
    16. Declare Function NetApiBufferFree& Lib "Netapi32" (ByVal buffer&)
    17. Function GetWorkgroup() As String
    18.    Dim ret As Long, buffer(512) As Byte, i As Integer
    19.    Dim wk101 As WKSTA_INFO_101, pwk101 As Long
    20.    Dim langroup As String
    21.  
    22.    ret = NetWkstaGetInfo(ByVal 0&, 101, pwk101)
    23.    RtlMoveMemory wk101, ByVal pwk101, Len(wk101)
    24.  
    25.    lstrcpyW buffer(0), wk101.wki101_langroup
    26.    i = 0
    27.    Do While buffer(i) <> 0
    28.       langroup = langroup & Chr(buffer(i))
    29.       i = i + 2
    30.    Loop
    31.    ret = NetApiBufferFree(pwk101)
    32.  
    33.    GetWorkgroup = langroup
    34. End Function
    Just call it like this:
    [Highlight=VB]
    'anywhere you want
    VB Code:
    1. msgbox GetWorkgroup
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width