找回密码
 加入
搜索
查看: 1486|回复: 9

对本地登陆的账号分类问题

[复制链接]
发表于 2009-7-21 19:51:03 | 显示全部楼层 |阅读模式
本帖最后由 qqgghh1 于 2009-7-28 16:12 编辑

需求:对登陆本地的账号进行分类:1.  7天内登陆的视为活跃账号;2.超过7天,小于等于60天的视为历史账号;3.超过60天的不记录。
问题:用非管理员账号运行该段代码编译后的EXE档时,有的报错有的正常。报错为:Line -1 Error:子脚本使用了非数组变量。报错的那些电脑用管理员登陆运行又正常了,很是郁闷。请教大大们,是何原因,代码是否需要再写得严谨点。
#Include <Date.au3>
#Include <File.au3>

Func checkaccount()
        $now = _NowCalc();获取当前日期时间
        $count = StringLen(@UserName) + 1;获取当前账户名长度+1
        $path = StringTrimRight(@UserProfileDir,$count);获取当前登陆账号目录的上级目录
        $filelist = _FileListToArray($path,"*",2) ;获取系统帐户目录下所有登陆账户
        For $i =1 to $filelist[0]
                If $filelist[$i] <> "All Users" And $filelist[$i] <> "Default User"  And $filelist[$i] <> "LocalService"  And $filelist[$i] <> "movedomain" And $filelist[$i] <> "NetworkService" Then ;首先排除这些账号
                        $diffdatepath = $path&""&$filelist[$i];要筛选的某个账户所在目录
                        $t = FileGetTime($diffdatepath&"\NTUSER.DAT",0);该账户标志档案的上一次修改日期时间
                        $now1 = StringLeft($now,10);对返回的当前日期时间取YY/MM/DD格式
                        $modifytime = $t[0] & "/" & $t[1] & "/" & $t[2];对$t 取YY/MM/DD格式
                        $diffdate = _DateDiff("D",$modifytime,$now1);比对日期,返回天数
                        If FileExists($diffdatepath&"\NTUSER.DAT") Then;首先要有NTUSER.DAT档案
                                If $diffdate  <= 60  And $diffdate > 7 Then
                                        $historyaccount = $historyaccount&"|"&$filelist[$i]
                                ElseIf  $diffdate >= 0 And $diffdate <= 7 Then
                                        $activeaccount = $activeaccount&"|"&$filelist[$i]
                                EndIf
                        EndIf
                EndIf
        Next
EndFunc 
发表于 2009-7-21 22:16:20 | 显示全部楼层
If FileExists($diffdatepath&"\NTUSER.DAT") Then;首先要有NTUSER.DAT档案
这一行移到
$t = FileGetTime($diffdatepath&"\NTUSER.DAT",0);该账户标志档案的上一次修改日期时间
上面,排查一下吧~
发表于 2009-7-21 22:22:39 | 显示全部楼层
本帖最后由 lynfr8 于 2009-7-21 22:24 编辑
#Include <Date.au3>
#Include <File.au3>
#include <Array.au3>

Dim $historyaccount,$activeaccount
checkaccount()
Func checkaccount()
        $now = _NowCalc()
        $count = StringLen(@UserName) + 1;获取当前账户名长度+1                
        $path = StringTrimRight(@UserProfileDir,$count);获取当前登陆账号目录的上级目录                
        $filelist = _FileListToArray($path,"*",2) ;获取系统帐户目录下所有登陆账户
        For $i =1 to $filelist[0]
                If FileExists($path&""&$filelist[$i]&"\NTUSER.DAT") And $filelist[$i] <> "All Users" And $filelist[$i] <> "Default User"  And $filelist[$i] <> "LocalService"  And $filelist[$i] <> "movedomain" And $filelist[$i] <> "NetworkService" Then ;首先排除这些账号
                        $t = FileGetTime($path&""&$filelist[$i]&"\NTUSER.DAT",0);该账户标志档案的上一次修改日期时间
                        $now1 = StringLeft($now,10);对返回的当前日期时间取YY/MM/DD格式
                        $time = $t[0] & "/" & $t[1] & "/" & $t[2]  ;  对$t 取YY/MM/DD格式                                                
                        $diffdate = _DateDiff("D",$time,$now1);比对日期,返回天数                                                
                                If   7 < $diffdate  <= 60 Then
                                        $historyaccount = $historyaccount&"|"&$filelist[$i]
                                                                                MsgBox(64,'历史账号',$historyaccount)
                                ElseIf 0 <= $diffdate <= 7  Then
                                        $activeaccount = $activeaccount&"|"&$filelist[$i]
                                                                                MsgBox(64,'活跃账号',$activeaccount)
                                                                        EndIf
                EndIf
        Next
EndFunc 
简单整理了一下楼主的代码,测试结果如下:
>"C:\autoit3\SciTe\ACNWrapper\ACNWrapper.exe" /run /ErrorStdOut /in "C:\Documents and Settings\Administrator\桌面\xcv.au3" /autoit3dir "C:\autoit3" /UserParams    
+>22:19:48 开始执行 ACNWrapper v.1.0.0.2
+>执行环境:
+>        系统语言:        0804
+>        键盘布局:        00000804
+>        操作系统:        WIN_XP/Service Pack 3
+>        系统构架:        X86
+>        CPU构架:        X64
+>        AU3版本:        3.3.0.0
+>        IP地址:                192.168.1.102
>运行 AU3Check (1.54.15.0)  开始目录:C:\autoit3
+>22:19:48 AU3Check 结束[CODE]:0
>运行:(3.3.1.0):C:\autoit3\autoit3.exe "C:\Documents and Settings\Administrator\桌面\xcv.au3"    
+>22:19:50 AutoIT3.exe 完成:[CODE]:0
+>22:19:51 ACNWrapper 完成!
>退出代码: 0    时间: 3.277
编译exe测试过,没报错了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2009-7-21 22:24:18 | 显示全部楼层
谢谢,我明天去公司试试。不过可能和这个没有关系,If FileExists($diffdatepath&"\NTUSER.DAT") 这个判断我不需要写。明天上传下微软工程师帮我们公司写的VBS中有设计到判断这个的。请大大们帮我改成AU3的
发表于 2009-7-21 22:39:13 | 显示全部楼层
发表于 2009-7-22 10:34:11 | 显示全部楼层
学习一下。。
 楼主| 发表于 2009-7-22 10:54:07 | 显示全部楼层
本帖最后由 qqgghh1 于 2009-7-22 10:55 编辑

我在公司里上不了BBS,这是微软的关于判断账号登陆时间的VBS代码,请大大们帮我修改成AU3的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2009-7-22 12:52:02 | 显示全部楼层
微软是首先根据注册表来的,我用的是搜索文件夹,差距啊!重搞起!
 楼主| 发表于 2009-7-23 18:31:40 | 显示全部楼层
我在参考微软工程师提供的VBS修改AU3,若OK了再发来给大家分享。

评分

参与人数 1金钱 +1 收起 理由
lynfr8 + 1 waiting...

查看全部评分

 楼主| 发表于 2009-7-28 16:10:14 | 显示全部楼层
本帖最后由 qqgghh1 于 2009-7-28 16:11 编辑

搞定,已成功收集8000多笔数据,啊哈。和微软给的VBS里对账号的登陆判断原理是一样的。
        $i = 0 
        $now1 = _NowCalc()
        $now2 = StringLeft($now1,10)
        While 1
                $i+=1
                $subkey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList",$i)
                If @error <> 0 then ExitLoop
                If StringLen($subkey) > 9  Then
                        $var1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"&$subkey,"ProfileImagePath")
                        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"&$subkey,"IsNewUser")
                        $profile = StringSplit($var1, "")
                        $accountchecked = $profile[$profile[0]]
                        If StringInStr($accountchecked,"_") <>0 And StringInStr($accountchecked,".") = 0  And $var2 <> 1  Or StringRight($accountchecked,4) = ".psz" Then
                                $diffdatepath = @HomeDrive&""&$profile[2]&""&$profile[3]
                                If FileExists($diffdatepath&"\NTUSER.DAT") Then
                                        $t = FileGetTime($diffdatepath&"\NTUSER.DAT",0)
                                        $modifytime = $t[0] & "/" & $t[1] & "/" & $t[2]
                                        $diffdate = _DateDiff("D",$modifytime,$now2)
                                        ;MsgBox(0,$accountchecked,$diffdate)
                                        If $diffdate  <= 90  And $diffdate > 7 Then
                                                $historyaccount = $historyaccount&"|"&$accountchecked                                                        
                                        ElseIf  $diffdate >= 0 And $diffdate <= 7 Then
                                                $activeaccount = $activeaccount&"|"&$accountchecked                                                        
                                        EndIf
                                EndIf
                        EndIf
                EndIf
        WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-2 12:56 , Processed in 0.076930 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表