开发者社区


C++/C | Java | .Net/Windows | Linux/Unix | 开源 | 其他
首页 - 编程
编程
全文搜索:   

三个成员提交的管理脚本将会简化工作
作者: 开发者在线
2006-01-04 14:58:14


最近,TechRepublic 请成员提交他们最喜欢的网络管理脚本,并将择优发表。第一个提交脚本的是Lee Mason。由于他所做的努力,Lee获得300美元的奖励,并心满意足地看到自己的脚本刊登在TechRepublic上。

用你的管理脚本赚取100美元
我们会花钱买你的原创脚本,这样我们就可以将它们刊登在TechRepublic上以供下载,让你的IT同行从脚本编写技巧中受益。你只需为脚本添加适当的注释,以便我们了解脚本的用途及需要定制的变量。给我们发送你的原创Windows管理脚本,只要它在TechRepublic上作为下载项刊登出来,我们即付给你100美元。

自述

编者按:除了你下面看到的列表外,我还在工具条中放置了列表。工具条在剪切及粘贴脚本时更有用。如果不行的话,请在讨论时作一下提示,我会想出另外的解决方法。 

A

此脚本将一指定的域名组添加到一台特定计算机的指定本地组中。

(脚本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()


'Written by Lee Mason
'Platform: Outlook VBA
'Purpose: Checks inbox for read mail and (in this case) moves it to
'an folder. Also counts unread mail in mailbox.

------------------

On Error goto 1000

'Declares and initialised variables
Dim myOlApp As Application
Dim myNameSpace As NameSpace
Dim myibox As MAPIFolder
Dim mydelitems As MAPIFolder
Dim myitem As MailItem
Dim n As Integer
Dim unreadmail As Integer

n = 1
unreadmail = 0
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myibox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set mymovefolder = myibox.Folders("Old Items")

'Looks at items in the inbox and moves to
'Inbox/Old Items Folder if read, otherwise adds to the
'running count of unread items.

For n = 1 To myibox.Items.CountSet myitem = myibox.Items(n)If myitem.UnRead = True Thenunreadmail = unreadmail + 1Else: myitem.Move mymovefolderEnd IfNext n


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

责任编辑:张琎

查看本文的国际来源

声明:
Builder.com.cn(原ZDNet China应用开发频道)原创文章版权所有,未经许可严禁转载,且不构成投资建议。
近期相关报道:
[an error occurred while processing this directive]
实用技术文档
J2me XML
C/C++ C#
Java Oracle
Mysql .Net
VB.NET CSS
SQL Server 数据库
SQL UNIX
Linux Jsp
PHP Perl
Javascript IIS
XHTML ColdFusion
ASP/ASP.NET Apache
AJAX Software
数据库 操作系统
应用程序 互联网
订阅技术邮件
订阅"技术圈"杂志!请在下面选择您感兴趣的专题,填写e-mail地址,然后按订阅按钮:
应用开发管理
VS.NET 周刊
Database 周刊
WEB Service周刊
JAVA 周刊
IT 认证
Windows服务器周刊
互联网开发
当Windows Server 2008专家得5000元现金大奖
CNET NETWORKS 中国: 爱卡汽车网 | CNET科技资讯网 | e询网 | CWEEK | 蜂鸟网 | GameSpot China | 个人电脑 | PChome | SPN | 网友世界 | ZDNet China | 中关村在线
CNET NETWORKS 美国: BNET | CNET.com | CNET Download.com | CNET News.com | CNET Reviews | CNET Shopper.com | GameSpot | MP3.com | mySimon | Release 1.0 | Search.com | TechRepublic | TV.com | Webshots | ZDNet
Copyright (c) CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
ZDNet 公司标识是 CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号