﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-joan-文章分类-QTP</title><link>http://www.blogjava.net/joan/category/32987.html</link><description>私は张で
QQ:774199038

</description><language>zh-cn</language><lastBuildDate>Fri, 20 Aug 2010 02:13:13 GMT</lastBuildDate><pubDate>Fri, 20 Aug 2010 02:13:13 GMT</pubDate><ttl>60</ttl><item><title>自动化测试中如何利用WMI </title><link>http://www.blogjava.net/joan/articles/329360.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Thu, 19 Aug 2010 06:34:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/329360.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/329360.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/329360.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/329360.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/329360.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WMI即<a href="http://windows.chinaitlab.com/" target="_blank">Windows</a>管理规范，是用户管理本地和远程计算机的一种模型。通过它可以访问、配置、管理和监视几乎所有的 <a href="http://windows.chinaitlab.com/" target="_blank">Windows</a> 资源。WMI的语法十分简单，基本上常见的命名空间、对象等用几乎一模一样。它对应的是Windows里的WMI服务（winmgmt）
<p>　　WMI实际是由两部分组成：CIM库和WMI脚本对象库。在具体使用过程中，我们是通过WMI脚本对象库去访问CIM库，管理托管的资源。也就是说，在我们编写脚本的过程大致可以分为这么几步：</p>
<p>　　1）创建WMI对象脚本库的指针实例；</p>
<p>　　2）调用其实例的方法，连接到CIM库，并指明需要访问的资源的逻辑位置；</p>
<p>　　3）获得托管资源也就是类的实例的集合；</p>
<p>　　4）枚举实例，完成工作</p>
<p>　　WMI的命名空间共有16个，不过我们常用的只有两个：</p>
<p>　　1）root\cimv2&nbsp; 在这个命名空间里包括了绝大多数与计算机、操作系统相关联的类。</p>
<p>　　2）root\default&nbsp; 管理注册表的类</p>
<p>　　给出两个实例参考：</p>
<p>　　在日志报告中记录<a href="http://softtest.chinaitlab.com/" target="_blank">测试</a>机器的地址：</p>
<p>&nbsp;</p>
<table style="border-right: rgb(153,153,153) 1px solid; border-top: rgb(153,153,153) 1px solid; font-size: 12px; border-left: rgb(153,153,153) 1px solid; width: 80%; border-bottom: rgb(153,153,153) 1px solid; background-color: rgb(221,221,221)" align="center">
    <tbody>
        <tr>
            <td>
            <p>Public Function GetIP()<br />
            &nbsp;'获取<a href="http://softtest.chinaitlab.com/" target="_blank">测试</a>机器的IP<br />
            &nbsp; ComputerName="."<br />
            &nbsp; Dim objWMIService,colItems,objItem,objAddress<br />
            &nbsp;Set ōbjWMIService = GetObject("winmgmts:\\" &amp; ComputerName &amp; "\root\cimv2")<br />
            &nbsp; Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")<br />
            &nbsp;For Each objItem in colItems<br />
            &nbsp;&nbsp;&nbsp;&nbsp; For Each objAddress in objItem.IPAddress<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If objAddress &lt;&gt; "" Then<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetIP = objAddress<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
            &nbsp;&nbsp;&nbsp;&nbsp; Next<br />
            &nbsp; Next<br />
            End Function</p>
            </td>
        </tr>
    </tbody>
</table>
<p>　　如何在判断进程是否存在：</p>
Function ProcessExist(processName)<br />
&nbsp; For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process")<br />
&nbsp;&nbsp; If Process.Name = processName Then<br />
&nbsp;&nbsp;&nbsp;&nbsp; ProcessExist = True<br />
&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br />
&nbsp; End If<br />
&nbsp;Next<br />
&nbsp;ProcessExist = False<br />
End Function
<img src ="http://www.blogjava.net/joan/aggbug/329360.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2010-08-19 14:34 <a href="http://www.blogjava.net/joan/articles/329360.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>遍历个人电脑盘符信息脚本(qtp) 原创</title><link>http://www.blogjava.net/joan/articles/320136.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Wed, 05 May 2010 09:18:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/320136.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/320136.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/320136.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/320136.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/320136.html</trackback:ping><description><![CDATA[<br />
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">'Company:&nbsp;&#215;&#215;&#215;&#215; <br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">'自我学习系列</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">'Author: joan ''<br />
'Product: Test<br />
'Date: 2010.5.5</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">'''''''''''''''''''''''''''''''''''''''''''''''''''''</span></span></span></p>
<p><br />
<span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">Function dirvesmsg<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg = "驱动器名称：" &amp; objDrive.DriveLetter &amp; "&nbsp;&nbsp; "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg =msg &amp; "文件系统的类型：" &amp; objDrive.FileSystem &amp;"&nbsp; "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg = msg &amp; "驱动器总容量：" &amp; int(objDrive.TotalSize/(1024*1024*1024)) &amp; "G "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg = msg &amp; "剩余空间总量：" &amp; int(objDrive.FreeSpace/(1024*1024*1024)) &amp; "G&nbsp; "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgbox msg&nbsp; '<br />
End Function</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">&nbsp;</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">' 创建FileSystemObject对象<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
' 创建Drives集合，并赋值给colDrives<br />
Set colDrives = objFSO.Drives<br />
' 遍历Drives集合</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">For Each objDrive in colDrives<br />
'判断驱动器是否已准备好<br />
&nbsp;If objDrive.IsReady Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dirvesmsg&nbsp; ' 调用&nbsp; Function <br />
&nbsp; End If<br />
Next<br />
reporter.ReportEvent&nbsp; micDone ,"遍历Drives集合",msg<br />
<br />
</span></span></span></p>
<p><span style="font-size: 12pt"><span style="font-family: Comic Sans MS"><span style="font-family: Georgia">详细内容原文我的QQ blog </span></span></span></p>
<img src ="http://www.blogjava.net/joan/aggbug/320136.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2010-05-05 17:18 <a href="http://www.blogjava.net/joan/articles/320136.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>qtp 视频收藏</title><link>http://www.blogjava.net/joan/articles/318524.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Fri, 16 Apr 2010 07:11:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/318524.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/318524.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/318524.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/318524.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/318524.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
1. 小布作品：QTP培训系列 - 1QTP的概述<br />
在线观看： http://www.boobooke.com/v/bbk3207<br />
视频下载： http://www.boobooke.com/v/bbk3207.zip<br />
2. 小布作品：QTP培训系列 - 2<br />
讲解了QTP的测试规划<br />
在线观看： http://www.boobooke.com/v/bbk3302<br />
视频下载： http://www.boobooke.com/v/bbk3302.zip<br />
3. 小布作品：QTP培训系列 - 3<br />
继续介绍QTP的测试规划<br />
在线观看： http://www.boobooke.com/v/bbk3303<br />
视频下载： http://www.boobooke.com/v/bbk3303.zip<br />
4. 小布作品：QTP培训系列 - 4<br />
QTP录制之前的注意要点<br />
在线观看： http://www.boobooke.com/v/bbk3307<br />
视频下载： http://www.boobooke.com/v/bbk3307.zip<br />
5. 小布作品：QTP培训系列 - 5<br />
介绍QTP录制和回放<br />
在线观看： http://www.boobooke.com/v/bbk3308<br />
视频下载： http://www.boobooke.com/v/bbk3308.zip<br />
6. 小布作品：QTP培训系列 - 6<br />
介绍QTP的对象库<br />
在线观看： http://www.boobooke.com/v/bbk3309<br />
视频下载： http://www.boobooke.com/v/bbk3309.zip<br />
7. 小布作品：QTP培训系列 - 7<br />
继续介绍QTP的对象库<br />
在线观看： http://www.boobooke.com/v/bbk3310<br />
视频下载： http://www.boobooke.com/v/bbk3310.zip<br />
8. 小布作品：QTP培训系列 - 8<br />
介绍QTP的同步点<br />
在线观看： http://www.boobooke.com/v/bbk3311<br />
视频下载： http://www.boobooke.com/v/bbk3311.zip<br />
9. 小布作品：QTP培训系列 - 9<br />
介绍QTP的检查点<br />
在线观看： http://www.boobooke.com/v/bbk3312<br />
视频下载： http://www.boobooke.com/v/bbk3312.zip<br />
10. 小布作品：QTP培训系列 - 10<br />
继续介绍QTP的检查点<br />
在线观看： http://www.boobooke.com/v/bbk3313<br />
视频下载： http://www.boobooke.com/v/bbk3313.zip<br />
<br />
 <img src ="http://www.blogjava.net/joan/aggbug/318524.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2010-04-16 15:11 <a href="http://www.blogjava.net/joan/articles/318524.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>谈Scripting.FileSystemObject对象</title><link>http://www.blogjava.net/joan/articles/302720.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Tue, 17 Nov 2009 08:32:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/302720.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/302720.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/302720.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/302720.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/302720.html</trackback:ping><description><![CDATA[<p>谈Scripting.FileSystemObject对象<br />
FileSystemObject对象提供对计算机文件系统的访问，它允许我们在代码内操作文本文件、文件夹及驱动器。它是脚本运行期库提供的对象之一，对于服务器ASP页面内的VBScript和JScript都有效。如果页面的扩展名为.hta（表示它们是HTA的一部分），它也可用在客户端的IE 5中。本节仅讨论在服务器上的ASP脚本如何使用FileSystemObject对象。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 超级文本应用程序（HTA）由指定的&#8220;受信任的&#8221;页面组成，在页面的&lt;HEAD&gt;段里包含&lt;HTA: APPLICATION&gt;元素。例如：<br />
&nbsp;&nbsp;&nbsp; &lt;HTA:APPLICATION ID=&#8221;objMyApp&#8221; APPLICATIONNAME=&#8221;myApp&#8221;&gt;<br />
这些页面可以使用客户端脚本引擎中的一些不常用特性，这些特性中有FileSystemObject对象和TextStream对象。关于超级文本应用程序的更多信息，请访问Microsoft Workshop网站。<br />
可以使用下面的程序创建一个FileSystemObject对象实例：<br />
&#8216; In VBScript:<br />
Dim objMyFSO<br />
Set objMyFSO = Server.CreateObject(&#8220;Scripting.FileSystemObject&#8221;)</p>
<p>// In JScript:<br />
var objMyFSO = Server.CreateObject(&#8216;Scripting.FileSystemObject&#8217;);</p>
<p>&lt;!-- Server-side with an OBJECT element --&gt;<br />
&lt;OBJECT RUNAT=&#8221;SERVER&#8221; SCOPE=&#8221;PAGE&#8221; ID=&#8221;objFSO&#8221;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PROGID=&#8221;Scripting.FileSystemObject&#8221;&gt;<br />
&lt;/OBJECT&gt;<br />
在ASP页面里，增加一个对于FileSystemObject类型库的引用是非常有用的。这允许使用它直接定义的内置常数，不用像过去那样用数字等效表达式代替。整个脚本运行期库的类型库可以增加到任何ASP页面中，代码如下：<br />
&lt;!-- METADATA TYPE=&#8221;typelib&#8221; FILE=&#8221;C:WinNTSystem32scrrun.dll&#8221; --&gt;如果你是在另一个目录下安装Windows，必须编辑FILE的属性值。<br />
5.4.1 FileSystemObject对象成员概要<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileSystemObject对象提供一个属性和一系列方法，可用它们来操纵FileSystemObject对象实现的一些从属对象。这里提供了全部的内容概要，然后介绍每一个从属对象。<br />
1．&nbsp; FileSystemObject的属性<br />
FileSystemObject对象只有一个属性，它用于得到当前机器上的所有有效驱动器的列表，如表5-4所示：<br />
表5-4&nbsp; FileSystemObject对象的属性及说明<br />
属 性 <br />
说 明 </p>
<p>Drivers <br />
返回本地计算机可用的驱动器列表。 </p>
<p>2．&nbsp; FileSystemObject的方法<br />
FileSystemObject对象提供了使用从属对象的一系列方法，从属对象包括Drive、Folder和File等对象。它也实现了用于TextStream对象的两个方法：CreateTextFile和OpenTextFile。根据所使用的对象的类型，将方法划分为三类。<br />
(1)&nbsp;&nbsp;&nbsp; 与驱动器有关的方法<br />
与驱动器有关的方法如表5-5所示：<br />
表5-5 与驱动器有关的方法及说明<br />
方 法 <br />
说 明 </p>
<p>DriveExists(drivespec) <br />
如果在drivespec中指定的驱动器存在，则返回True，否则返回False。drivespec参数可以是一个驱动器字母，或者是文件、文件夹的完整绝对路径 </p>
<p>GetDrive(drivespec) <br />
返回drivespec指定的驱动器所对应的Drive对象。drivespec可以包含冒号、路径分隔符或者是网络共享名，即：&#8220;C&#8221;、&#8220;C:&#8221;、&#8220;C:&#8221;及&#8220;\machinesharename&#8221; </p>
<p>GetDriveName(drivespec) <br />
用字符串返回drivespec指定的驱动器的名称。drivespec参数必须是文件或文件夹的绝对路径，或者仅仅是驱动器字母，例如：&#8220;c:&#8221;或&#8220;c&#8221; </p>
<p>(2)&nbsp;&nbsp;&nbsp; 与文件夹有关的方法<br />
与文件夹有关的方法如表5-6所示：<br />
表5-6&nbsp; 与文件夹有关的方法及说明<br />
方 法 <br />
说 明 </p>
<p>BuildPath(path,name) <br />
在已有的路径path上增添名字为name的文件或文件夹，如果需要，则增添路径分隔符&#8217;&#8217; </p>
<p>CopyFolder(source,destination,overwrite) <br />
从指定的源文件夹source（可以包含通配符）中复制一个或多个文件夹到指定的目标文件夹destination，包含了源文件夹中的所有文件。如果source包含通配符或destination末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是要放置源文件夹的拷贝的文件夹。否则的话，认为destination是要创建的新文件夹的路径名。如果destination文件夹已经存在且overwrite参数设置为False，将产生错误，缺省的overwrite参数是True </p>
<p>CreateFolder(foldername) <br />
创建一个路径名为foldername的文件夹。如果foldername已经存在将产生错误 </p>
<p>DeleteFolder(folderspec,force) <br />
删除由folderspec指定的一个或多个文件夹（可以在路径的最后部分包含通过配符）及文件夹中的所有内容。如果可选的force参数设置为true，那么即使文件夹包含的文件具有只读属性，也将删除该文件夹。缺省的force参数是False </p>
<p>FolderExist(folderspec) <br />
如果folderspec指定的文件夹存在则返回True，否则返回False。folderspec参数可以包含文件夹的绝对或相对路径，或者仅仅是当前文件夹中看到的文件夹名 </p>
<p>GetAbsolutePathName(pathspec) <br />
返回明确指定文件夹的路径，其中要考虑到当前文件夹的路径。例如，如果当前文件夹是&#8220;c:docssales&#8221;，而pathspec是&#8220;jan&#8221;，返回的字符是&#8220;cocssalesjan&#8221;。通配符、&#8221;..&#8221;和&#8221;\&#8221;路径操作符都是可以接受的 </p>
<p>GetFolder(folderspec) <br />
返回folderspec指定的文件夹对应的Folder对象。folderspec可以是文件夹的相对的或绝对的路径 </p>
<p>GetParentFolderName(pathspec) <br />
返回pathspec文件或文件夹的上一级文件夹。不检验该文件夹是否存在 </p>
<p>GetSpecialfolder(folderspec) <br />
返回一个特定的Windows文件夹相对应的Folder对象。参数folderspec的允许值是WindowsFolder(0)、SystemFolder(1)和TemporaryFolder(2) </p>
<p>MoveFolder(source,destination) <br />
将source指定的一个或多个文件夹移动到destination指定的文件夹。在source里可以包含通配符，但在destination中不行。如果source包含通配符或destination末尾是路径分隔符(&#8216;&#8217;)，则认为destination是要放置源文件夹的文件夹，否则认为它是一个新文件夹的完整路径和名字。如果目的文件夹destination已经存在则产生错误 </p>
<p>(3)&nbsp;&nbsp;&nbsp; 与文件有关的方法<br />
与文件有关的方法如表5-7所示：<br />
方 法 <br />
说 明 </p>
<p>CopyFile(source,destination,<br />
overwrite) <br />
将source（可包含通配符）指定的一个或多个文件复制到指定的目标文件夹destination。如果source包含通配符或destination末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是文件夹。否则认为destination为一新文件的完全路径和名称。如果目标文件夹已经存在且overwrite参数设置为False，将产生错误。缺省的overwrite参数是True </p>
<p>CreateTextFile(filename,overwrite,<br />
unicode) <br />
用指定的文件名filename在磁盘上创建一个新的文本文件，并返回与其对应的TextStream对象，如果可选的overwrite参数设置为True，则覆盖同一路径下已有的同名文件。缺省的overwrite参数是False。如果可选的unicode参数设置为True，则该文件的内容将存储为Unicode文本，缺省的unicode参数是False </p>
<p>DeleFile(filespec,force) <br />
删除由filespec指定的一个或多个文件（可以在路径的最后部分包含通配符）。如果可选的force参数设置为true，那么也删除具有只读属性的文件。缺省的force参数是False </p>
<p>FileExists(filespec) <br />
如果filespec指定的文件存在则返回True，否则返回False。filespec参数可以包含文件的绝对路径或相对路径，或者是当前文件夹中的文件名 </p>
<p>GetBaseName(filespec) <br />
返回filespec指定的文件的名称，即包含文件路径但去掉了文件的扩展名 </p>
<p>GetExtensionName(filespec) <br />
返回filespec指定的文件的扩展名 </p>
<p>GetFile(filespec) <br />
返回filespec指定的文件所对应的File对象。可以指定文件的相对或绝对路径 </p>
<p>GetFileName(pathspec) <br />
返回pathspec指定的文件的路径或文件名，如果没有文件名就返回最后的文件夹名。不检查该文件或文件夹是否存在 </p>
<p>GetTempName() <br />
返回一个随机产生的文件名，用于完成运算所需的临时文件或文件夹 </p>
<p>MoveFile(source,destination) <br />
将source指定的一个或多个源文件移动到destination指定的目的文件夹。在source里可以包含通配符，但destination不行。如果source包含通过配符或destination末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是一文件夹。否则，认为destination是一新文件夹的完整路径和名称。如果目的文件夹已经存在则产生错误 </p>
<p>OpenTextFile(filename,iomode,create,<br />
&nbsp;&nbsp;&nbsp; format) <br />
创建一个名叫做filename的文件，或打开一个现有的名为filename的文件，并且返回一个与其相关的TextStream对象。filename参数可以包含绝对或相对路径。iomode参数指定了所要求的访问类型。允许的数值是ForReading(1)（缺省）、ForWriting(2)、ForAppending(8)。当写入或追加到一个不存在的文件时，如果create参数设置为true，就将创建一个新文件。缺省的create参数是False。format参数说明对文件读或写的数据格式。允许数值是：TristatetFalse(0)（缺省），按照ASCII格式打开；TristatetTrue(-1)，按照Unicode格式打开；TristateDefault(-2)，用系统缺省格式打开 </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Unicode文件使用两个字节标识每个字符，取消了ASCII字符最多256个的限制。</p>
<p>5.4.2 使用驱动器<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下面是使用FileSystemObject对象的简单例子，它使用DriveExists方法得到现有的驱动器字母的列表：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; In VBScript<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objFSO = Server.CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For intCode = 65 To 90&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;ANSI codes for &#8216;A&#8217; to &#8216;Z&#8217;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strLetter = Chr(intCode)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If objFSO.DriveExists(strLetter) Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write &#8220;Found drive &#8220; &amp; strLetter &amp; &#8220;:&lt;BR&gt;&#8221;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 或用JScript：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // In Jscript<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var objFSO = Server.CreateObject(&#8216;Scripting.FileSystemObject&#8217;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (var intCode = 65; intCode &lt;= 90; intCode++) {&nbsp;&nbsp;&nbsp; //ANSI codes for &#8216;A&#8217; to &#8216;Z&#8217;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strLetter = String.formCharCode(intCode);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (objFSO.DriveExists(strLetter))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write (&#8216;Found drive &#8216; + strLetter + &#8220;:&lt;BR&gt;&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这两个程序段的运行结果是相同的，如图5-9所示：</p>
<p><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这一页面为driveexists_vb.asp，由本书的示例文件提供。<br />
1．&nbsp; Drive对象<br />
正如已经看到的，FileSystemObject对象包含一个属性——Drives，它返回一个包括本地计算机上所有可用驱动器的集合。<br />
Drives集合里的每个条目是一个Drive对象。Drive对象的属性如表5-8所示：<br />
表5-8&nbsp; Drive对象的属性及说明<br />
属 性 <br />
说 明 </p>
<p>AvailableSpave <br />
考虑了帐户定额和/或其他限制，返回驱动器上对于该用户可用的空间的大小 </p>
<p>DriveLetter <br />
返回驱动器的字母 </p>
<p>DriveType <br />
返回驱动器的类型。返回值可以是Unknown(0)、Removeable(1)、Fixed(2)、Network(3)、CDRom(4)和RamDisk(5)。然而需要注意的是当前版本的scrrun.dll不支持预定义常数Network，必须使用十进制3来代替 </p>
<p>FileSystem <br />
返回驱动器文件系统的类型。返回值包括&#8220;FAT&#8221;、&#8220;NTFS&#8221;和&#8220;CDFS&#8221; </p>
<p>FreeSpace <br />
返回驱动器上可用剩余空间的总量 </p>
<p>IsReady <br />
返回一个布尔值表明驱动器是否已准备好 </p>
<p>Path <br />
返回一个由驱动器字母和冒号组成的驱动器路径，即&#8220;C:&#8221; </p>
<p>RootFolder <br />
返回代表的驱动器根目录文件夹的Folder对象 </p>
<p>SerialNumber <br />
返回一个用于识别磁盘卷的十进制的序列号 </p>
<p>ShareName <br />
如果是一个网络驱动器，返回该驱动器的网络共享名 </p>
<p>TotalSize <br />
返回驱动器的总容量（以字节为单位） </p>
<p>VolumeName <br />
设定或返回本地驱动器卷名 </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 因此，通过使用Drives集合里的Drive对象，可以在服务器上产生一个驱动器列表，与通过检查每个可能的驱动器字母来判别驱动器是否存在的方法相比，效率更高。我们也可以得到关于该驱动器的信息。在VBScript里，代码如下：<br />
' In VBScript:<br />
' create a FileSystemObject instance<br />
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")<br />
' create a Drives collection<br />
Set colDrives = objFSO.Drives<br />
' iterate through the Drives collection<br />
For Each objDrive in colDrives</p>
<p>&nbsp; Response.Write "DriveLetter: &lt;B&gt;" &amp; objDrive.DriveLetter &amp; "&lt;/B&gt;&nbsp;&nbsp; "<br />
&nbsp; Response.Write "DriveType: &lt;B&gt;" &amp; objDrive.DriveType<br />
&nbsp; Select Case objDrive.DriveType<br />
&nbsp;&nbsp;&nbsp; Case 0: Response.Write " - (Unknown)"<br />
&nbsp;&nbsp;&nbsp; Case 1: Response.Write " - (Removable)"<br />
&nbsp;&nbsp;&nbsp; Case 2: Response.Write " - (Fixed)"<br />
&nbsp;&nbsp;&nbsp; Case 3: Response.Write " - (Network)"<br />
&nbsp;&nbsp;&nbsp; Case 4: Response.Write " - (CDRom)"<br />
&nbsp;&nbsp;&nbsp; Case 5: Response.Write " - (RamDisk)"<br />
&nbsp; End Select<br />
&nbsp; Response.Write "&lt;/B&gt;&nbsp;&nbsp; "</p>
<p>If objDrive.DriveType = 3 Then<br />
&nbsp;&nbsp;&nbsp; If objDrive.IsReady Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write "Remote drive with ShareName: &lt;B&gt;" &amp; objDrive.ShareName &amp; "&lt;/B&gt;"<br />
&nbsp;&nbsp;&nbsp; Else<br />
Response.Write "Remote drive - &lt;B&gt;IsReady&lt;/B&gt; property returned_<br />
&lt;B&gt;False&lt;/B&gt;&lt;BR&gt;"<br />
&nbsp;&nbsp;&nbsp; End If<br />
&nbsp; Else If objDrive.IsReady then <br />
&nbsp;&nbsp;&nbsp; Response.Write "FileSystem: &lt;B&gt;" &amp; objDrive.FileSystem &amp; "&lt;/B&gt;&nbsp;&nbsp; "<br />
&nbsp;&nbsp;&nbsp; Response.Write "SerialNumber: &lt;B&gt;" &amp; objDrive.SerialNumber &amp; "&lt;/B&gt;&lt;BR&gt;"<br />
Response.Write "Local drive with VolumeName: &lt;B&gt;" &amp; _<br />
objDrive.VolumeName &amp; "&lt;/B&gt;&lt;BR&gt;"<br />
Response.Write "AvailableSpace: &lt;B&gt;" &amp; FormatNumber( _<br />
objDrive.AvailableSpace / 1024, 0) &amp; "&lt;/B&gt; KB&nbsp;&nbsp; "<br />
Response.Write "FreeSpace: &lt;B&gt;" &amp; FormatNumber( _<br />
objDrive.FreeSpace / 1024, 0) &amp; "&lt;/B&gt; KB&nbsp;&nbsp; "<br />
Response.Write "TotalSize: &lt;B&gt;" &amp; FormatNumber(_ <br />
objDrive.TotalSize / 1024, 0) &amp; "&lt;/B&gt; KB"<br />
&nbsp; End if&nbsp; <br />
&nbsp; Response.Write "&lt;P&gt;"<br />
&nbsp; End if<br />
Next<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注意，不能用预定义常数Network比较驱动器的DriveType属性，因为（至少在scrrun.dll的当前版本中）在类型库中省略了Network常数，因此不再作为公用的常数使用。<br />
在JScript中，该程序是：<br />
// In JScript:<br />
// create a FileSystemObject instance<br />
var objFSO = Server.CreateObject('Scripting.FileSystemObject');<br />
// create a Drives collection<br />
var colDrives = new Enumerator(objFSO.Drives);</p>
<p>for (; !colDrives.atEnd(); colDrives.moveNext()) {<br />
&nbsp; objDrive = colDrives.item();<br />
&nbsp; Response.Write('DriveLetter: ' + objDrive.DriveLetter + '&lt;BR&gt;');<br />
&nbsp; Response.Write('DriveType: ' + objDrive.DriveType + '&lt;BR&gt;');</p>
<p>&nbsp; if (objDrive.DriveType == 3)<br />
&nbsp;&nbsp;&nbsp; if (objDrive.IsReady) <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write('Remote drive with ShareName: ' + <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDrive.ShareName + '&lt;BR&gt;')<br />
&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write('Remote drive - IsReady property returned False&lt;BR&gt;&lt;BR&gt;');<br />
&nbsp;&nbsp;&nbsp; else if (objDrive.IsReady) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write('Local drive with VolumeName: ' + <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDrive.VolumeName + '&lt;BR&gt;');<br />
&nbsp;&nbsp;&nbsp; Response.Write('FileSystem: ' + objDrive.FileSystem + '&lt;BR&gt;');<br />
&nbsp;&nbsp;&nbsp; Response.Write('SerialNumber: ' + objDrive.SerialNumber + '&lt;BR&gt;');<br />
&nbsp;&nbsp;&nbsp; Response.Write('AvailableSpace: ' + objDrive.AvailableSpace + ' bytes&lt;BR&gt;');<br />
&nbsp;&nbsp;&nbsp; Response.Write('FreeSpace: ' + objDrive.FreeSpace + ' bytes&lt;BR&gt;');<br />
&nbsp;&nbsp;&nbsp; Response.Write('TotalSize: ' + objDrive.TotalSize + ' bytes&lt;P&gt;');<br />
}<br />
}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在系统上运行这段程序以前有一点要注意。如果在A驱动器里没有磁盘，或CD-ROM驱动器里没有光盘，将得到一个错误提示：&#8220;Disk Not Ready&#8221;。除了DriveLetter属性和DriveType属性外，在使用其他属性和方法前，通过检查每个驱动器的IsReady属性，可以保护该页面。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当在服务器上运行以上VBScript代码时，运行结果如图5-10所示。这一页面为drivescollection_vb.asp，来自本书提供的示例文件。</p>
<p>2．&nbsp; 文件系统定位<br />
FileSystemObject的几个方法可用于得到其他对象的引用，因此可以在服务器的文件系统和任何网络驱动器中定位。事实上，在ASP代码里使用的所有对象或组件中，除了ActiveX Data Object组件，FileSystemObject对象很可能是最复杂的对象之一。<br />
这种复杂性是由于对如何访问文件系统的不同部分，要求有极高的灵活性。例如，可以从FileSystemObject向下通过使用各种从属对象定位一个文件。其过程是从Drives集合开始，到一个Drive对象，再到驱动器的根Folder对象，然后到子Folder对象，再到文件夹的Files集合，最后到集合内的File对象。<br />
另外，如果已知要访问的驱动器、文件夹或文件。可以直接对其使用GetDrive、GetFolder、GetSpecialFolder和GetFile方法。图5-11有助于理解所有文件系统定位相关的组件、对象、方法和属性之间的关系。</p>
<p>1．&nbsp; Folder对象<br />
Driver对象的RootFolder属性返回一个Folder对象，通过该对象可访问这个驱动器内的所有的内容。可以使用这个Folder对象的属性和方法遍历驱动器上的目录，并得到该文件夹和其他文件夹的属性。<br />
(1)&nbsp;&nbsp;&nbsp; Folder对象的属性<br />
Folder对象提供一组属性，可用这些属性得到关于当前文件夹的更多信息，也可以改变该文件夹的名称。其属性及说明如表5-9所示：<br />
表5-9&nbsp; Folder 对象的属性及说明<br />
属 性 <br />
说 明 </p>
<p>Attributes <br />
返回文件夹的属性。可以是下列值中的一个或其组合：Normal(0)、ReadOnly(1)、Hidden(2)、System(4)、Volume(名称)(8)、Directory（文件夹）(16)、Archive(32)、Alias(64)和Compressed(128)。例如，一个隐藏的只读文件，Attributes的值为3 </p>
<p>DateCreated <br />
返回该文件夹的创建日期和时间 </p>
<p>DateLastAccessed <br />
返回最后一次访问该文件夹的日期和时间 </p>
<p>DateLastModified <br />
返回最后一次修改该文件夹的日期和时间 </p>
<p>Drive <br />
返回该文件夹所在的驱动器的驱动器字母 </p>
<p>Files <br />
返回Folder对象包含的Files集合，表示该文件夹内所有的文件 </p>
<p>IsRootFolder <br />
返回一个布尔值说明该文件夹是否是当前驱动器的根文件夹 </p>
<p>Name <br />
设定或返回文件夹的名字 </p>
<p>ParentFolder <br />
返回该文件夹的父文件夹对应的Folder对象 </p>
<p>Path <br />
返回文件夹的绝对路径，使用相应的长文件名 </p>
<p>ShortName <br />
返回DOS风格的8.3形式的文件夹名 </p>
<p>ShortPath <br />
返回DOS风格的8.3形式的文件夹的绝对路径 </p>
<p>Size <br />
返回包含在该文件夹里所有文件和子文件夹的大小 </p>
<p>SubFolers <br />
返回该文件夹内包含的所有子文件夹对应的Folders集合，包括隐藏文件夹和系统文件夹 </p>
<p>Type <br />
如果可能，返回一个文件夹的说明字符串（例如，&#8220;Recycle Bin&#8221;）<br />
(2)&nbsp;&nbsp;&nbsp; Folder对象的方法<br />
Folder对象提供一组可用于复制、删除和移动当前文件夹的方法。这些方法的运行方式与FileSystemObject对象的CopyFolder、DeleFolder和MoveFolder方法相同，但这些方法不要求source参数，因为源文件就是这个文件夹。这些方法及说明如表5-10所示：<br />
表5-10&nbsp; Folder对象的方法及说明<br />
方 法 <br />
说 明 </p>
<p>Copy(destination,overwrite) <br />
将这个文件夹及所有的内容复制到destination指定的文件夹。如果destination的末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是放置拷贝文件夹的一个文件夹。否则认为destination是要创建的新文件夹的路径和名字。如果目标文件夹已经存在且overwrite参数设置为False，将产生错误，缺省的overwrite参数是True </p>
<p>Delete(force) <br />
删除文件夹及里面的所有内容。如果可选的force参数设置为True，即使文件夹设置为只读或含有只读的文件，也将删除该文件夹。缺省的force是False </p>
<p>Move(destination) <br />
将文件夹及里面所有的内容移动到destination指定的文件夹。如果destination的末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是放置移动文件夹的一个文件夹。否则认为destination是一个新的文件夹的路径和名字。如果目标文件夹已经存在，则出错 </p>
<p>CreateTextFile<br />
(filename,overwrite,unicode) <br />
用指定的文件名在文件夹内创建一个新的文本文件，并且返回一个相应的TextStream对象。如果可选的overwrite参数设置为True，将覆盖任何已有的同名文件。缺省的overwrite参数是False。如果可选的unicode参数设置为True，文件的内容将存储为unicode文本。缺省的unicode是False </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在文件夹之间可以使用当前文件夹的ParentFolder属性，返回到父目录。当到达一个文件夹时，如果IsRootFolder属性是True，就停下来。离开驱动器的根目录，沿目录树向下，可遍历或访问在Folders集合（由当前文件夹的SubFolders属性返回）内的指定文件夹。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下列程序遍历了驱动器C根目录内的所有文件夹，并显示各个文件夹的有关信息。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VBScript程序如下：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'In VBScript:<br />
' Create a FileSystemObject instance<br />
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")<br />
' Get a reference to drive C<br />
Set objDriveC = objFSO.GetDrive("C:")<br />
' Get a reference to the root folder<br />
Set objRoot = objDriveC.RootFolder<br />
' Get a reference to the SubFolders collection<br />
Set objFolders = objRoot.SubFolders<br />
' Get a reference to the first folder in the SubFolders collection<br />
For Each objFolder In objFolders<br />
&nbsp; Set objFolder1 = objFolders.Item((objFolder.Name))<br />
&nbsp; Exit For<br />
Next<br />
' Iterate through all the files in this folder<br />
For Each objFile in objFolder1.Files<br />
&nbsp; Response.Write "Name: " &amp; objFile.Name &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "ShortName: " &amp; objFile.ShortName &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "Size: " &amp; objFile.Size &amp; " bytes&nbsp;&nbsp;&nbsp; "<br />
&nbsp; Response.Write "Type: " &amp; objFile.Type &amp; "&lt;BR&gt;"<br />
&nbsp; Response.Write "Path: " &amp; objFile.Path &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "ShortPath: " &amp; objFile.ShortPath &amp; "&lt;BR&gt;"<br />
&nbsp; Response.Write "Created: " &amp; objFile.DateCreated &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "LastModified: " &amp; objFile.DateLastModified &amp; "&lt;P&gt;"<br />
Next<br />
JScript程序如下：<br />
//In JScript:<br />
// Create a FileSystemObject instance<br />
var objFSO = Server.CreateObject('Scripting.FileSystemObject');<br />
// Get a reference to drive C<br />
var objDriveC = objFSO.GetDrive('C:');<br />
// Get a reference to the root folder<br />
var objRoot = objDriveC.RootFolder;<br />
// Get a reference to the first folder in the SubFolders collection<br />
var colAllFolders = new Enumerator(objRoot.SubFolders);<br />
var objFolder1 = colAllFolders.item();<br />
// Get a reference to the Files collection for this folder<br />
var colFiles = new Enumerator(objFolder1.Files);</p>
<p>// Iterate through all the files in this collection<br />
for (; !colFiles.atEnd(); colFiles.moveNext()) {<br />
&nbsp; objFile = colFiles.item()<br />
&nbsp; Response.Write('Name: ' + objFile.Name + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('ShortName: ' + objFile.ShortName + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Size: ' + objFile.Size + ' bytes&nbsp;&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Type: ' + objFile.Type + '&lt;BR&gt;');<br />
&nbsp; Response.Write('Path: ' + objFile.Path + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('ShortPath: ' + objFile.ShortPath + '&lt;BR&gt;');<br />
&nbsp; Response.Write('Created: ' + objFile.DateCreated + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Accessed: ' + objFile.DateLastAccessed + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Modified: ' + objFile.DateLastModified + '&lt;P&gt;');<br />
}<br />
该VBScript程序在服务器上运行时的结果如图5-12所示。该页面为folderscollection_vb.asp，来自本书提供的示例文件。</p>
<p>(3)&nbsp;&nbsp;&nbsp; 使用特殊文件夹<br />
GetSpecialFolder是FileSystemObject对象的方法之一，它返回计算机上三个&#8220;特殊文件夹&#8221;对应的Folder对象：<br />
&#183; WindowsFolder：%Windows%目录，缺省为WinNT（或Windows，在非NT/2000计算机上）目录。<br />
&#183; SystemFolder：%System%目录，缺省为WinNTSystem32（或WindowsSystem，在非NT/2000计算机上）目录。<br />
&#183; TemporaryFolder：%Temp%目录，缺省为WinNTTemp（或WindowsTemp，在非NT/2000计算机上）目录。<br />
为得到对特殊文件夹的引用，我们提供相应的预定义常数作为GetSpecialFolder方法的参数：<br />
' In VBScript:<br />
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")</p>
<p>Set objFolder = objFSO.GetSpecialFolder(WindowsFolder)<br />
Response.Write "GetSpecialFolder(WindowsFolder) returned:&lt;BR&gt;"<br />
Response.Write "Path: " &amp; objFolder.Path &amp; "&lt;BR&gt;"<br />
Response.Write "Type: " &amp; objFolder.Type &amp; "&lt;P&gt;"</p>
<p>Set objFolder = objFSO.GetSpecialFolder(SystemFolder)<br />
Response.Write "GetSpecialFolder(SystemFolder) returned:&lt;BR&gt;"<br />
Response.Write "Path: " &amp; objFolder.Path &amp; "&lt;BR&gt;"<br />
Response.Write "Type: " &amp; objFolder.Type &amp; "&lt;P&gt;"</p>
<p>Set objFolder = objFSO.GetSpecialFolder(TemporaryFolder)<br />
Response.Write "GetSpecialFolder(TemporaryFolder) returned:&lt;BR&gt;"<br />
Response.Write "Path: " &amp; objFolder.Path &amp; "&lt;BR&gt;"<br />
Response.Write "Type: " &amp; objFolder.Type &amp; "&lt;P&gt;"<br />
或用JScript：<br />
// In JScript:<br />
var objFSO = Server.CreateObject('Scripting.FileSystemObject');</p>
<p>var objFolder = objFSO.GetSpecialFolder(WindowsFolder);<br />
Response.Write('GetSpecialFolder(WindowsFolder) returned -&nbsp; ');<br />
Response.Write('Path: ' + objFolder.Path + '&nbsp;&nbsp; ');<br />
Response.Write('Type: ' + objFolder.Type + '&lt;BR&gt;');</p>
<p>var objFolder = objFSO.GetSpecialFolder(SystemFolder);<br />
Response.Write('GetSpecialFolder(SystemFolder) returned -&nbsp; ');<br />
Response.Write('Path: ' + objFolder.Path + '&nbsp;&nbsp; ');<br />
Response.Write('Type: ' + objFolder.Type + '&lt;BR&gt;');</p>
<p>var objFolder = objFSO.GetSpecialFolder(TemporaryFolder);<br />
Response.Write('GetSpecialFolder(TemporaryFolder) returned -&nbsp; ');<br />
Response.Write('Path: ' + objFolder.Path + '&nbsp;&nbsp; ');<br />
Response.Write('Type: ' + objFolder.Type + '&lt;BR&gt;');<br />
该VBScript程序在服务器上运行时的结果如图5-13所示。该页面名为specialfolder_vb.asp，来自本书提供的示例文件。</p>
<p>2．&nbsp; File对象<br />
File对象提供了对文件的属性的访问，通过它的方法能够对文件进行操作。每个Folder对象提供了一个Files集合，包含文件夹中文件对应的File对象。还可以直接地从FileSystemObject对象中通过使用GetFile方法得到一个File对象引用。<br />
(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File对象的属性<br />
File对象有一系列的属性，类似于Folder对象的属性，如表5-11所示：<br />
表5-11&nbsp; File对象的属性及说明<br />
属 性 <br />
说 明 </p>
<p>Attributes <br />
返回文件的属性。可以是下列值中的一个或其组合：Normal(0)、ReadOnly(1)、Hidden(2)、System(4)、Volume(名称)(9)、Directory(文件夹)(16)、Archive(32)、Alias(64)和Compressed(128) </p>
<p>DateCreated <br />
返回该文件夹的创建日期和时间 </p>
<p>DateLastAccessed <br />
返回最后一次访问该文件的日期和时间 </p>
<p>DateLastModified <br />
返回最后一次修改该文件的日期和时间 </p>
<p>Drive <br />
返回该文件所在的驱动器的Drive对象 </p>
<p>Name <br />
设定或返回文件的名字 </p>
<p>ParentFolder <br />
返回该文件的父文件夹的Folder对象 </p>
<p>Path <br />
返回文件的绝对路径，可使用长文件名 </p>
<p>ShortName <br />
返回DOS风格的8.3形式的文件名 </p>
<p>ShortPath <br />
返回DOS风格的8.3形式的文件绝对路径 </p>
<p>Size <br />
返回该文件的大小（字节） </p>
<p>Type <br />
如果可能，返回一个文件类型的说明字符串（例如：&#8220;Text Document&#8221;表示.txt文件） </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (2)&nbsp; File对象的方法<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 同样类似于Folder对象，File对象的方法允许复制、删除以及移动文件。它也有一个使用文本流打开文件的方法。File对象的方法及说明如表5-12所示：<br />
表5-12&nbsp; File对象的方法及说明<br />
方 法 <br />
说 明 </p>
<p>Copy(destination,overwrite) <br />
将这个文件复制到destination指定的文件夹。如果destination的末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是放置拷贝文件的文件夹。否则认为destination是要创建的新文件的路径和名字。如果目标文件已经存在且overwrite参数设置为False，将产生错误，缺省的overwrite参数是True </p>
<p>Delete(force) <br />
删除这个文件。如果可选的force参数设置为True，即使文件具有只读属性也会被删除。缺省的force是False </p>
<p>Move(destination) <br />
将文件移动到destination指定的文件夹。如果destination的末尾是路径分隔符(&#8216;&#8217;)，那么认为destination是一文件夹。否则认为destination是一个新的文件的路径和名字。如果目标文件夹已经存在，则出错 </p>
<p>CreateTextFile<br />
(filename,overwrite,unicode) <br />
用指定的文件名创建一个新的文本文件，并且返回一个相应的TextStream对象。如果可选的overwrite参数设置为True，将覆盖任何已有的同名文件。缺省的overwrite参数是False。如果可选的unicode参数设置为True，文件的内容将存储为unicode文本。缺省的unicode是False<br />
OpenAsTextStream<br />
(iomode,format) <br />
打开指定文件并且返回一个TextStream对象，用于文件的读、写或追加。iomode参数指定了要求的访问类型，允许值是ForReading(1) (缺省值)、ForWrite(2)、ForAppending(8)。format参数说明了读、写文件的数据格式。允许值是TristateFalse(0)（缺省），说明用ASCII数据格式；TristateTrue(-1)说明用Unicode数据格式；TristateUseDefault(-2)说明使用系统缺省格式 </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 因此给定一个File对象后，可以使用ParentFolder属性得到包含该文件的Folder对象的引用，用来在文件系统中导航。甚至可以用Drive属性获得相应的Drive对象的引用，并得到各种Folder对象以及所包含的File对象。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 另外，给定一个Folder对象以及对应的Files集合后，可以通过遍历该集合检查这一文件夹中的每个文件。还可以使用File对象的各种方法以一定方式处理该文件，如复制、移动或删除。下面的代码给出了C驱动器的第一个文件夹的文件列表：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' In VBScript:<br />
' Create a FileSystemObject instance<br />
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")<br />
' Get a reference to drive C<br />
Set objDriveC = objFSO.GetDrive("C:")<br />
' Get a reference to the root folder<br />
Set objRoot = objDriveC.RootFolder<br />
' Get a reference to the SubFolders collection<br />
Set objFolders = objRoot.SubFolders<br />
' Get a reference to the first folder in the SubFolders collection<br />
For Each objFolder In objFolders<br />
&nbsp; Set objFolder1 = objFolders.Item((objFolder.Name))<br />
&nbsp; Exit For<br />
Next<br />
' Iterate through all the files in this folder<br />
For Each objFile in objFolder1.Files<br />
&nbsp; Response.Write "Name: " &amp; objFile.Name &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "ShortName: " &amp; objFile.ShortName &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "Size: " &amp; objFile.Size &amp; " bytes&nbsp;&nbsp;&nbsp; "<br />
&nbsp; Response.Write "Type: " &amp; objFile.Type &amp; "&lt;BR&gt;"<br />
&nbsp; Response.Write "Path: " &amp; objFile.Path &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "ShortPath: " &amp; objFile.ShortPath &amp; "&lt;BR&gt;"<br />
&nbsp; Response.Write "Created: " &amp; objFile.DateCreated &amp; "&nbsp;&nbsp; "<br />
&nbsp; Response.Write "LastModified: " &amp; objFile.DateLastModified &amp; "&lt;P&gt;"<br />
Next<br />
注意，不能使用数字索引来定位Folders或Files集合里的条目，因此必须使用For Each &#8230; Next语句遍历该集合直到最初的条目，然后使用该条目的Name属性。也不得不使用嵌套的圆括号强迫其作为值（字符串）传送给该Folders集合的Item方法。<br />
用下面的JScript程序可完成同样的工作：<br />
// In JScript:<br />
// Create a FileSystemObject instance<br />
var objFSO = Server.CreateObject('Scripting.FileSystemObject');<br />
// Get a reference to drive C<br />
var objDriveC = objFSO.GetDrive('C:');<br />
// Get a reference to the root folder<br />
var objRoot = objDriveC.RootFolder;<br />
// Get a reference to the first folder in the SubFolders collection<br />
var colAllFolders = new Enumerator(objRoot.SubFolders);<br />
var objFolder1 = colAllFolders.item();<br />
// Get a reference to the Files collection for this folder<br />
var colFiles = new Enumerator(objFolder1.Files);</p>
<p>// Iterate through all the files in this collection<br />
for (; !colFiles.atEnd(); colFiles.moveNext()) {<br />
&nbsp; objFile = colFiles.item()<br />
&nbsp; Response.Write('Name: ' + objFile.Name + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('ShortName: ' + objFile.ShortName + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Size: ' + objFile.Size + ' bytes&nbsp;&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Type: ' + objFile.Type + '&lt;BR&gt;');<br />
&nbsp; Response.Write('Path: ' + objFile.Path + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('ShortPath: ' + objFile.ShortPath + '&lt;BR&gt;');<br />
&nbsp; Response.Write('Created: ' + objFile.DateCreated + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Accessed: ' + objFile.DateLastAccessed + '&nbsp;&nbsp; ');<br />
&nbsp; Response.Write('Modified: ' + objFile.DateLastModified + '&lt;P&gt;');<br />
}<br />
两个程序的结果是相同的<br />
&nbsp;&nbsp;&nbsp; 在C驱动器上的第一个文件夹可能是CAConfig，缺省情况下该文件夹是空的。这种情况下，可先向该文件夹复制一些文件，完成实验以后再删除这些文件。<br />
</p>
<p>&nbsp;--------------------------------------------<br />
QTP：FileSystemObject基础知识<br />
　在QTP测试中，比较本地的两个文件是不是相同，需要使用VBScript的FileSystemObject对象，在此作简要的概述 <br />
一．基础FileSystemObject <br />
1.&nbsp;&nbsp;&nbsp;&nbsp; 创建 FileSystemObject 对象 <br />
Dim fso <br />
Set fso = CreateObject(\"Scripting.FileSystemObject\") <br />
　　Scripting 是类型库的名字，而 FileSystemObject 则是想要创建的对象的名字。 <br />
　　要用 FileSystemObject (FSO) 对象模式来编程，则：使用 CreateObject 方法来创建 FileSystemObject 对象。&nbsp; <br />
　　FSO 对象模式包含在 Scripting 类型库中，该库位于 Scrrun.dll 文件中。因而，要使用 FSO 对象模式，必须把 Scrrun.dll 放在 Web 服务器的适当系统目录中。 <br />
2.&nbsp;&nbsp;&nbsp;&nbsp; 使用方法： <br />
　　访问现有驱动器、文件和文件夹 <br />
GetDrive()、GetFolder()、GetFile()、CreateFolder()、CreateFile()、CreateTextFile ()、OpenTextFile()、FolderExists(url)、DeleteFolder(url)、MoveFolder(src,to)、FileExists(url)、CopyFile()、MoveFile()、DeleteFile()、 <br />
例如： <br />
Dim fso, f1 <br />
Set fso = CreateObject(\"Scripting.FileSystemObject\") <br />
Set f1 = fso.GetFile(\"c:\\test.txt\") <br />
3.&nbsp;&nbsp;&nbsp;&nbsp; 访问属性： <br />
Name、Path、Size、Type、DateLastModified（上一次修改的文件时间） <br />
二．FSO的一些特殊功能 <br />
1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSpecialFolder Method 返回特定的Windows文件夹的路径: <br />
　　Windows安装目录；Windows系统目录;Windows临时目录&nbsp; <br />
　　FSO.GetSpecialFolder([0, 1, or 2])　&nbsp; <br />
2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetTempName Method 返回一个随机产生的文件或者目录名字，用于存储临数据 <br />
3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetAbsolutePathName Method 返回文件夹的绝对路径(类似于Server.MapPath)。 <br />
比如，FSO.GetAbsolutePathName(\"region\") 将返回类似于下面的结果：\"c:mydocsmyfolder egion\"&nbsp; <br />
4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetExtensionName Method 返回路径中最后部分的扩展名 (比如：FSO.GetExtensionName(\"c:docs est.txt\") 将返回txt)&nbsp; <br />
5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetBaseName and GetParentFolder Methods 返回路径中最后部分的父文件夹 (比如：FSO.GetParentFolder (\"c:docsmydocs\") 将返回&#8217;docs&#8217;)&nbsp; <br />
6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Drives Property 返回所有本地可用驱动器的集合，用于建立资源浏览器样的用户接口。<br />
</p>
<img src ="http://www.blogjava.net/joan/aggbug/302720.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2009-11-17 16:32 <a href="http://www.blogjava.net/joan/articles/302720.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QTP 测试PDF 的方法</title><link>http://www.blogjava.net/joan/articles/266546.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Mon, 20 Apr 2009 05:39:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/266546.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/266546.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/266546.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/266546.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/266546.html</trackback:ping><description><![CDATA[<span style="font-family: Comic Sans MS">Adobe的PDF文件是目前通用的文件格式之一，很多文档都以这种格式来存储。在使用QTP进行自动化测试的过程中，经常要验证PDF文件的内容是否满足要求，因此需要访问PDF文件的内部属性。幸好Adobe提供了以COM方式访问PDF的接口，使得我们可以实现QTP测试PDF的自动化过程。下面是一个简单的例子，用于打开一份PDF文档，读取PDF文档的页数：<br />
<br style="font-family: " />
Option Explicit<br />
Dim gApp, gPDDoc, jso<br />
Set gApp = CreateObject("AcroExch.App")<br />
Set gPDDoc = CreateObject("AcroExch.PDDoc")<br />
&nbsp;&nbsp;&nbsp;&nbsp;If gPDDoc.Open("C:\Documents and Settings\joan\桌面\详解与案例剖析.pdf") Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Msgbox gPDDoc.GetNumPages<br />
&nbsp;&nbsp;&nbsp;&nbsp;End If<br />
Set gPDDoc = Nothing : Set gApp = Nothing<br />
'Adobe Acrobat Professional<br />
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; color: rgb(0,0,0); font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; color: rgb(0,0,0); font-family: '宋体'; mso-spacerun: 'yes'">（需要安装Adobe Acrobat Professional ）</span></p>
</span><!--endfragment--></span>
<img src ="http://www.blogjava.net/joan/aggbug/266546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2009-04-20 13:39 <a href="http://www.blogjava.net/joan/articles/266546.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QuickTest Plus小工具，大作用（转载）</title><link>http://www.blogjava.net/joan/articles/242806.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Wed, 26 Nov 2008 08:20:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/242806.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/242806.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/242806.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/242806.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/242806.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: QuickTest Plus小工具，大作用（转载）&nbsp;&nbsp;<a href='http://www.blogjava.net/joan/articles/242806.html'>阅读全文</a><img src ="http://www.blogjava.net/joan/aggbug/242806.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2008-11-26 16:20 <a href="http://www.blogjava.net/joan/articles/242806.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转载！（QTP使用中的一些好的方法）</title><link>http://www.blogjava.net/joan/articles/217031.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Wed, 23 Jul 2008 14:17:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/217031.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/217031.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/217031.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/217031.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/217031.html</trackback:ping><description><![CDATA[<div class="cnt" id="blog_text">SystemUtil Object Descrīption <br />
An object used to control applications and processes during a run session. <br />
在脚本运行过程中,可使用该对象控制应用程序或进程. <br />
Operations <br />
The tables below list the built-in methods and properties that you can use as operations for the SystemUtil object. 下表列出了SystemUtil对象的内建方法与属性. <br />
Methods BlockInput Prevents keyboard and mouse input events from reaching applications. <br />
禁止键盘或鼠标操作. <br />
CloseDescendentProcesses Closes all processes opened by QuickTest. <br />
关闭由QuickTest打开的所有进程. <br />
CloseProcessByHwnd Closes a process that is the owner of a window with the specified handle. <br />
根据窗口的句柄找到相应的进程,并关闭该进程. <br />
CloseProcessById Closes a process according to its Process ID (PID). <br />
关闭指定进程PID的进程. <br />
CloseProcessByName Closes a process according to its name. <br />
关闭指定进程名称的进程. <br />
CloseProcessByWndTitle Closes all processes that are owners of <a onclick="javascript:tagshow(event, 'windows');" href="javascript:;" target="_self"><u><strong>windows</strong></u></a> with the specified title. <br />
关闭指定窗口标题的进程. <br />
Run Runs a file or application. <br />
运行文件或应用程序. <br />
UnblockInput Re-enables keyboard and mouse input events after a BlockInput statement <br />
was used to block them. <br />
在BlockInput语句禁止键盘或鼠标之后,使用UnblockInput语句可解除对键盘或<br />
鼠标的禁止. <br />
BlockInput Method Descrīption <br />
Prevents keyboard and mouse input events from reaching applications. <br />
禁止键盘或鼠标操作. <br />
Syntax object.BlockInput <br />
Argument Descrīption <br />
Object A <a onclick="javascript:tagshow(event, 'test');" href="javascript:;" target="_self"><u><strong>test</strong></u></a> object of type SystemUtil. <br />
SystemUtil类型的<a onclick="javascript:tagshow(event, '%B2%E2%CA%D4');" href="javascript:;" target="_self"><u><strong>测试</strong></u></a>对象. <br />
Return Value <br />
None <br />
Remarks <br />
You can use this method to prevent a run session being accidentally interrupted by someone using the keyboard or mouse on a QuickTest Professional computer. <br />
当电脑正在运行<a name="baidusnap0"></a><strong style="color: black; background-color: #ffff66">QTP</strong>脚本时,使用BlockInput方法可以防止因键盘或鼠标的操作扰乱<strong style="color: black; background-color: #ffff66">QTP</strong>的正常运行. <br />
After using this method, keyboard and mouse input is blocked until one of the following occurs: <br />
使用BlockInput方法后,使用以下方法可以解除对键盘或鼠标的禁止: <br />
An UnblockInput statement is used <br />
当使用了UnblockInput语句后. <br />
A run session ends or is paused for any reason (end of test run, run error, breakpoint, and so forth) <br />
当脚本运行结束或中断(如整个test结束,运行错误,断点等等). <br />
The Ctrl+Alt+Delete key combination is pressed on the keyboard <br />
在键盘上按下Ctrl+Alt+Delete结合键后. <br />
A critical system error occurs <br />
当出现了严重的系统错误时. <br />
Example <br />
Block Keyboard and Mouse Input During a Run Session <br />
下面的例子使用BlockInput方法,在<strong style="color: black; background-color: #ffff66">QTP</strong>脚本运行过程中禁用了键盘及鼠标. <br />
Sub BlockInput_Example() <br />
SystemUtil.BlockInput <br />
Browser("Welcome: <a onclick="javascript:tagshow(event, 'Mercury');" href="javascript:;" target="_self"><u><strong>Mercury</strong></u></a> Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set <br />
"mercury" <br />
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury <br />
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc" <br />
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2, <br />
2 、SystemUtil.UnblockInput <br />
End Sub <br />
UnblockInput Method <br />
Descrīption <br />
Re-enables keyboard and mouse input events after a BlockInput statement was used to block them. <br />
在BlockInput语句禁止键盘或鼠标之后,使用UnblockInput语句可解除对键盘或鼠标的禁止. <br />
Syntax <br />
object.UnblockInput <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
Return Value <br />
None <br />
Remarks <br />
You can use this method to unblock keyboard and mouse input that was earlier blocked using a BlockInput <br />
statement. <br />
如果先前使用了BlockInput方法禁止了键盘及鼠标,使用UnblockInput方法可解除禁止. <br />
Example <br />
Unblock Keyboard and Mouse Input That Was Previously Blocked <br />
本例在开始使用BlockInput方法禁止了键盘及鼠标,后来使用UnblockInput方法解除了禁止. <br />
Sub UnblockInput_Example() <br />
SystemUtil.BlockInput <br />
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set <br />
"mercury" <br />
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury <br />
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc" <br />
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2, <br />
2 <br />
SystemUtil.UnblockInput <br />
End Sub <br />
CloseDescendentProcesses Method <br />
Descrīption <br />
Closes all processes opened by QuickTest. <br />
关闭由QuickTest打开的所有进程. <br />
Syntax <br />
object.CloseDescendentProcesses <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
Return Value <br />
A Long value. The number of instances of the application that are closed when the statement runs. <br />
一个长整型值.被CloseDescendentProcesses方法语句关闭的程序实例数. <br />
Remarks <br />
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If <br />
the process is still open after 5 seconds, QuickTest terminates the process. <br />
注意:执行该语句时,QuickTest首先向进程窗口发送一个WM_CLOSE信息,偿试关闭该进程;如果该进程在5秒钟后存未<br />
关闭,则QuickTest强制结束进程. <br />
Example <br />
Close All Applications Opened By QuickTest <br />
在本例中:假定在运行程序之初,Record and Run对话框自动打开了某个窗口,然后通过Run语句打开了一个NotePad窗口,<br />
那么该CloseDscendentProcessed方法的返回值就就该是2,因此Message对话框显示的信息应该是"2". <br />
Sub CloseDescendentProcesses_Example() <br />
SystemUtil.Run "Notepad.exe" <br />
MsgBox SystemUtil.CloseDescendentProcesses <br />
End Sub <br />
CloseProcessByHwnd Method <br />
Descrīption <br />
Closes a process that is the owner of a window with the specified handle. <br />
根据窗口的句柄找到相应的进程,并关闭该进程. <br />
Syntax <br />
object.CloseProcessByHwnd (hWnd) <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
hWnd Required. An ULong object. <br />
The handle of the window owned by the process you want to close. <br />
Tip: You can retrieve the window handle using the hwnd property. For <br />
example: <br />
Window("MyAppName").GetROProperty("hwnd") <br />
必须.一个ULong对象. <br />
你想要关闭的进程的窗口的句柄. <br />
Tip:你可以通过获取Runtime窗口对象的hwnd属性值来获得句柄信息.例如: <br />
Window("MyAppName").GetRoProperty("hwnd") <br />
Return Value <br />
A Boolean value. <br />
一个Boolean值. <br />
True--The specified process was successfully closed. <br />
True――指定的进程已被成功关闭. <br />
False--The specified process was not closed. <br />
False――指定的进程未被关闭. <br />
Remarks <br />
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If <br />
the process is still open after 5 seconds, QuickTest terminates the process. <br />
注意:执行该语句时,QuickTest首先向进程窗口发送一个WM_CLOSE信息,偿试关闭该进程;如果该进程在5秒钟后存未<br />
关闭,则QuickTest强制结束进程. <br />
Example <br />
Close the Process that is an Owner of a Window with the Specified Handle <br />
在本例中,首先通过GetroProperty方法获取NotePad窗口的句柄,然后使用CloseProcessByHwnd方法关闭Notepad程序. <br />
Sub CloseProcessByHwnd_Example() <br />
hWnd = Window("Notepad").GetROProperty("hwnd") <br />
SystemUtil.CloseProcessByHwnd (hWnd) <br />
End Sub <br />
CloseProcessById Method <br />
Descrīption <br />
Closes a process according to its Process ID (PID). <br />
根据进程的Process ID(PID)关闭进程. <br />
Syntax <br />
object.CloseProcessById (wdProcessId) <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
wdProcessId Required. An ULong object. <br />
The Process ID (PID) of the process you want to close. <br />
Tip: You can find the PID of an application by viewing the value in the <br />
Processes tab of the Windows Task Manager, or you can retrieve the value <br />
using the process id property. For example: <br />
Window("MyAppName").GetROProperty("process id") <br />
必须.一个ULong对象. <br />
你想关闭的进程的PID. <br />
Tip:在Windows的任务窗口的进程标签页可以查看到程序的PID值,你也可以通<br />
过获取Runtime窗口对象的Process id属性值来获得PID信息.例如: <br />
Window("MyAppName").GetRoProperty("process id") <br />
Return Value <br />
A Boolean value. <br />
一个Boolean值. <br />
True--The specified process was successfully closed. <br />
True――指定的进程已被正常关闭. <br />
False--The specified process was not closed. <br />
False――指定的进程未被关闭. <br />
Remarks <br />
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If <br />
the process is still open after 5 seconds, QuickTest terminates the process. <br />
注意:执行该语句时,QuickTest首先向进程窗口发送一个WM_CLOSE信息,偿试关闭该进程;如果该进程在5秒钟后存未<br />
关闭,则QuickTest强制结束进程. <br />
Example <br />
Close an Application According to its Process ID <br />
下面的例子通过GetRoProperty方法获取Notepad窗口的PID值,然后使用CloseProcessById方法关闭Notepad程序. <br />
Sub CloseProcessById_Example() <br />
PID = Window("Notepad").GetROProperty("process id") <br />
SystemUtil.CloseProcessById (PID) <br />
End Sub <br />
CloseProcessByName Method <br />
Descrīption <br />
Closes a process according to its name. <br />
Syntax <br />
object.CloseProcessByName (bsProcessName) <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
bsProcessName Required. A String value. <br />
The name of the process you want to close. <br />
必须.一个字符串值. <br />
你想关闭的进程的名称. <br />
Return Value <br />
A Long value. The number of instances of the application that are closed when the statement runs. <br />
一个Long值.所关闭的程序的实例数. <br />
Remarks <br />
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If <br />
the process is still open after 5 seconds, QuickTest terminates the process. <br />
注意:执行该语句时,QuickTest首先向进程窗口发送一个WM_CLOSE信息,偿试关闭该进程;如果该进程在5秒钟后存未<br />
关闭,则QuickTest强制结束进程. <br />
Example <br />
Close All Instances of a Specified Application <br />
本例通过CloseProcessByName方法,关闭所有已打开的Notepad实例.如果当前所有的Notepad实例都是由下面的Run语句打开的,则CloseProcessByName方法语句会关闭这些实例,并且MsgBox窗口显示的数值应为"3". <br />
Sub CloseProcessByName_Example() <br />
SystemUtil.Run "Notepad.exe" <br />
SystemUtil.Run "Notepad.exe" <br />
SystemUtil.Run "Notepad.exe" <br />
MsgBox SystemUtil.CloseProcessByName("Notepad.exe") <br />
End Sub <br />
CloseProcessByWndTitle Method <br />
Descrīption <br />
Closes all processes that are owners of windows with the specified title. <br />
关闭指定窗口标题的所有进程. <br />
Syntax <br />
object.CloseProcessByWndTitle (bsTitle, [bRegExp]) <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
bsTitle Required. A String value. <br />
The title of the window owned by the process you want to close. <br />
必须.一个字符串值. <br />
你想关闭的进程的窗口的标题. <br />
bRegExp Optional. A Boolean value. <br />
Indicates whether the bsTitle argument is treated as a <a name="baidusnap1"></a><strong style="color: black; background-color: #a0ffff">regular</strong> <br />
<a name="baidusnap2"></a><strong style="color: black; background-color: #99ff99">expression</strong>. Default = False. <br />
可选.一个Boolean值. <br />
检查BsTitle参数是否是一个正则表达式.默认值为False. <br />
Return Value <br />
A Long value. The number of instances of the application that are closed when the statement runs. <br />
一个Long值.被语句所关闭的程序的实例数. <br />
Remarks <br />
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If <br />
the process is still open after 5 seconds, QuickTest terminates the process. <br />
注意:执行该语句时,QuickTest首先向进程窗口发送一个WM_CLOSE信息,偿试关闭该进程;如果该进程在5秒钟后存未关闭,则QuickTest强制结束进程. <br />
Example <br />
Close All Windows with a Title Containing a Specified String <br />
本例关闭了所有的标题包含有"Notepad"字样的顶层窗口.因为bRegExp参数值为"ture",表示bsTitle值是一个正则表达式. <br />
Sub CloseProcessByWndTitle_Example1() <br />
SystemUtil.CloseProcessByWndTitle "Notepad", True <br />
End Sub <br />
Close All Windows in which the Exact Title Matches a Specified String <br />
本例关闭所有窗口标题为"Untitled-Notepad"的顶层窗口.因为bRegExp参数值为"false",表示bsTitle参数值是一个文字串,因此窗口标题必须与参数值精确匹配. <br />
Sub CloseProcessByWndTitle_Example2() <br />
SystemUtil.CloseProcessByWndTitle "Untitled - Notepad" <br />
End Sub <br />
Run Method <br />
Descrīption <br />
Runs a file or application. <br />
运行一个文件或应用程序. <br />
Syntax <br />
object.Run file, [params], [dir], [op], [mode] <br />
Argument Descrīption <br />
object A test object of type SystemUtil. <br />
SystemUtil类型的测试对象. <br />
file Required. A String value. <br />
The name of the file you want to run. <br />
必须.一个字符串值. <br />
你想要运行的文件的名称. <br />
params Optional. A String value. <br />
If the specified file argument is an executable file, use the params argument to specify <br />
any parameters to be passed to the application. <br />
可选.一个字符串值. <br />
如果file参数中指定的是一个可执行文件,则可以使用params参数来指定该可执行文件的运行参数. <br />
dir Optional. A String value. <br />
The default directory of the application or file. <br />
可选.一个字符串值. <br />
应用程序或文件的默认目录. <br />
op Optional. A String value. The action to be performed. If this argument is blank ( ""), the <br />
open operation is performed. <br />
The following operations can be specified for the op argument: <br />
可选.一个字符串值.将要被执行的动作.如果该参数值为空(""),则默认操作为open操作. <br />
下面是op参数中可以指定的操作: <br />
Operation Descrīption <br />
open <br />
Opens the file specified by the FileName parameter. The file can be an <br />
executable file, a document file, or a folder. Non-executable files are <br />
open in the associated application. <br />
打开file参数中所指定的文件.文件有可能是一个可执行文件,一个文档文件,或<br />
一个文件夹.非可执行文件会被相应的应用程序打开. <br />
edit <br />
Launches an editor and opens the document for editing. If the FileName <br />
argument does not specify an editable document file, the statement <br />
fails. <br />
将文件在文件编辑器中打开以进行编辑.如果file参数中指定的文件不可编辑,则<br />
本语句失败. <br />
explore <br />
Explores the folder specified by the FileName argument. <br />
打开由file参数中所指定的文件夹. <br />
find <br />
Initiates a search starting from the specified folder path. <br />
在file参数所指定的文件夹中进行搜索. <br />
print <br />
Prints the document file specified by the FileName argument. If the <br />
specified file is not a printable document file, the statement fails. <br />
打印在file参数中所指定的文档.如果参数中所指定的文档不可打印,则语句失败. <br />
mode Optional. An Integer value. <br />
Specifies how the application is displayed when it opens. You can specify one of the modes <br />
in the table below. <br />
Default = 1 <br />
可选.一个Integer值. 指定应用程序打开时的显示模式.可以指定以下几种打开模式.默认模式是1. <br />
Mode Descrīption <br />
0 <br />
Hides the window and activates another window. <br />
隐藏程序窗口,激活另外一下窗口. <br />
1 <br />
Activates and displays the window. If the window is minimized or maximized, <br />
the system restores it to its original size and position. Specify this flag when <br />
displaying the window for the first time. <br />
激活并显示程序窗口.如果窗口是最大化或最小化状态,则将它恢复为默认窗口大小并放<br />
置于默认位置. <br />
2 <br />
Activates the window and displays it as a minimized window. <br />
激活窗口并最小化. <br />
3 <br />
Activates the window and displays it as a maximized window. <br />
激活窗口并最大化. <br />
4 <br />
Displays the window in its most recent size and position. The active window <br />
remains active. <br />
按照窗口最近一次的显示大小及位置显示该窗口,但不激活该窗口.原来活动的窗口仍保<br />
持活动状态. <br />
5 <br />
Activates the window and displays it in its current size and position. <br />
激活窗口,保持当前的大小及位置不变. <br />
6 <br />
Minimizes the specified window and activates the next top-level window in the <br />
Z order. <br />
最小化指定的窗口,并激活它的下一个top-level窗口(按Z顺序找到它的下一下top-level<br />
窗口). <br />
7 <br />
Displays the window as a minimized window. The active window remains active. <br />
显示窗口并最小化,但不激活该窗口.原来活动的窗口仍保持活动状态. <br />
8 <br />
Displays the window in its current state. The active window remains active. <br />
显示窗口,大小及位置保存不变.原来活动的窗口仍保持活动状态. <br />
9 <br />
Activates and displays the window. If the window is minimized or maximized, <br />
the system restores it to its original size and position. Specify this flag when <br />
restoring a minimized window. <br />
激活并显示窗口.如果窗口处于最大化或最小化状态,则将它恢复为原始大小与位置. <br />
10 <br />
Sets the show-state based on the state of the program that started the <br />
application. <br />
Return Value <br />
None <br />
Remarks <br />
When specifying a non-executable file, the file opens in the associated application. <br />
当指定的是一个非可执行文件时,文件被相应的应用程序打开. <br />
Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test. <br />
注意:在录制脚本的过程中,如果你从系统的"开始"菜单或"运行"对话框中运行应用程序时,SystemUtil.Run语句会自动添加到脚本中. <br />
Tip: You can also use this method to perform operations on the specified file, similar to the <a name="baidusnap3"></a><strong style="color: black; background-color: #ff9999">usage</strong> of the Windows ShellExecute command. <br />
Tip:你也可以使用本方法对指定的文件进行操作,该功能类似于使用Windows ShellExecute命令. <br />
Example <br />
Open a Text File in the Default Text Application (Notepad) <br />
本例使用Run方法打开了一个名为type.txt的文件(txt类型文件的默认打开程序是Notpad),然后向文件中输入"happy days"文字,然后使用快捷键保存该文件,然后关闭NotePad应用程序. <br />
Sub CloseDescendentProcesses_Example() <br />
SystemUtil.Run "C:\type.txt", "", "", "" <br />
Window("Text:=type.txt - Notepad").Type "happy days" <br />
Window("Text:=type.txt - Notepad").Type micAltDwn &amp; "F" &amp; micAltUp <br />
Window("Text:=type.txt - Notepad").Type micLShiftDwn &amp; "S" &amp; micLShiftUp <br />
Window("Text:=type.txt - Notepad").Close <br />
End Sub</div>
<img src ="http://www.blogjava.net/joan/aggbug/217031.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2008-07-23 22:17 <a href="http://www.blogjava.net/joan/articles/217031.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> QTP 安装问题小结</title><link>http://www.blogjava.net/joan/articles/joan.html</link><dc:creator>joan</dc:creator><author>joan</author><pubDate>Sun, 13 Jul 2008 03:21:00 GMT</pubDate><guid>http://www.blogjava.net/joan/articles/joan.html</guid><wfw:comment>http://www.blogjava.net/joan/comments/214556.html</wfw:comment><comments>http://www.blogjava.net/joan/articles/joan.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joan/comments/commentRss/214556.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joan/services/trackbacks/214556.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对于&nbsp;QTP 9.2 安装。运行setup.exe 出现&nbsp;&nbsp;Command line option syntax error. Type Command /? for Help 错误提示框的有效解除方法是将安装程序包放到一个全英文路径下，再重新安装就可以解决。比如：D:\qtp92<img src="/CuteSoft_Client/CuteEditor/images/emstar.gif" align="absMiddle" border="0"  alt="" /><br />
&nbsp;&nbsp;&nbsp;
 <img src ="http://www.blogjava.net/joan/aggbug/214556.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joan/" target="_blank">joan</a> 2008-07-13 11:21 <a href="http://www.blogjava.net/joan/articles/joan.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>