Solved

remote logoff

Posted on 2006-11-01
7
2,250 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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