Solved

VB.net and WMI logoff remote user

Posted on 2014-10-19
9
527 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
[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
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Independent Software Vendors: 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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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