Solved

remote logoff

Posted on 2006-11-01
7
2,249 Views
Last Modified: 2008-10-06
I would like to remotely logoff a user on another computer.  I tried to use psexec and use shutdown -l, but command switch this does not work with psexec.  Is there a way I can do this within vb on a remote computer?  I know I can use:

     'setup the class to reboot the computer
    Private Declare Function ExitWindowsEx Lib "user32.dll" ( _
       ByVal uFlags As Long, _
       ByVal dwReserved As Long) As Long

    Private Const EWX_FORCE = 4         'const for a forced logoff

  ExitWindowsEx(EWX_FORCE, 4)

to log a user off a local machine, but can I run this on a remote XP machine?  If so how?

Chad

0
Comment
Question by:chadmanvb
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:manch
ID: 17855698
'Use the Followind Code for it
'it is used to teminate a process

        Dim strProcess As String
        Dim methodArgs() As Object = {}
        Dim strComputer As String = 'write ur Computer Name here          
        Dim options As New ConnectionOptions

        options.Impersonation = ImpersonationLevel.Impersonate
        options.EnablePrivileges = True
        options.Username = "administrator"
        options.Password = 'write the password here
        strProcess = "calc.exe"   'write the process name here ' u must write the shell process

        Dim ms As New ManagementScope("\\" & strComputer & "\root\CIMV2", options)
        Dim q As New SelectQuery("select * from Win32_Process where Name='" & strProcess & "'")

        ms.Connect()

        Dim search As New ManagementObjectSearcher(ms, q)
        Dim wmiprocess As ManagementObject

        For Each wmiprocess In search.Get()
            wmiprocess.InvokeMethod("Terminate", methodArgs)
        Next

Try It
0
 
LVL 18

Accepted Solution

by:
armoghan earned 500 total points
ID: 17855740
0
 
LVL 18

Expert Comment

by:armoghan
ID: 17855747
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:chadmanvb
ID: 17863413
Ok, I guess I am a little slow.  I am still confused on how this will log a user off on a remote computer.  What am I missing?  Thanks, Chad
0
 
LVL 18

Expert Comment

by:armoghan
ID: 17864240
Try the links present above.. They also have code with them..

With Administrator rights you can control any computer.
0
 

Author Comment

by:chadmanvb
ID: 17867896
I did look at your link, but I am still confused on how to shutdown a remote machine.  I can get this to work fine on my machine, but I need to do this on remote machines.

Thanks, Chad
0
 

Author Comment

by:chadmanvb
ID: 17870580

Ok I got it working.  The link to the code was a little incorrect.  Dim ss As String() = {"0", "0"} is used to logoff a user and NOT Dim ss As String() = {"2", "2"} ' logoff that is listed in the link.

 '***********************************************************************************************
    Public Sub logoff()
        Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\" & TextBox2.Text & "\root\cimv2")
        ms.Options.EnablePrivileges = True
        'ms.Options.Password = ""
        'ms.Options.Username = ""
        Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem")
        Dim query1 As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(ms, oq)
        Dim queryCollection1 As System.Management.ManagementObjectCollection = query1.Get()
        For Each mo As System.Management.ManagementObject In queryCollection1
            'Dim ss As String() = {"2", "0"} ' Reboot
            'Dim ss As String() = {"2", "2"} ' Shudown
            Dim ss As String() = {"0", "0"} ' logoff
            mo.InvokeMethod("Win32Shutdown", ss)
        Next

    End Sub

Thanks, Chad
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - For Loop Error 5 37
Make all values in arrayist to titlecase+vb.net 23 27
LINQ - C# to VB convertion 12 48
Exit the loop 4 35
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now