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.

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 13
July 07, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
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 StringByVal strDomainName As String,
ByVal shtDomainid As ShortByVal strUID As StringByVal 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)

'***************************************************************************

'
Retrieves ComputerSystemOperatingSystem query strings from app.config
' This is an SQL Formatted WMI query.

'
***************************************************************************

Dim strCSquery As String "Select * from Win32_ComputerSystem"
Dim objCSQuery As New WqlObjectQuery(strCSquery)
Dim objCSsearcher As New ManagementObjectSearcher(scopeobjCSQuery)

Dim envVar As ManagementObject

Dim rowComputer 
As DataRow

Dim objCSItem 
As PropertyData
Dim strCSColName 
As String

Try

 scope.Connect()

Catch 
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

     theRow
.Item(strCSColName) = objCSItem.Value

    
Else

     
theRow.Item(strCSColName) = Convert.DBNull

    End 
If

   
Next

  
Catch As Exception

   Console
.WriteLine(f.Message)
  
End Try

 Next

Catch As Exception

 Console
.WriteLine(f.Message)
End Try

End Sub

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials