Click here to Skip to main content
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 1: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 Sergey Alexandrovich Kryukov 485
1 OriginalGriff 310
2 Shweta N Mishra 244
3 Mathew Soji 225
4 BillWoodruff 200
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


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