Feedback

VB - Systemdirectory eines Remotesystems mit WMI ermitteln

Veröffentlicht von am 12/8/2009
(1 Bewertungen)
Ermittelt mit WMI das Systemverzeichnis eines Remotesystems.

Aufruf

SysDirRemSys(Remotesystem, Domaine\Username, Password)


Der Username muss entweder in der o.g. Form oder in Form Systemname\User angegeben werden.

Function SysDirRemSys(ByVal _sSystem As String, ByVal _sUser As String, ByVal _sPassword As String) As String
        Dim sW32Segment As String = String.Empty
        Dim options As System.Management.ConnectionOptions

        options = New System.Management.ConnectionOptions()


        options.Username = _sUser
        options.Password = _sPassword

        Dim scope As System.Management.ManagementScope


        Try
            scope = New System.Management.ManagementScope( _
               "\\" & _sSystem & "\root\cimv2", options)
            scope.Connect()
        Catch ex As Exception
            Return (ex.Message & " Error while Connecting!")
            Exit Function
        End Try



        sW32Segment = "Win32_OperatingSystem"
       
        Dim query As System.Management.ObjectQuery
        query = New System.Management.ObjectQuery("SELECT * FROM " & sW32Segment)

        Dim searcher As System.Management.ManagementObjectSearcher
        searcher = New System.Management.ManagementObjectSearcher(scope, query)

        Dim queryCollection As System.Management.ManagementObjectCollection
        queryCollection = searcher.Get()

        Dim mo As System.Management.ManagementObject
        Dim strR As String = String.Empty
        Dim strS As String = String.Empty

        Dim cimobject As System.Management.ManagementClass = New System.Management.ManagementClass(sW32Segment)
        Dim moc As System.Management.ManagementObjectCollection = cimobject.GetInstances()


        For Each mo In queryCollection

            If _stopMode = True Then Exit For

            Try

                strS = Trim(mo("SystemDirectory").ToString)
                Dim sRoot As New DirectoryInfo(Trim(mo("SystemDirectory").ToString))

                strR = sRoot.Root.ToString
                strR = strS.Replace(":\", "$\")

            Catch ex As Exception
                Return ex.Message
            End Try
        Next

        strS = "\\" & _sSystem & "\" & strR


        Return strS


End Function
Abgelegt unter Systermverzeichnis, WMI.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!