|
导读写在前面:翻译整理这篇文档前,满以为该组件也能在VB中使用,结果后来一看,好像只能应用在Asp环境中,真是大失所望。但其功能对于asp编程者来说,实在不错,所以贴在这里,如有翻译和理解上的错误,欢迎... 写在前面:翻译整理这篇文档前,满以为该组件也能在VB中使用,结果后来一看,好像只能应用在Asp环境中,真是大失所望。但其功能对于asp编程者来说,实在不错,所以贴在这里,如有翻译和理解上的错误,欢迎指正[a]jiangjianxiao@163.net[/a]。GenObj是AspLib 1.1的组成部分之一,其它几个是 Aspfile、AspConv、AspSortie。它是一个ActiveX组件,其中封装了一些常见的功能: Ⅰ NT服务控制 Ⅱ NT事务日志支持 Ⅲ INT文件和注册表操作 Ⅳ 增加、删除ODBC系统DSN Ⅴ 信用卡验证 Ⅵ Base 64编码和译码 Ⅶ 常见系统信息 大家可以从这个地址下载试用版http://www.ServerObjects.com 怎样安装GenObj ■ 拷贝GenObj.Dll到Windows的系统目录,如windows 9x一般为windows\System,NT则为WinNT\System32 ■ 使用RegSvr32 GenObj.Dll注册GenObj.Dll ■ 拷贝GenObj.ini到windows所在目录,Windows 9x一般为Windows,而NT一般为Winnt ■ 可通过通过编辑GenObj.ini关闭或允许GenObj的功能,设置为0为关闭此功能,设置为1为允许此功能。如AllowIniRead=1,即表示GetObj允许读取Ini文件,AllowIniRead=0,表示不允许GetObj对象读取Ini文件。此功能还可通过设置GetObj对象相应的属性来实现,详细见下面属性。 GetObj.ini文件 [Configuration] AllowIniRead=1 AllowIniWrite=1 AllowRegRead=1 AllowRegWrite=1 AllowServiceStart=1 AllowServiceStop=1 AllowStopW3SVC=1 AllowCheckServiceStatus=1 AllowSystemDSNAdd=1 AllowSystemDSNRemove=1 AllowSystemInfo=1 AllowEventLog=1 AllowNetwork=1 AllowFileDir=1 使用GenObj Dim objGenObj Set objGenObj=Server.CreateObject("ASPsvr.GenObj") 方法清单 网络支持 1. NetGetUserName 说明:返回某一设备的使用者姓名,如果为Null,表示返回当前机器登录者姓名 语法:NetGetUserName(device) 参数:device,可选 2. NetAddConnection 说明:增加网络资源连接 语法:GenObj.NetAddConnection(RemoteResource,LocalName,Password ) 参数:RemoteResource-资源UNC描述(\\计算机名\共享名),LocalName-资源本地名称,Password-口令,可选 返回值:0表示成功,其它失败 3. NetCancelConnection 说明:断开某一网络资源连接 语法:GenObj.NetCancelConnection(Device,True) 参数:Device:资源本地名称,第二个参数文档中没有描述,按例子中的值为True 返回值:0表示成功,其它失败 NT服务控制(仅适用于NT) 1. StopW3SVC 说明:停止Web服务 2. StartService 说明:启动某一NT服务 语法:GenObj.StartService(ServiceName) 参数:ServiceName-服务名称 3. StopService 说明:停止某一NT服务 语法:GenObj.StopService(ServiceName) 参数:ServiceName-服务名称 4. ServiceStatus 说明:返回某一NT服务状态 语法:GenObj.ServiceStatus(ServiceName) 参数:ServiceName-服务名称 返回值:1-服务停止,2-服务正在开始,3-服务正在停止,4-服务正在运行,5—服务正在继续,6-服务正在暂停,7-服务暂停,8—未知 事务日志支持(仅适用于NT) 1. WriteAppEventLogError 2. WriteAppEventLogWarning 3. WriteAppEventLogInfo 说明:在系统事物日志中写入Error/Warning/Info等内容 语法:WriteAppEventLogXXX(消息标题,消息内容,消息代号) INI文件处理 1. IniWriteBool 说明:写一布尔值到Ini文件 语法:GenObj.IniWriteBool (IniFileName, Section, Ident, Value) 参数:IniFileName-Ini文件名,Section-小节名,Ident-关键字名称,Value-值,取True或False 2. IniWriteInteger 说明:写一整型值到Ini文件 语法:GenObj.IniWriteInteger (IniFileName, Section, Ident, Value) 参数:IniFileName-Ini文件名,Section-小节名,Ident-关键字名称,Value-值,取Integer值(整数) 3. IniWriteString 说明:写一字符串到Ini文件 语法:GenObj.IniWriteString (IniFileName, Section, Ident, Value) 参数:IniFileName-Ini文件名,Section-小节名,Ident-关键字名称,Value-值,取字符串 4. IniReadBool 说明:从Ini文件中读取一布尔值 语法:GenObj.IniReadBool(IniFileName,Sectin,Ident,default) 参数:IniFileName-ini文件名,Section-小节名,Ident-关键字名,default-缺省值,可省略,当Ident的值为Null时用Default代替。取值为True或false 5. IniReadInteger 说明:从Ini文件中读取一整数值 语法:GenObj.IniReadBool(IniFileName,Sectin,Ident,default) 参数:IniFileName-ini文件名,Section-小节名,Ident-关键字名,default-缺省值,可省略,当Ident的值为Null时用Default代替。取值为整数。 6. IniReadString 说明:从Ini文件中读取一字符串值 语法:GenObj.IniReadBool(IniFileName,Sectin,Ident,default) 参数:IniFileName-ini文件名,Section-小节名,Ident-关键字名,default-缺省值,可省略,当Ident的值为Null时用Default代替。取值为字符串 注册表处理 1. RegWriteBool 2. RegWriteInteger 3. RegWriteString 4. RegReadBool 5. RegReadInteger 6. RegReadString 说明:读写系统注册表中的布尔,整数,字符串值 代码:用代码说明会比较好些 Response.Write ("<p><b>Registry Tests</b><br>") HKEY_CLASSES_ROOT = &H80000000 HKEY_CURRENT_USER = &H80000001 HKEY_LOCAL_MACHINE = &H80000002 HKEY_USERS = &H80000003 HKEY_PERFORMANCE_DATA = &H80000004 HKEY_CURRENT_CONFIG = &H80000005 HKEY_DYN_DATA = &H80000006 strKeyName = "SOFTWARE\MyWebApp" if GenObj.RegWriteBool (HKEY_LOCAL_MACHINE, strKeyName, "BoolValue", True) then Response.Write ("Write Boolean: success<br>") else Response.Write ("Write Boolean: failed<br>") end if if GenObj.RegWriteInteger (HKEY_LOCAL_MACHINE, strKeyName, "IntValue", 2007) then Response.Write ("Write Integer: success<br>") else Response.Write ("Write Integer: failed<br>") end if if GenObj.RegWriteString(HKEY_LOCAL_MACHINE, strKeyName, "StringValue", "jjx") then Response.Write ("Write String: success<br>") else Response.Write ("Write String: failed<br>") end if bolTemp = GenObj.RegReadBool (HKEY_LOCAL_MACHINE, strKeyName, "BoolValue", "default") Response.Write ("Read Boolean=" & bolTemp & "<br>") intTemp = GenObj.RegReadInteger (HKEY_LOCAL_MACHINE, strKeyName, "IntValue", "default") Response.Write ("Read Integer=" & intTemp & "<br>") strTemp = GenObj.RegReadString (HKEY_LOCAL_MACHINE, strKeyName, "StringValue", "default") Response.Write ("Read String=" & strTemp & "<br>") ODBC数据源名(DSN)处理 1. AddSystemDSN 说明:增加一系统DSN 语法:GenObj.AddSystemDSN(ODBCDriverName,DSNAttributes) 参数:ODBCDriverName-ODBC驱动程序名,如Microsoft Access Driver (*.mdb)或SQL Server等,DSNAttrbutes-DSN属性,各属性间用chr(0)分隔,用Chr(0) & Chr(0)结束,如:"DSN=Test" & chr(0) & "DBQ="c:\my documents\db1.mdb" & chr(0) & chr(0) 2. RemoveSystemDSN 说明:删除一存在的系统DSN 语法:GenObj.RemoveSystemDSN(ODBCDriverName,SystemDSNName) 参数:ODBCDriverName-ODBC驱动程序名,SystemDSNName-系统DSN名 信用卡检查 1. IsValidCreditCard 说明:判断信用卡号码是否正确 语法:IsValidCreditCard(信用卡号码) 返回值:True-号码正确,False-号码错误 2. CreditCardType 说明:判断信用卡类型 语法:CreditCardType(信用卡号码) 返回值:V-VISA Card,A-American Express Card,M-MasterCard,D-Discover(此不解?) Base64处理 1. Base64Encode 说明:对指定字符串进行Base64编码 语法:GenObj.Base64Encode(Key) 返回:编码后的字符串 2. Base64Decode 说明:对经过Base64编码后字符串进行译码 语法:GenObj.Base64Encode(Key) 返回:Base64编码前的原始字符串 磁盘信息 1. GetFreeDiskSpace 说明:取指定磁盘的剩余空间,以字节为单位返回 语法:GenObj.GetFreeDiskSpeace(指定盘符) 2. GetTotalDiskSpace 说明:取指定磁盘的总磁盘空间,以字节为单位返回 语法:GenObj.GetFreeDiskSpace(指定盘符) 3. GetUsedDiskSpace 说明:取指定磁盘的所用磁盘空间,以字节为单位返回 语法:GenObj.GetUsedDiskSpace(盘符) 系统信息 1. GetPhysicalMemory 说明:返回系统物理内存 2. GetFreePhysicalMemory 说明:返回系统剩余物理内存 3. GetPageFileMemory 说明:返回页面文件大小 4. GetAvailPageFileMemory 说明:返回未用页面文件大小 5. GetVirtualMemory 说明:返回虚拟内存 6. GetAvailVirtualMemory 说明:返回可用虚拟内存 7. GetComputerName 说明:返回当前计算机名 8. GetWindowsDirectory 说明:返回Windows目录 9. GetSystemDirectory 说明:返回Windows系统目录 10. GetTempPath 说明:返回系统临时目录 11. GetOSVersion 说明:返回操作系统版本 12. GetOSBuildNumber 说明:返回操作系统Build Number 文件和目录 1. GetTempFileName 说明:返回一唯一的临时文件名 语法:GetTempFileName(DirectoryName,FilePrefix) 参数:DirectoryName-目录名,FilePrefix-文件名前缀 2. GetFileSize 说明:返回指定文件的大小 语法:GenObj.GetFileSize(FileName) 参数:FileName-文件名 返回:-1—失败,否则返回文件大小 3. CreateDirectory 说明:创建一目录 语法:GenObj.CreateDirectory(DirectoryName) 参数:DirectoryName-目录名 返回值:True-创建目录成功,False-失败 4. RemoveDirectory 说明:删除一指定目录 语法:GenObj.RemoveDirectory(DirectoryName) 参数:DirectoryName-待删除的目录名 返回值:True-删除目录成功,False-失败 5. EraseFile 说明:删除一指定文件 语法:GenObj.EraseFile(FileName) 参数:FileName-待删除的文件名 返回值:True-删除文件成功,False-失败 6. RenameFile 说明:重新命名一文件 语法:GetObj.RenameFile OldFileName,NewFielName 其他 1. Beep 说明:发声 语法:GenObj.Beep(频率,持续时间) 属性 2. AllowIniRead 说明:设置或返回是否允许使用IniReadBool,IniReadInteger,IniReadString等方法,取值True或False 3. AllowIniWrite 说明:设置或返回是否允许使用IniWriteBool,IniWriteInteger,IniWriteString等方法,取值True或False 4. AllowRegRead 说明:类似,下略 5. AllowRegWrite 6. AllowSvcStart 7. AllowSvcStop 8. AllowStopW3Svc 9. AllowSvcStatus 10. AllowSysInfo 11. AllowEventLog 12. AllowNetwork 13. AllowFileDir |
温馨提示:喜欢本站的话,请收藏一下本站!