Click here to Skip to main content
11,703,632 members (64,209 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB9.0 VB.NET
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
good
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
        Try
            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(oReturn("UserName").ToString)
                Else
                    Console.WriteLine("Not logged in")
                End If
            Next
        Catch ex As Exception
            Console.WriteLine(ex.ToString)
        End Try
    End Sub
  Permalink  
Comments
ahmad7_8 at 4-Dec-11 1:30am
   
thnx i will try that
ahmad7_8 at 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
0 OriginalGriff 550
1 Maciej Los 530
2 Sergey Alexandrovich Kryukov 381
3 Andy Lanng 294
4 CPallini 195
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 1 Dec 2011
Copyright © CodeProject, 1999-2015
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