Click here to Skip to main content
13,093,097 members (68,931 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi there ...
what the code that can Detect if the user log in physically or he log in using "remote disc-top","team viewer","remote administration","VNC","Hamachi" or other Sw.
my vb is 2008\3.5
Posted 21-Nov-11 0:12am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Try this code :
Imports System.Management
Imports System.DirectoryServices
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
Module Module1
    Dim objManagementClass As ManagementClass
    Dim objManagementScope As ManagementScope
    Dim objManagementBaseObject As ManagementBaseObject
    Public Strcomputer As String = ""
    Sub Main()
        Dim WMIScope As Management.ManagementScope
        Dim WMIConnectionOptions As New Management.ConnectionOptions
        Dim strRootDomain As String
        Dim objRootLDAP As DirectoryEntry
        Dim query As ManagementObjectSearcher
        Dim queryCollection As ManagementObjectCollection
        Dim oq As New System.Management.ObjectQuery
        Dim mo As New ManagementObject
        Dim UserDomain As String
        Dim UserID As String
        Dim StrLoggedUserSID() As Byte
            Dim Strcomputer As String = My.Application.CommandLineArgs.Item(0)
            With WMIConnectionOptions
                .Impersonation = System.Management.ImpersonationLevel.Impersonate
                .Authentication = System.Management.AuthenticationLevel.Packet
            End With
            WMIScope = New Management.ManagementScope("\\" & _
            Strcomputer & "\root\cimv2", WMIConnectionOptions)
            objRootLDAP = New DirectoryEntry("LDAP://RootDSE")
            strRootDomain = objRootLDAP.Properties.Item("rootDomainNamingContext").Value.ToString
            oq = New System.Management.ObjectQuery("SELECT UserName from Win32_ComputerSystem")
            query = New ManagementObjectSearcher(WMIScope, oq)
            queryCollection = query.Get()
            For Each oReturn As ManagementObject In queryCollection
                If Not oReturn("UserName") Is Nothing Then
                    Console.WriteLine("Not logged in")
                End If
        Catch ex As Exception
        End Try
    End Sub
ahmad7_8 4-Dec-11 1:30am
thnx i will try that
ahmad7_8 4-Dec-11 3:38am
this line :
Dim Strcomputer As String = My.Application.CommandLineArgs.Item(0).ToString
throw this exception :

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 1 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100