首先,先建立两个脚本文件..分别为LOGON.VBS,LOGOFF.VBS.
LOGON.VBS
Option
Explicit
Dim
oNet,
sUser,
sComputer,
ServerLog
ServerLog
=
"\\SERVERNAME\logctrl$\"
加$目的是为了用户在游览服务器共享文件的时候看不到.这样用户就无法来更改他们的登录信息..
Set
oNet
=
CreateObject("Wscript.Network")
sUser
=
oNet.UserName
sComputer
=
oNet.ComputerName
Set
oNet
=
Nothing
Dim
fso,
f1,
WshShell,
argu,
alllog,
lastlog
Dim
FileName
FileName=ServerLog
&
sUser
&
".txt"
Set
fso
=
CreateObject("Scripting.FileSystemObject")
If
Not
(fso.FileExists(FileName))
Then
Set
f1
=
fso.CreateTextFile(FileName,True)
f1.WriteLine
sUser
&
"
"
&
sComputer
f1.Close
Set
WshShell
=
Wscript.CreateObject("Wscript.Shell")
argu
=
FileName
&
"/T/E/G"
&
sUser
&
":f
/R
Everyone"
WshShell.run("cacls
"
&
argu)
Set
WshShell
=
Nothing
End
If
Set
f1
=
fso.OpenTextFile(FileName,
1,
True)
alllog
=
f1.readall
f1.Close
Set
f1
=
fso.OpenTextFile(FileName,
1,
True)
lastlog
=
f1.readline
f1.Close
If
Left(lastlog,
5)
=
"logon"
Then
'判断是否登入
If
InStr(lastlog,sComputer)
<
1
Then
'判断是否同一台机器,如果不是,往下运行
Set
f1
=
fso.OpenTextFile(FileName,
2,
True)
f1.WriteLine
(lastlog
&
Chr(13)
&
Chr(10)
&
"fail-so-logoff:"
&
Now()
&
"
"
&
sUser
&
"
at
"
&
scomputer
&
Chr(13)
&
Chr(10)
&
alllog)
f1.Close
Set
WshShell
=
Wscript.CreateObject("Wscript.Shell")
Dim
i,OldComputer
i=InStr(lastlog,"at")
OldComputer=Right(lastlog,Len(lastlog)-i-2)
WshShell.popup
"对不起:此账号已经在
"
&
OldComputer
&
"
上登入使用!出现此提示,如是你还没有登录,说明你的账号被盗,请及时上报技术部,谢谢合作!!!"
,
30
Set
WshShell
=
Nothing
Dim
os,
retcode
For
Each
os
In
GetObject("Winmgmts:{impersonationLevel=impersonate,(shutdown,remoteshutdown)}!//"
+
sComputer).InstancesOf("Win32_OperatingSystem")
retcode
=
os.Win32ShutDown(4,
0)
Next
Wscript.quit
Else
Set
f1
=
fso.OpenTextFile(FileName,
2,
True)
f1.WriteLine
("logon:
"
&
Now()
&
"
"
&
sUser
&
"
at
"
&
sComputer
&
Chr(13)
&
Chr(10)
&
alllog)
f1.Close
End
If
Else '没有登入
Set
f1
=
fso.OpenTextFile(FileName,
2,
True)
f1.WriteLine
("logon:
"
&
Now()
&
"
"
&
sUser
&
"
at
"
&
sComputer
&
Chr(13)
&
Chr(10)
&
alllog)
f1.Close
End
If
Set
f1
=
Nothing
Set
fso
=
Nothing
Wscript.quit
LOGOFF.VBS
option
explicit
dim
oNet,sUser,sComputer,ServerLog
ServerLog
=
"\\SERVERNAME\logctrl$\"
set
oNet=createobject("Wscript.Network")
sUser=oNet.UserName
sComputer=oNet.ComputerName
set
oNet=nothing
dim
fso,f1,alllog,lastlog
Dim
FileName
FileName=ServerLog
&
sUser
&
".txt"
set
fso=createobject("Scripting.filesystemobject")
set
f1=fso.opentextfile(FileName,1,true)
lastlog=f1.readline
f1.close
set
f1=fso.opentextfile(FileName,1,true)
alllog=f1.readall
f1.close
if
left(lastlog,5)="logon"
Then
If
InStr(lastlog,sComputer)
>
0
Then
'判断是否同一台机器,如果是,往下运行
Set
f1=fso.opentextfile(FileName,2,true)
f1.writeline("logoff:
"
&
Now()
&
"
"
&
suser
&
"
at
"
&
scomputer
&
Chr(13)
&
chr(10)
&
alllog)
f1.close
End
If
end
if
set
f1=nothing
set
fso=nothing
wscript.quit
我最初对蒋世滨先生写那遍文章感兴趣,试完之后觉得有存在一些问题,所以进行适当的修改.我在2000
ADVANCED
SERVER测试通过.
如大家在测试过程中出现的问题,可以进行深入探讨.