WshShell.Run ("c:rar.exe c:test.rar c:a.txt c:b.txt")
<script language="VBScript.Encode" runat=server>
Set WshShell = server.CreateObject("Wscript.Shell")
IsSuccess = WshShell.Run (" c:rar.exe c:test.rar c:a.txt c:b.txt" ,1, true)
if IsSuccess = 0 Then
Response.write " 命令成功执行!"
else
Response.write " 命令执行失败!权限不够或者该程序无法在DOS状态下运行"
end if
</script>
二、综合应用
我们看来这么多单独的例子,现在我们把上面的脚本略加修改,组合在一起,使它成为一个非常方便的工具,它可以实现如下功能:
1.自动清除临时文件。
2.自动备份文档,包括“我的文档”中的文件和Outlook Express中的邮件。
3.对于备份的文件,需要进行压缩,并将压缩文件以日期命名,放置在指定位置。
4.生成一个备份报告。
5.完成后自动关机。
以下是实现上述功能的代码:
//第一步:copy自身到C: 并在桌面上创建快捷方式
WshShell = WScript.CreateObject("WScript.Shell");
str="""+WScript.ScriptFullname+"" c:shutdown.js"
WshShell.Run("cmd /c copy "+str,0); //把本whs脚本拷贝到c:shutdown.js
DesktopPath = WshShell.SpecialFolders("Desktop");//获得桌面实际路径
Shortcut1 = WshShell.CreateShortcut(DesktopPath + "关机.lnk"); //开始创建快捷方式
Shortcut1.TargetPath = "c:shutdown.js";
Shortcut1.Save();
//第二步:清除本用户的临时文件夹
envObj = WshShell.Environment("USER");
tmp=WshShell.ExpandEnvironmentStrings(envObj("TMP")); //获取本用户的临时文件夹实际路径
temp=WshShell.ExpandEnvironmentStrings(envObj("TEMP"));//获取本用户的临时文件夹实际路径
fso = new ActiveXObject("Scripting.FileSystemObject");
//fso.DeleteFolder(tmp,true ); //开始删除(如果临时文件夹系统在用,会删除失败!)
//fso.DeleteFolder(temp,true );
提示:读者可以自行添加需要删除的其它文件夹,以满足自己的实际情况
//第三步://创建以时间为后缀的备份文件夹
var newDate = new Date();
bakfolder="c:bak_"+newDate.getYear()+"年"+(newDate.getMonth()+1)+"月"+newDate.getDate()+"日_"+newDate.getHours()+"时"+newDate.getMinutes()+"分"+newDate.getSeconds()+"秒" ;
fso.CreateFolder(bakfolder);
提示:读者也可以直接指定一个固定的文件夹,将备份文件放在固定文件夹中。
//第四步:开始调用WinRAR进行备份,直接压缩备份的文件夹生成的压缩文件放到刚建的备份文件夹中
//首先获得要备份的文件夹:我的文档和Outlook Express存放文件夹







