将当前login的用户获取到Windows XP Pro系统

我们有一台XP机器,它在清晨运行计划任务,不幸的是必须login到某个用户的桌面才能工作。 不幸的是,该用户有时会从pipe理员login(并忘记重新login到正确的用户)或重新启动以应用安全更新等方式被注销。

我想让Nagios监视当前login的用户,确认它是正确的。 Nagios正在Linux上运行。

到目前为止,我已经与当前用户查找了一个SNMPvariables。 我没有运气。 我尝试了snmpbulkwalk -m all -v2c -c community machine并为其用户名grep'd,并做了一个login前和login后,并检查差异,没有发现什么有用的。

我检查了net命令(来自Samba),但是我没有看到任何东西 – 虽然我承认它可能是我错过了一些东西。 各种session选项似乎只显示net会话(即使我使用我的域pipe理员帐户)。

%WINDIR%\System32\dllcache\query.exe session将为您提供WinXP上所有当前login用户的列表。

出于某种原因,我的WinXPtesting机器上的query.exe不在我的path环境variables中,所以这就是我指定整个path的原因。

询问

如果您需要某种能够通过RPC / DCOM远程获取此信息的内容,请查看我写的一些内容:

http://myotherpcisacloud.com/post/2013/01/16/Usersexe-v1003.aspx

http://www.myotherpcisacloud.com/post/2013/01/13/Getting-RDP-Sessions-with-Client-Computer-Name.aspx

顺便说一句,你需要尽快离开XP。 这是非常古老的。

编辑:好吧,我会给你另一个select,因为这些都没有帮助你。 你想用你的Linux机器通过networking查询这个WinXP机器。 你想使用WMI。 你已经find了一个Linux的WMI客户端。 到现在为止还挺好。

这将使您通过WMI WQL查询当前login本地或远程计算机的用户。 我在Powershell中写了这个。 对不起,我不会把它转换成Perl或Bash,但是只要你能做WQL查询,这个概念还是一样的:

 $Sessions = Get-WMIObject -Query "SELECT * FROM Win32_LogonSession WHERE LogonType=2 OR LogonType=10" Foreach($Session In $Sessions) { If($Session -AND $Session.PSObject.Properties.Match('LogonId').Count) { Get-WMIObject -Query "Associators Of {Win32_LogonSession.LogonId=$($Session.LogonId)} WHERE AssocClass=Win32_LoggedOnUser Role=Dependent" } } 

2和10的logintypes包括本地和远程交互式会话,但不包括服务login,networkinglogin或批处理login。

是的,你需要访问WinXP机器的权限。 这不仅仅是为了匿名networking进程而喋喋不休。 WinXP上的本地组织并不是很精细,因为WinXP是非常老的,它的安全性远不如现代版本的Windows …我的意思是把你的networking监控用户放在WinXP机器的本地Admins组中可能是你最好的select。 但是,如果您仍然希望遵循最小特权原则,则可以推荐您,在这种情况下,您可以使用WMI控制台wmimgmt.msc,并将权限设置为您想要为其分配权限的任何帐户。

谢谢你@Ryan里斯,这里是我使用的实际的Perl脚本。 希望它certificate对别人有用。 它似乎工作,请随时报告任何错误。 我会尽量记住,如果我find任何更新。

此外,我找不到任何方式来使这个XP的工作,而不是把监控用户在pipe理员。 我认为这是在XP上唯一的方法。

 #!/usr/bin/perl -w use 5.010; use IPC::Run qw(run); use Nagios::Plugin; use strict; my $np = Nagios::Plugin->new( shortname => 'check_windows_user', version => '0.01', license => 'Copyright 2013 Customer Relationship Metrics, LC. Based on a Powerhell program by Ryan Ries. CC-BY-SA http://creativecommons.org/licenses/by-sa/3.0/', usage => 'Usage: %s -H <host> -A <authfile> -u <user>|-s <sid> -w <threshold> -c <threshold>', extra => <<EXTRA Thresholds are in session counts. See http://nagiosplug.sourceforge.net/developer-guidelines.html for a description of the threshold format. EXTRA ); $np->add_arg( spec => 'host|H=s', help => '-H, --host=hostname', required => 1, ); $np->add_arg( spec => 'user|u=s', help => '-u, --user=username', required => 0, ); $np->add_arg( spec => 'sid|s=s', help => '-s, --sid=sid', required => 0, ); $np->add_arg( spec => 'authentication_file|authentication-file|A=s', help => '-A, --authentication-file=FILE', required => 1, ); $np->add_arg( spec => 'warning|w=s', help => '-w, --warning=INTEGER:INTEGER', required => 1, ); $np->add_arg( spec => 'critical|c=s', help => '-c, --critical=INTEGER:INTEGER', required => 1, ); $np->getopts; $np->set_thresholds( warning => $np->opts->warning, critical => $np->opts->critical ); # setup local $SIG{ALRM} = sub { die "alarm timed out\n" }; alarm 30; my $target_user = defined $np->opts->user ? lc $np->opts->user : undef; my $target_sid = defined $np->opts->sid ? lc $np->opts->sid : undef; my @wmic = ( 'wmic', -A => $np->opts->authentication_file, ('//' . $np->opts->host)); my $wmic_out; # get all logon ids my @all_logon_ids; run [ @wmic, q{SELECT LogonId FROM Win32_LogonSession WHERE LogonType = 2 or LogonType = 10} ], \undef, \$wmic_out; @all_logon_ids = split("\n", $wmic_out); $all_logon_ids[0] =~ /^CLASS: Win32_LogonSession$/ or die "Unexpected wmic result: $wmic_out"; $all_logon_ids[1] =~ /^LogonId$/ or die "Unexpected wmic result: $wmic_out"; splice @all_logon_ids, 0, 2; # get user of each logon, check if matches my $session_count = 0; foreach my $logon_id (@all_logon_ids) { # does not seem to be a way to specify which fields we want, or # their order :-( # # also, it only seems to do delimited data — pick a character that # isn't going to occur in the data. And unit separator is even for # that purpose! run [ @wmic, '--delimiter' => "\x1F", qq{Associators Of {Win32_LogonSession.LogonId=$logon_id} WHERE AssocClass=Win32_LoggedOnUser Role=Dependent} ], \undef, \$wmic_out; # sessions get left in Win32_LogonSession after log out (sometimes). next if '' eq $wmic_out; my @tmp = split("\n", $wmic_out); 3 == @tmp && $tmp[0] =~ /^CLASS: Win32_UserAccount$/ or die "Unexpected associator: $wmic_out"; my %record; @record{map lc, split("\x1F", $tmp[1])} = map lc, split("\x1F", $tmp[2]); # try to disqualify defined $target_user && $target_user ne $record{caption} and next; defined $target_sid && $target_sid ne $record{sid} and next; # qualified ++$session_count; } $np->add_message($np->check_threshold($session_count), "$session_count sessions"); $np->nagios_exit($np->check_messages); 

更新日志

  • 显然,如果通过远程桌面注销会话,并且不login另一个用户,会话将保留在Win32_LogonSession中,但没有任何关联。 状态始终为空,因此无法过滤。 通过缺乏关联来过滤。 如果没有这两行修复,插件会死(因此返回未知)。