Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. vbscript processes for current user

vbscript processes for current user

Scheduled Pinned Locked Moved Windows API
questioncsharpsysadmin
5 Posts 3 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JR212
    wrote on last edited by
    #1

    Hi, I can get the processes for the machine by this code

    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

    But how can I filter it so that I only have the processes for the current user? Now I check with getowner but I think it can be easyer Full testcode

    Sub Main()
    Dim a, p, n

    Set a = GetProcesses(FullUserName)
    wscript.echo "Er zijn: " & a.count & " processen!"

    for n= 0 to a.count -1  
    wscript.echo a.item(n)'.Name
    

    Next
    End Sub
    Function GetProcesses(User)
    Dim sLogedinUser, strcomputer, strNameOfUser, strUserDomain
    Dim objWMIService, colProcessList, objProcess
    Dim colProperties
    Dim colProcesses
    dim nCount

    Set colProcesses = CreateObject("Scripting.Dictionary")

    sLogedinUser = User
    strcomputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objProcess In colProcessList
    colProperties = objProcess.GetOwner(strNameOfUser, strUserDomain)
    If sLogedinUser = strUserDomain & "\" & strNameOfUser Then
    colProcesses.Add ncount, objProcess.name
    nCount =ncount+1
    End If
    Next
    Set GetProcesses = colProcesses
    End Function

    Function FullUserName()
    Dim objNetwork

    Set objNetwork = CreateObject("WScript.Network")
    FullUserName = objNetwork.userdomain & "\" & objNetwork.UserName
    End Function

    Jan

    D 1 Reply Last reply
    0
    • J JR212

      Hi, I can get the processes for the machine by this code

      Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

      But how can I filter it so that I only have the processes for the current user? Now I check with getowner but I think it can be easyer Full testcode

      Sub Main()
      Dim a, p, n

      Set a = GetProcesses(FullUserName)
      wscript.echo "Er zijn: " & a.count & " processen!"

      for n= 0 to a.count -1  
      wscript.echo a.item(n)'.Name
      

      Next
      End Sub
      Function GetProcesses(User)
      Dim sLogedinUser, strcomputer, strNameOfUser, strUserDomain
      Dim objWMIService, colProcessList, objProcess
      Dim colProperties
      Dim colProcesses
      dim nCount

      Set colProcesses = CreateObject("Scripting.Dictionary")

      sLogedinUser = User
      strcomputer = "."
      Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
      Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
      For Each objProcess In colProcessList
      colProperties = objProcess.GetOwner(strNameOfUser, strUserDomain)
      If sLogedinUser = strUserDomain & "\" & strNameOfUser Then
      colProcesses.Add ncount, objProcess.name
      nCount =ncount+1
      End If
      Next
      Set GetProcesses = colProcesses
      End Function

      Function FullUserName()
      Dim objNetwork

      Set objNetwork = CreateObject("WScript.Network")
      FullUserName = objNetwork.userdomain & "\" & objNetwork.UserName
      End Function

      Jan

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Easier?? How much easier do you want it?? You're doing it the correct way. There is no other way to filter the process list without comparing the username to what's in the process.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Easier?? How much easier do you want it?? You're doing it the correct way. There is no other way to filter the process list without comparing the username to what's in the process.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        J Offline
        J Offline
        JR212
        wrote on last edited by
        #3

        I was hoping that a where in :

        Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

        was faster Thanks for the awnser Jan

        D M 2 Replies Last reply
        0
        • J JR212

          I was hoping that a where in :

          Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

          was faster Thanks for the awnser Jan

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Since the Owner doesn't show up in the properties of Win32_Process, a WHERE clause isn't possible.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          1 Reply Last reply
          0
          • J JR212

            I was hoping that a where in :

            Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

            was faster Thanks for the awnser Jan

            M Offline
            M Offline
            MicroVirus
            wrote on last edited by
            #5

            In addition to what Dave said: see http://msdn.microsoft.com/en-us/library/windows/desktop/aa390460(v=vs.85).aspx[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups