HomeASP.NET How To Pass The UserName & Password to an...
How To Pass The UserName & Password to any Domain using WMI and .NET
This is a routine to pass in a username, password, domain, domainname, datarow to connect using .NET and WMI.. Even though this is just a snippet, this route would help connect to any domain it has to be in the format domainuser.
This is a routine to pass in a username, password, domain, domainname, datarow to connect using .NET and WMI.. Even though this is just a snippet, this route would help connect to any domain it has to be in the format domain\user. This returns the computer system collection via WMI. Hope this helps.
Sub ComputerInfo
(ByVal strCN As String, ByVal strDomainName As String, ByVal shtDomainid As Short, ByVal strUID As String, ByVal strPWD As String, ByRef theRow As DataRow)
Dim options As New ConnectionOptions()
options.Username = strUID
options.Password = strPWD
Dim scope As New ManagementScope("\Computer.Domain.comrootcimv2", options)
Dim strCSquery As String = "Select * from Win32_ComputerSystem" Dim objCSQuery As New WqlObjectQuery(strCSquery) Dim objCSsearcher As New ManagementObjectSearcher(scope, objCSQuery)
Dim envVar As ManagementObject
Dim rowComputer As DataRow
Dim objCSItem As PropertyData Dim strCSColName As String
Try
scope.Connect()
Catch f As Exception
Console.WriteLine(f.Message)
Exit Sub
End Try
Try
For Each envVar In objCSsearcher.Get()
Try
For Each objCSItem In envVar.Properties
strCSColName = objCSItem.Name
If Convert.ToString(objCSItem.Value) <> String.Empty Then