Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use ConnectionOptions in VB6

43 views
Skip to first unread message

Hammer

unread,
Jan 30, 2005, 4:41:06 PM1/30/05
to
I need to use something like ConnectionOptions in VB6 to validate with
different credentials. Can anyone help??

Thanks!


Torgeir Bakken (MVP)

unread,
Feb 1, 2005, 2:33:36 PM2/1/05
to
Hammer wrote:

> I need to use something like ConnectionOptions in VB6 to
> validate with different credentials. Can anyone help??

Hi

Using WMI, you can connect with explicit user credentials (e.g. the
local Administrator account on the remote computer), using
SWbemLocator.ConnectServer instead of GetObject("winmgmts:...")

IWbemLocator::ConnectServer
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/iwbemlocator_connectserver.asp

Some VBScript examples:

Subject: Login with explicit username and password
Newsgroups: microsoft.public.win32.programmer.wmi
http://groups.google.co.uk/groups?th=2b5bcad76f5debaa

Subject: ImpersoantionLevel other than impersonate
Newsgroups: microsoft.public.scripting.wsh
http://groups.google.co.uk/groups?th=89ff50603f12dcfb


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Al Edlund

unread,
Feb 1, 2005, 3:50:54 PM2/1/05
to
might try something like this....
al


Public Sub subWmiNetAdapterInfo()


Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
Const wbemQueryFlagShallow = &H1
Const strClass = "Win32_NetworkAdapter"

Dim itmx As ListItem
Dim strQuery As String

Dim wbemLocator As SWbemLocator
Dim wbemServices As SWbemServices
Dim wbemObjectSet As SWbemObjectSet
Dim wbemObject As SWbemObject
Dim wbemError As SWbemLastError

Dim strComputer As String
Dim strUserName As String
Dim strUserPass As String
Dim strNameSpace As String
Dim strDomain As String
Dim strLocale As String

Dim strAuthenticationLevel As String
Dim lngSecurityFlags As Long
Dim lngInstanceFlags As Long


On Error GoTo WmiNetAdaptInfo_Err

lngInstanceFlags = wbemFlagReturnImmediately + wbemFlagForwardOnly

strDomain = frmWkstMgmt.txtWMI_Domain.Text
strUserName = frmWkstMgmt.txtWMI_UserName.Text
If strDomain <> "" Then
strUserName = strDomain & "\" & strUserName
End If


strUserPass = frmWkstMgmt.txtWMI_UserPass.Text
strComputer = frmWkstMgmt.txtWMI_Workstation.Text
strLocale = "ms_409"

' strNameSpace not need here
' strNameSpace = "root\cimv2"

' if target is blank do the local
If strComputer = "" Then strComputer = "."

' Debug.Print "create locator"
Set wbemLocator = CreateObject("WbemScripting.SWbemLocator")
wbemLocator.Security_.AuthenticationLevel =
wbemAuthenticationLevelPktPrivacy
wbemLocator.Security_.ImpersonationLevel =
wbemImpersonationLevelImpersonate

' Debug.Print "connect server"
If strComputer = "." Then
' this is a local display
Set wbemServices = wbemLocator.ConnectServer(strComputer)
Else
'this is a remote and we have to logon
Set wbemServices = wbemLocator.ConnectServer(strComputer, , _
strUserName, _
strUserPass, _
strLocale)
End If

Set wbemObjectSet = wbemServices.InstancesOf(strClass, lngInstanceFlags)

' clear the list before we start
frmWkstMgmt.lstvwAdaptInfo.ListItems.Clear

Dim strObjectId As String
strObjectId = ""

For Each wbemObject In wbemObjectSet
With wbemObject
strObjectId = .DeviceId
strObjectId = funcUpdateObjectId(strObjectId)
Set itmx = frmWkstMgmt.lstvwAdaptInfo.ListItems.Add(, , strObjectId)
itmx.SubItems(1) = .Description
itmx.SubItems(2) = .MACAddress
itmx.SubItems(3) = .AdapterType
itmx.SubItems(4) = .Manufacturer
End With
Next

frmWkstMgmt.mpWkstMgmt.Value = 2

wmiNetAdaptInfo_Exit:

Exit Sub

WmiNetAdaptInfo_Err:

If Hex(Err) = "5E" Then
Resume Next
Else
Debug.Print "Err in wmiWkstAdaptInfo " & Hex(Err) & " " &
Err.Description _
& vbCrLf & Err.Source
Resume Next
End If


End Sub

"Hammer" <no...@none.com> wrote in message
news:ONUQyRxB...@TK2MSFTNGP11.phx.gbl...

0 new messages