Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

remote logoff

Posted on 2006-11-01
7
Medium Priority
?
2,258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 total points
ID: 17855740
0
 
LVL 18

Expert Comment

by:armoghan
ID: 17855747
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

719 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