WMI - Accès refusé

flopad Messages postés 528 Date d'inscription mercredi 28 septembre 2005 Statut Membre Dernière intervention 6 mars 2009 - 5 juil. 2006 à 09:04
cs_Joe28 Messages postés 1 Date d'inscription mercredi 17 septembre 2003 Statut Membre Dernière intervention 20 janvier 2009 - 20 janv. 2009 à 16:59
Bonjour, 

Je suis en train de faire un prog qui me liste les processus lancés sur une machine distante;
Voici un extrait de mon code ; mon prog bloque à la ligne en rouge en me donnat comme message  L'exception System.UnauthorizedAccessException n'a pas été gérée
  Message="Accès refusé. (Exception de HRESULT : 0x80070005 (E_ACCESSDENIED))"
:

Dim myConnectionOptions
AsNew System.Management.ConnectionOptionsmyConnectionOptions.EnablePrivileges TruemyConnectionOptions.Username
"administrateur"myConnectionOptions.Password "XXXX"myConnectionOptions.Impersonation 3

Dim myManagementScope
As System.Management.ManagementScope

' myManagementScope = New System.Management.ManagementScope("\" & _

'myServerName & "\root\cimv2", myConnectionOptions)myManagementScope =

New System.Management.ManagementScope(
"\" +
"192.82.1.8" +
"\root\cimv2", myConnectionOptions)

'* connect to WMI namespacemyManagementScope.Connect()

If myManagementScope.IsConnected =
False
ThenMsgBox(

"Could not connect to WMI namespace")

End
If

Dim myObjectSearcher
As System.Management.ManagementObjectSearcher

Dim myCollection
As System.Management.ManagementObjectCollection

Dim myObject
As System.Management.ManagementObjectmyObjectSearcher =

New System.Management.ManagementObjectSearcher( _myManagementScope.Path.ToString,

"Select * From Win32_Process")

'* execute querymyCollection = myObjectSearcher.Get()

'* list packages installed

Merci d'avance!!

4 réponses

cesar1984 Messages postés 2 Date d'inscription mercredi 20 juin 2007 Statut Membre Dernière intervention 31 juillet 2007
25 juil. 2007 à 11:43
J'ai exactement le meme pb que toi...j'ai pas trouvé de solution satisfaisante pour l'instant...en configurant un canal ipc$ entre les 2 machines ca fonctionne mais c pas top...voili voilou si quelqu'un a une solution je suis preneur... merci
0
cesar1984 Messages postés 2 Date d'inscription mercredi 20 juin 2007 Statut Membre Dernière intervention 31 juillet 2007
31 juil. 2007 à 10:04
Bon apparement ce post n'interesse pas grand monde...mais si ca peu servir a quelqu'un....
J'ai reglé mon probleme en modifiant le parametre de securité locaux sur la machine sur laquelle je me connecte...
Outils d'administration=>Stragegie de securité locale=> Strategie locale => option de securité=>Accés reseau: model de partage et de securité pour les compte locaux : Classique- les utilistateur s'authentifie eux meme
voila et en plus ca fonctionne....++
0
rahon55 Messages postés 6 Date d'inscription vendredi 21 octobre 2005 Statut Membre Dernière intervention 13 mars 2008
13 mars 2008 à 10:32
Même probleme, si y a du nouveau faite le savoir... Merci
0
cs_Joe28 Messages postés 1 Date d'inscription mercredi 17 septembre 2003 Statut Membre Dernière intervention 20 janvier 2009
20 janv. 2009 à 16:59
Public Function CheckProcess(ByVal sProcessName As String) As String
           
    Dim oConnectionOptions As New System.Management.ConnectionOptions
    oConnectionOptions.Username = "domaine\user"
    oConnectionOptions.Password = "xxxx"
    oConnectionOptions.Impersonation = ImpersonationLevel.Impersonate


 


    Dim oManagementPath As System.Management.ManagementPath = Nothing
    Dim oManagementScope As System.Management.ManagementScope = Nothing
    Dim oSearcher As System.Management.ManagementObjectSearcher = Nothing
    Dim oCollection As System.Management.ManagementObjectCollection = Nothing
    Dim oObject As System.Management.ManagementObject = Nothing


    Try


        oManagementPath = New System.Management.ManagementPath("[file://\\ServerName"\root\cimv2 \\ServerName"\root\cimv2]")
        oManagementScope = New System.Management.ManagementScope(oManagementPath, oConnectionOptions)
        oManagementScope.Connect()
        If oManagementScope.IsConnected = False Then
            Return "Erreur :: Could not connect to WMI "
            Exit Function
        End If


       
        Dim oQuery As New System.Management.ObjectQuery("Select * From Win32_Process where Name = '" & sProcessName & "'")
        oSearcher = New System.Management.ManagementObjectSearcher(oManagementScope, oQuery)


        '* execute query
        oCollection = oSearcher.Get()
       
        For Each oObject In oCollection
            If oObject.GetPropertyValue("Name") = sProcessName Then
                '...
            End If
        Next




    Catch ex As Exception
        Return ex.Message


    Finally


        If Not oManagementPath Is Nothing Then
            oManagementPath = Nothing
        End If


        If Not oManagementScope Is Nothing Then
            oManagementScope = Nothing
        End If


        If Not oSearcher Is Nothing Then
            oSearcher = Nothing
        End If
        If Not oCollection Is Nothing Then
            oCollection = Nothing
        End If
        If Not oObject Is Nothing Then
            oObject = Nothing
        End If


    End Try


End Function
0
Rejoignez-nous