Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help getting open sessions 1

Status
Not open for further replies.

hayt

IS-IT--Management
Oct 5, 2004
132
US
is there a way to return the users that currently have open sessions or open files on a local machine? i intend for the application to pull the users that have open files on the local machine (hosting the app, not their machine). please please please someone help. i can find absolutely NO information anywhere!
 
i will give a star to anyone with anything
 
You could have the app add the user's windows ID to a log file when they start the app and remove it when they end the app.

Not sure about pulling the users of the app via an API though.

-Rick

----------------------
 
i might not have explained myself very well. in win2k, you can go to the management console and view shared files and then see open sessions. this lists users that are currently connected to that computer via the network. they may be browsing a drive or folder, or may have a file open or running an app. i need the vbscript to return the computer names and users that are connected to the local machine.

the app will pull the list, and send a user defined message to each user connected via net send for restarts of servers.

does this help?
 
Okay, so you hit my curious bone. I dug up some info on the WMI. Add a reference to System.Management to your app and add this function:

Code:
  Public Overloads Shared Sub SearchShares()
    Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Share")
    Dim share As ManagementObject
    Dim relationship As System.Management.ManagementObject

    For Each share In searcher.Get()
      Console.WriteLine("Share = " & share("Name").ToString())
      For Each relationship In share.GetRelationships
        Console.WriteLine(" Relationships = " & relationship.GetText(TextFormat.Mof).ToString)
      Next
    Next share
  End Sub

it will output the share name and then a line of lots of info on the relationships. If a user it connected that line will end in something like this:

Code:
UserName=\"RWAY\"";

This is just for the local machine, but it might point you in the right direction. The WMI is pretty impressive, lots of functionality, I have no idea what it's limits are, but I'm guessing it can probrably do what you are looking for.

-Rick

----------------------
 
Man, I should really be working... but, here is the code to see who is connected to a share on a remote machine:

Code:
  Public Sub RemoteShares()
    Dim options As New ConnectionOptions()
    options.Username = "[password]"
    options.Password = "[domain\username]"
    Dim scope As New ManagementScope("\\[computer.domain]\root\cimv2", options)
    scope.Connect()
    Dim searcher As New ManagementObjectSearcher(scope, New Management.ObjectQuery("SELECT * FROM Win32_Share"))
    Dim share As ManagementObject
    Dim relationship As System.Management.ManagementObject

    For Each share In searcher.Get()
      Console.WriteLine("Share = " & share("Name").ToString())
      For Each relationship In share.GetRelationships
        Console.WriteLine(" Relationships = " & relationship("Dependent").ToString)
      Next
    Next share
  End Sub

-Rick

----------------------
 
you rock. now get back to work. hehe. thanks alot man, i am going to try it out now. i knew wmi could do it, just didn't know how to do it in .net (i have an app in vbscript that does it, but it isn't very friendly). thanks.


hayt
 
unfortunately, that did work. i have no way to get to the rpc or ad servers. i just need the current open sessions on the local machine. isn't there a way to get the local shares, and see who is accessing them??? and what files, if any?
 
is there anyway that i can get the username and machine name? i tried it, and it returns the local share brilliantly. thanks
 
Code:
Share = test
 Relationships = 
instance of Win32_ConnectionShare
{
	Antecedent = "\\\\3704-XP\\root\\cimv2:Win32_Share.Name=\"test\"";
	Dependent = "\\\\3704-XP\\root\\cimv2:Win32_ServerConnection.ComputerName=\"127.0.0.1\",ShareName=\"test\",UserName=\"RWAY\"";
};

That is the output from the code I posted when I create a local share (Called test) and browse to it through the network. You should be able to parse out the share name and username.

You'll also get all the other share info as well, Win32_ShareToDirectory, and Win32_SecuritySettingOfLogicalShare, for any other shares on the drive. Just look for the Win32_ConnectionShare and parse out the username and share.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top