Solved

remote logoff

Posted on 2006-11-01
7
2,256 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 500 total points
ID: 17855740
0
 
LVL 18

Expert Comment

by:armoghan
ID: 17855747
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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