Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:05:11+00:00 2026-05-28T14:05:11+00:00

EDIT I still can’t assign the process the username of the session id that

  • 0

EDIT

I still can’t assign the process the username of the session id that is associated with it.

This is the code i use to retrieve user details:

    Public Sub GetUsers()
    Using server As ITerminalServer = manager.GetRemoteServer(strHostName)
        server.Open()
        For Each session As ITerminalServicesSession In server.GetSessions()
            If Not String.IsNullOrEmpty(session.UserName) Then
                dictuser.Add(session.SessionId, New User(session.SessionId, session.UserName))
            End If
        Next
    End Using
End Sub

my user class is defined simply as:

Public Class User
Private _SessionID As Integer
Private _UserName As String

Sub New(ByVal SessionID As Integer, ByVal UserName As String)
    _SessionID = SessionID
    _UserName = UserName
End Sub

Public ReadOnly Property SessionID As String
    Get
        Return _SessionID
    End Get
End Property

Public ReadOnly Property UserName As String
    Get
        Return _UserName
    End Get
End Property
End Class

i have created a function in my process class:

Public Sub AddUserInfo(ByVal UserName As String)
    _UserName = UserName
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:05:12+00:00Added an answer on May 28, 2026 at 2:05 pm

    This replaces the process if a process with the same id is found in the dictionary and automatically adds a new process otherwise.

    dictProcess(process.ProcessId) = process
    

    EDIT (in response to your edited question):

    I would change the name of the Processes class to Process, since it is not a collection, but is supposed to represent one process. You could change the constructor of the Process class to

    Public Sub New(ByVal ProcessId As Integer, ByVal ProcessName As String, ByVal SessionId As Integer)            
        _ProcessId = ProcessId            
        _ProcessName = ProcessName            
        _SessionId = SessionId            
    End Sub
    

    Then add a method

    Public Sub AddWmiInfo (ByVal PageFileUsage As Integer, ByVal WorkingSetSize As Integer)
        _PageFileUsage = PageFileUsage            
        _WorkingSetSize = WorkingSetSize            
    End Sub
    

    Alternatively, you could also make these properties read/write, however you get a better encapsulation like this.

    Add the basic process information to the dictionary using Cassia. Note that ProcessId is declared as Integer and thus the check Not String.IsNullOrEmpty(process.ProcessId) makes no sense.

    For Each process As ITerminalServicesProcess In server.GetProcesses()                       
        dictprocess.Add( _
          process.ProcessId, _
          New Process(process.ProcessId, process.ProcessName, process.SessionId))                       
    Next
    

    Finally, you would add the information from the WMI like this

    Dim p As Process = Nothing
    For Each wmiProcess In prowmi
        If dictprocess.TryGetValue(wmiProcess.ProcessID, p) Then
            p.AddWmiInfo(wmiProcess.PageFileUsage, wmiProcess.WorkingSetSize)
        End If
    Next
    

    TryGetValue returns a process in the variable p. The second parameter of TryGetValue is a ByRef parameter.


    EDIt #2:

    Your loop should read

    Dim p As Process = Nothing
    For Each user As User In dictuser.Values
        If dictprocess.TryGetValue(user.SessionID, p) Then
            p.AddUserInfo(user.UserName)
        End If
    Next
    

    However, if you are never accessing the user dictionary through the key (session id), then a list would be more appropriate than a dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find out if one can still edit their google ads.
I've found some answers that are closely related to this problem, but I still
EDIT: I have made a clean, new project, but still can't get it working.
I've been dealing with this issue for a while, and still can't seem to
I have spent many hours looking into this and I still can't find a
So this is a small problem, but after research still can't make this work.
Still can't quite get this to work. My question is about how to make
I am stuck. Searched and tried for hours. EDIT: I still can't make it
I've looked at a number of questions but still can't quite figure this out.
Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.