I'm trying to figure how to pull the computers workgroup name using VB.NET. Any help would be great.
Found this code:
Function objGetComputerSystem() As ManagementObject Dim objectQuery As New ObjectQuery("select * from Win32_ComputerSystem") Dim searcher As New ManagementObjectSearcher(objectQuery) Dim computerSystem As ManagementObject Dim computerSystemOut As ManagementObject computerSystemOut = Nothing For Each computerSystem In searcher.Get() computerSystemOut = computerSystem Exit For Next computerSystem Return computerSystemOut End Function Function renameComputer(ByRef computerSystem As ManagementObject, ByVal newName As String) As UInt32 Dim rc As UInt32 Dim objArgs(1) As Object objArgs(0) = newName rc = computerSystem.InvokeMethod("Rename", objArgs) Return rc End Function
which might help you.
That really doesn't help because all that does is allow me to rename a computer. All i want to do is pull the Workgroup that a computer is joined to. I know I can pull the domain with
Did you check this method in the link:
Function JoinWorkgroup(ByRef computerSystem As ManagementObject, ByVal newWorkgroup As String) As UInt32 Dim rc As UInt32 Dim objArgs(5) As Object objArgs(0) = newWorkgroup objArgs(1) = vbNull objArgs(2) = vbNull objArgs(3) = vbNull objArgs(4) = vbNull rc = computerSystem.InvokeMethod("[B]JoinDomainOrWorkgroup[/B]", objArgs) Return rc End Function
That won't give me the current workgroup. That will only allow me to join it to one.
I stumbled accross this.
Don't know much about it but it brings back the workgroup name.
You have to add a reference to System.Managment.
Dim mos = New System.Management.ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_ComputerSystem") For Each mo As System.Management.ManagementObject In mos.Get() MsgBox(mo.Item("WorkGroup")) Next
I came accross the NetGetJoinInformation Windows API.
You can try this class. It works on my end.
Imports System.Runtime.InteropServices Public Class WorkGroupInfo Private WorkGroup As String = String.Empty Private IsWorkGroup As Boolean Sub New(ByVal ComputerName As String) Dim namebuffer As IntPtr Dim status As NetSetup_Join_Status If NetGetJoinInformation(ComputerName, namebuffer, status) = 0 Then If status = NetSetup_Join_Status.NetSetupWorkgroupName Then IsWorkGroup = True WorkGroup = Marshal.PtrToStringUni(namebuffer) Else 'the computer is part of a domain, by itself, or unknown End If NetApiBufferFree(namebuffer) End If End Sub Private Enum NetSetup_Join_Status NetSetupUnknownStatus = 0 'The status is unknown. NetSetupUnjoined 'The computer is not joined. NetSetupWorkgroupName 'The computer is joined to a workgroup. NetSetupDomainName 'The computer is joined to a domain. End Enum <DllImport("netapi32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _ Private Shared Function NetGetJoinInformation( _ ByVal Server As String, _ ByRef NameBuffer As IntPtr, _ ByRef BufferType As NetSetup_Join_Status) As Integer End Function <DllImport("netapi32.dll", SetLastError:=True)> _ Private Shared Function NetApiBufferFree(ByVal buffer As IntPtr) As Integer End Function ReadOnly Property IsWorkGroupComputer() As Boolean Get Return IsWorkGroup End Get End Property ReadOnly Property WorkGroupName() As String Get Return WorkGroup End Get End Property End Class
Dim WrkGrp As New WorkGroupInfo(My.Computer.Name) If WrkGrp.IsWorkGroupComputer Then MsgBox(WrkGrp.WorkGroupName) Else MsgBox("Not a workgroup computer.") End If
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...