Solved

remote logoff

Posted on 2006-11-01
7
2,245 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

12 Experts available now in Live!

Get 1:1 Help Now