Does anybody know how to get and set the Workgroupname, using API or any other way? Please help.
Printable View
Does anybody know how to get and set the Workgroupname, using API or any other way? Please help.
To Set the workgroup:
VB Code:
'in module' Public Declare Function NetJoinDomain Lib "Netapi32" _ (ByVal lpServer As Long, _ ByVal lpDomain As Long, _ ByVal lpAccountOU As Long, _ ByVal lpAccount As Long, _ ByVal lpPassword As Long, _ ByVal fJoinOptions As Long) _ As Long Public Function SetWorkgroup(WorkgroupName As String) As Long Dim nRet As Long Const strAccount As String = vbNullChar Const strPassword As String = vbNullChar WorkgroupName = WorkgroupName & vbNullChar nRet = NetJoinDomain(ByVal 0&, StrPtr(WorkgroupName), ByVal 0&, StrPtr(strAccount), StrPtr(strPassword), NETSETUP_JOIN_UNSECURE) SetWorkgroup = nRet End Function
and just call it like this
VB Code:
'anywhere you want SetWorkgroup Workgroupname
to get the workgroup:
Just call it like this:VB Code:
'In module Type WKSTA_INFO_101 wki101_platform_id As Long wki101_computername As Long wki101_langroup As Long wki101_ver_major As Long wki101_ver_minor As Long wki101_lanroot As Long End Type Declare Function NetWkstaGetInfo& Lib "Netapi32" _ (strServer As Any, ByVal lLevel&, pbBuffer As Any) Declare Sub lstrcpyW Lib "kernel32" (dest As Any, ByVal src As Any) Declare Sub RtlMoveMemory Lib "kernel32" _ (dest As Any, src As Any, ByVal size&) Declare Function NetApiBufferFree& Lib "Netapi32" (ByVal buffer&) Function GetWorkgroup() As String Dim ret As Long, buffer(512) As Byte, i As Integer Dim wk101 As WKSTA_INFO_101, pwk101 As Long Dim langroup As String ret = NetWkstaGetInfo(ByVal 0&, 101, pwk101) RtlMoveMemory wk101, ByVal pwk101, Len(wk101) lstrcpyW buffer(0), wk101.wki101_langroup i = 0 Do While buffer(i) <> 0 langroup = langroup & Chr(buffer(i)) i = i + 2 Loop ret = NetApiBufferFree(pwk101) GetWorkgroup = langroup End Function
[Highlight=VB]
'anywhere you want
VB Code:
msgbox GetWorkgroup