Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.net and WMI logoff remote user

Posted on 2014-10-19
9
Medium Priority
?
655 Views
Last Modified: 2014-10-25
I am attempting to logoff a remote user using wmi via vb.net. I created the below code in the wmi code creator but it doesn't do anything  it doesn't even error out:

Dim scope As New ManagementScope( _
                "\\192.168.1.105\root\CIMV2")
            scope.Connect()

            Dim classInstance As New ManagementObject(scope, _
                New ManagementPath("Win32_OperatingSystem.ReplaceKeyPropery='ReplaceKeyPropertyValue'"), _
                Nothing)

            ' Obtain [in] parameters for the method
            Dim inParams As ManagementBaseObject = _
                classInstance.GetMethodParameters("Win32Shutdown_OperatingSystem")

            ' Add the input parameters.
            inParams("Flags") = 0

            ' Execute the method and obtain the return values.
            Dim outParams As ManagementBaseObject = _
                classInstance.InvokeMethod("Win32Shutdown_OperatingSystem", inParams, Nothing)

Open in new window

0
Comment
Question by:derek7467
  • 5
  • 2
  • 2
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40391722
Is WMI a requirement? If not, you can use following

System.Diagnostics.Process.Start("shutdown.exe", String.Format(@"/l /f /m \\{1}", remoteComputerName));


Also check

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22084990.html
0
 

Author Comment

by:derek7467
ID: 40391826
WMI is not required, i tried your solution and get a "expression expected" over the @ symbol...
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40391877
Sorry that was C#. Try

System.Diagnostics.Process.Start("shutdown.exe", String.Format("/l /f /m \\{1}", remoteComputerName))
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:derek7467
ID: 40391943
I get th following when trying to run it:

 Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40392036
String.Format arguments are 0-based:

System.Diagnostics.Process.Start("shutdown.exe", String.Format("/l /f /m \\{0}", remoteComputerName))
0
 

Author Comment

by:derek7467
ID: 40392272
ehh that fixes the error but it doesnt run, it acts like i didnt type any command line switches in.  I thought logoff doesnt work remote using the shutdown command?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40392412
I haven't used the Shutdown command to log off a remote user, but I would have thought that it could work.

Shutdown
http://technet.microsoft.com/en-us/library/bb491003.aspx

-l   : Logs off the current user, this is also the default. -m ComputerName takes precedence.
-m [ \\ ComputerName ] : Specifies the computer that you want to shut down.

You can't use -l and -m together, since -m takes precedence over -l.

It looks like Win32_OperatingSystem.Win32Shutdown method has that capability to log off a user:

Win32Shutdown method of the Win32_OperatingSystem class
http://msdn.microsoft.com/en-us/library/aa394058(v=vs.85).aspx
0
 

Accepted Solution

by:
derek7467 earned 0 total points
ID: 40392517
Thanks for the info, i saw that on google searches and couldnt figure out how to make it for remote use, it looks like its local only the way its written.  Im using psexec now, i open a CMD window locally into the remote user, query session and then logoff the users ID...  That will work for me.
0
 

Author Closing Comment

by:derek7467
ID: 40403707
This was the best option i was able to find.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

772 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