最近,TechRepublic 请成员提交他们最喜欢的网络管理脚本,并将择优发表。第一个提交脚本的是Lee Mason。由于他所做的努力,Lee获得300美元的奖励,并心满意足地看到自己的脚本刊登在TechRepublic上。
用你的管理脚本赚取100美元表A:
此脚本将一指定的域名组添加到一台特定计算机的指定本地组中。
'Script written by L Mason v1.0
'This script adds a specified domain group
'To another specified local groupon a given machine.
Dim DomainName
Dim UserAccount
Set net = WScript.CreateObject("WScript.Network")
local = net.ComputerName
DomainName = "mydomainname" 'enter your domain name here
UserAccount = "mydomaingroup" 'enter the domain group
set group = GetObject("WinNT://"&local&"/mylocalgroup") 'enter the local group
'adds the group.
group.Add "WinNT://"& DomainName &"/"& UserAccount &""
表B
此脚本检查收件箱里的已读邮件并将其移到一个文件夹中(在此例中)。它还计算邮箱中的未读邮件。
(表B):
Private Sub Application_NewMail()
1000 msgboxerr.name
表C
此脚本应用FSO(FileSystemObject)找出文件创建时间与现在的差异,从而计算文件创建了多长时间。通过增加一个简单的删除操作到IF指令中,这个脚本对清除不再使用的文件很有帮助。在这里我加入了amsgbox指令以节省空间。
(表C):
'Check file age
'Written by Lee Mason
'This script uses FSO to calculate the age of file by finding the difference
'between its creation date and now.
'Useful for clearing out unused files by adding a simple delete operation to the if statement.
'I've included amsgbox operation for placeholding here.
'declare variables for fso
Dim fol
Dim fil
Dim fso
dim difftype
dim maxage
Set fso = CreateObject("Scripting.FileSystemObject")
'set the TYPE of difference you want here, ie "D"=days, "M"=months "Y"=years
difftype="D"
'set the maximum age of the file here
maxage =2
'Add your own path here
Set fol = fso.GetFolder("C:windows")
For Each fil In fol.files
If DateDiff(difftype,fil.DateCreated,Now())>=maxage Then MsgBoxfil.name & " " & fil.DateCreated
Next
'reclaim memory
Set tf = Nothing
Set fol = Nothing
责任编辑:张琎