|
View previous topic :: View next topic |
Author |
Message |
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Sat Sep 17, 2016 4:55 am Post subject: please help with script to find WHO is logged on |
|
|
Hi HM team
I have problems running a script that finds out WHO ( usernames ) is logged on to the system ( remote desktop services ) on Windows 2012 R2
i just want to have a reply that shows the usernames
for example reply : John,Joe,Crista,Madeline
can you please help me with this script ?
UPDATE:
i made some progress but still not working
this is my current script , but not working ...
Code: |
Option Explicit
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strLogonUser1, strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
If not objComputer.UserName = "" Then
strLogonUser = Split(objComputer.UserName,"\")
strLogonUser(1) = UCase(Left(strLogonUser(1),1))& Trim(Mid(strLogonUser(1),2,20))
WScript.StdOut.Write strLogonUser(1) & ","
End If
Next |
Error in script:
Error number :500
Source :Microsoft VBScript runtime error
Description :Variable is undefined: 'WScript'
Text :
Line :21
Column :0
Many thanks in advance
Menno |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Mon Sep 19, 2016 8:38 am Post subject: |
|
|
A assume you are trying to use Active Script test?
Please use Shell Script test instead: http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell
Script may look like the following:
Code: | Option Explicit
const statusUnknown = "scriptRes:Unknown:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strLogonUser1, strComputer, strRepl
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
strRepl = ""
For Each objComputer in colComputer
If not objComputer.UserName = "" Then
strLogonUser = Split(objComputer.UserName,"\")
strLogonUser(1) = UCase(Left(strLogonUser(1),1))& Trim(Mid(strLogonUser(1),2,20))
strRepl = strRepl & strLogonUser(1) & ","
End If
Next
WScript.StdOut.Write statusOk&strRepl |
Start cmd: cmd /c cscript /B /E:VBScript %Script% %Params% |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12806 Location: USA
|
Posted: Mon Sep 19, 2016 8:48 am Post subject: |
|
|
What test method do you use?
Error message looks like you are using Active Script test method.
While script looks like script for Shell Script test method.
If you want to use Active Script, please check the manual:
Quote: | Active Script
Requirements to the script:
1. script must contain "performtest" function. HM always call function with this name
2. "performtest" function must not have any parameters
3. "performtest" function must return string value. This string contains two parts separated by colon (. First obligatory part contains test status, it can take following values:
"Host is alive"
"No answer"
"Unknown"
"Unknown host"
"Ok"
"Bad"
"Bad contents"
Second optional part contains "Reply" value, HostMonitor displays this value in Reply field, writes to log files, uses to displays charts (Log Analyzer), etc.
E.g.
performtest = "Ok:300 Kb"
performtest = "Bad:90 %" |
I would recommend Shell Script test method instead
Regards
Alex |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Mon Sep 19, 2016 10:14 am Post subject: |
|
|
thanks for the info
i now use a shell script
the script you provided is working but ...
it gives a OK back.
i just want to see a reply like : john,joe,madaline,peter
( so these names must be in the reply field )
these are the people who are logged into the system via remote desktop services.
so .. the status is not that important ( like Ok or bad )
i hope you understand my question
Many many thanks in advnce |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Mon Sep 19, 2016 11:48 am Post subject: |
|
|
This script should return usernames list (strRepl variable).
Is your HostMonitor started as application or service? |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Mon Sep 19, 2016 1:35 pm Post subject: |
|
|
our Hostmonitor is started as a normal application on a dedicated VM machine
m |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Tue Sep 20, 2016 10:07 am Post subject: |
|
|
mmm did everything exactly as you told me be still no users in the reply field...
it just giving me the status OK but no users are displayed in the reply field
can you help me out here ?
thanks m
start cmd : cmd /c cscript /B /E:VBScript %Script% %Params%
Code: |
Option Explicit
const statusUnknown = "scriptRes:Unknown:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strLogonUser1, strComputer, strRepl
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
strRepl = ""
For Each objComputer in colComputer
If not objComputer.UserName = "" Then
strLogonUser = Split(objComputer.UserName,"\")
strLogonUser(1) = UCase(Left(strLogonUser(1),1))& Trim(Mid(strLogonUser(1),2,20))
strRepl = strRepl & strLogonUser(1) & ","
End If
Next
WScript.StdOut.Write statusOk&strRepl
|
|
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Tue Sep 20, 2016 4:13 pm Post subject: |
|
|
Different WMI class should be used in the script in order to detect Active user sessions.
Could you try the following VB script:
Code: | Option Explicit
const statusUnknown = "scriptRes:Unknown:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
Dim objWMI, colSessions, objSession, colList, objItem
Dim strComputer, strUserList, strNameOfUser, strUserDomain
strComputer = "."
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSessions = objWMI.ExecQuery("Select * from Win32_Process Where Name='explorer.exe'")
For Each objSession in colSessions
objSession.GetOwner strNameOfUser, strUserDomain
If strUserList <> "" Then strUserList = strUserList & ","
strUserList = strUserList & strNameOfUser
Next
WScript.StdOut.Write statusOk & strUserList |
Start cmd: cmd /c cscript /B /E:VBScript %Script% %Params% |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Wed Sep 21, 2016 12:03 am Post subject: |
|
|
Thanks .. this is working
|
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Wed Sep 21, 2016 7:31 am Post subject: |
|
|
You are welcome |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|