2006年01月20日

Microsoft Access 支持动态数据交换 (DDE) 作为一个目标(客户)应用程序或源(服务器)应用程序。例如,一个作为客户的应用程序,如 Microsoft Word,可以通过 DDE,从一个作为服务器的 Microsoft Access 数据库来请求数据。

提示   如果要操作另一个应用程序中的 Microsoft Access 对象,需要使用自动化。

客户和服务器之间的 DDE 对话是建立在特定的主题上的。主题可以是由服务器应用程序所支持格式的数据文件,也可以是提供有关服务器应用程序本身信息的 System 主题。一旦开始了特定主题的对话,就只能传送与那个主题相关的数据项。

例如,如果正在运行 Microsoft Word,并要将一个特定的 Microsoft Access 数据库中的数据插入到文档中,可以先使用 DDEInitiate 函数将 DDE 通道打开,并将数据库文件名称指定为主题,然后开始与 Microsoft Access 的 DDE 对话。通过该通道,可以将数据库中的数据传送给 Microsoft Word 文档。

作为 DDE 服务器, Microsoft Access 支持以下主题:

System 主题


数据库名称 (database 主题)


表名称 (tablename 主题)


查询名称 (queryname 主题)


Microsoft Access SQL 字符串(sqlstring 主题)

一旦建立了 DDE 对话,就可以使用 DDEExecute 语句将命令从客户发送到服务器应用程序。在作为 DDE 服务器使用时, Microsoft Access 将以下命令均识别为有效命令:

当前数据库中的宏名称。


在 Visual Basic 中,通过使用 DoCmd 对象的某个方法,可以执行的任何操作。


只为 DDE 运算而使用的 OpenDatabase 和 CloseDatabase 操作(如何使用这些操作,请参阅该主题以后的示例)。

注意   当将一个宏操作指定为一个 DDEExecute 语句时,该操作和所有的参数均遵循 DoCmd 对象的语法且必须包含在方括号([ ])中。但支持 DDE 的应用程序不识别 DDE 运算中的固有常量。同样,如果字符串包含逗号,则必须将该字符串参数包括在引号 (" ")中。否则,就不需要引号。

客户应用程序使用 DDERequest 函数,可以向由打开的 DDE 通道传送的服务器应用程序请求文本数据。反之,客户使用 DDEPoke 语句可以将数据发送到服务器应用程序。在数据传送完成以后,客户可以使用 DDETerminate 语句关闭 DDE 通道,或使用 DDETerminateAll 语句关闭所有打开的通道。

注意   当客户应用程序完成了从 DDE 通道接收数据后,应关闭该通道以节省内存资源。

以下示例将演示,如何将 Microsoft Access 用作为一个 DDE 服务器,以使用 Visual Basic 来创建 Microsoft Word 过程。(必须正在运行 Microsoft Access ,才能使该示例工作。)

Sub AccessDDE()
    Dim intChan1 As Integer, intChan2 As Integer
    Dim strQueryData As String

    ‘ 使用“系统”主题,打开“罗斯文”示例数据库。
    ‘ 必须在使用其他 DDE 主题之前已打开数据库。
    intChan1 = DDEInitiate("MSAccess", "System")
    ‘ 可能需要将此路径更改为“罗斯文”
    ‘ 示例数据库的路径。
    DDEExecute intChan1, "[OpenDatabase C:\Access\Samples\Northwind.mdb]"

    ‘ 从“十种最贵的产品”查询中获得所有数据。
    intChan2 = DDEInitiate("MSAccess", "Northwind.mdb;" _
        & "QUERY Ten Most Expensive Products")
    strQueryData = DDERequest(intChan2, "All")
    DDETerminate intChan2

    ‘ 关闭数据库。
    DDEExecute intChan1, "[CloseDatabase]"
    DDETerminate intChan1

    ‘ 将检索的数据印打印到“调试”窗口。
    Debug.Print strQueryData
End Sub有关将 Microsoft Access 用于 DDE 客户端的内容,请参阅《Microsoft Office 2000/Visual Basic Programmer’s Guide》中的信息。有关获得《Microsoft Office 2000/Visual Basic Programmer’s Guide》的内容,请单击 。

以下节提供有关 Microsoft Access 支持的有效 DDE 主题方面的信息。

System 主题

System 主题是一个针对所有基于 Microsoft Windows 应用程序的标准主题。它提供由应用程序所支持的其他主题的信息。要访问该信息,所用代码必须先以 "System" 作为 topic 参数调用 DDEInitiate 函数,然后用下面为 item 参数提供的选项之一执行 DDERequest 语句。

项目 返回
SysItems Microsoft Access 中的 System 主题所支持的项目列表。
Formats Microsoft Access 可以拷贝到“剪贴板”上的格式列表。
Status “Busy”或“Ready”。
Topics 所有已打开的数据库列表。


以下示例演示具有 System 主题的 DDEInitiate 和 DDERequest 函数的使用:

‘ 在 Visual Basic 中,使用 Microsoft Access 初始化 DDE 会话。
Dim intChan1 As Integer, strResults As String
intChan1 = DDEInitiate("MSAccess", "System")
‘ 请求“系统”主题支持的主题。
strResults = DDERequest(intChan1, "SysItems")
‘ 运行 OpenDatabase 操作,打开 Northwind.mdb。
‘ 可能需要将此路径更改为“罗斯文”示例数据库
‘ 实际位置。
DDEExecute intChan1, "[OpenDatabase C:\Access\Samples\Northwind.mdb]"database 主题

database 主题是某个已存在数据库的文件名。可以只键入基本名称 (Northwind),也可以外加其完整路径和 .mdb 扩展名 (C:\Access\Samples\Northwind.mdb)。在开始了与该数据库的 DDE 对话以后,可以申请该数据库中的对象列表。

注意   不能使用 DDE 来查询 Microsoft Access 工作组信息文件。

database 主题支持以下项目。

项目 返回
TableList 表列表。
QueryList 查询列表。
FormList 窗体列表。
ReportList 报表列表。
MacroList 宏列表。
ModuleList 模块列表。
ViewList 视图列表。
StoredProcedureList 存储过程列表。
DatabaseDiagramList 数据库图表列表。


以下示例显示如何打开在 Visual Basic 过程中的“罗斯文”示例数据库里的“雇员”窗体:

‘ 在 Visual Basic 中,使用“罗斯文”
‘ 示例数据库初始化 DDE 会话。
‘ 请确定数据库已打开。
intChan2 = DDEInitiate("MSAccess", "Northwind")
‘ 请求“罗斯文”示例数据库中窗体的列表。
strResponse = DDERequest(intChan2, "FormList")
‘ 运行 OpenForm 操作和参数,打开“雇员”窗体。
DDEExecute intChan2, "[OpenForm 雇员,0,,,1,0]"TABLE tablename、QUERY queryname 和 SQL sqlstring 主题

这些主题使用以下语法:

databasename; TABLE tablename

databasename; QUERY queryname

databasename; SQL [sqlstring]

组成部分 说明
databasename 表或查询所在的或 SQL 语句应用到的数据库名称,后接一个分号 (;)。该数据库名称可以只是基本名称 (Northwind),也可以外加其完整路径和 .mdb 扩展名 (C:\Access\Samples\Northwind.mdb)。
tablename 某个现有表的名称。
queryname 某个现有查询的名称。
sqlstring 一个以分号结尾的有效 SQL 语句,可长达 256 个字符。若要交换的字符多于 256 个,忽略该参数而使用后继的 DDEPoke 语句来建立 SQL 语句。
例如,以下的 Visual Basic 代码使用 DDEPoke 语句来建立 SQL 语句,然后请求查询结果。
 
  intChan1 = DDEInitiate("MSAccess", "Northwind;SQL")
DDEPoke intChan1, "SQLText", "SELECT *"
DDEPoke intChan1, "SQLText", " FROM Orders"
DDEPoke intChan1, "SQLText", " WHERE [Freight] > 100;"
strResponse = DDERequest(intChan1, "NextRow")
DDETerminate intChan1


下表列出了 TABLE tablename, QUERY queryname 和 SQL sqlstring 主题的有效项目。

项目 返回
All 表中的所有数据,包括字段名。
Data 所有数据行,不含字段名。
FieldNames 字段名单行列表。
FieldNames;T 字段名(第一行)及其数据类型(第二行)的两行列表。
  这些是返回的值和它们代表的数据类型:
  值 数据类型
  0 Invalid
  1 True/False (non-Null)
  2 Unsigned byte
  3 2-byte signed integer (Integer)
  4 4-byte signed integer (Long)
  5 8-byte signed integer (Currency)
  6 4-byte single-precision floating-point (Single)
  7 8-byte double-precision floating-point (Double)
  8 Date/Time
  9 二进制数据,最多 256 字节
  10 ANSI 文本,不分大小写,最多 256 字节(文本)
  11 Long binary (OLE Object)
  12 Long text (Memo) 
NextRow 表或查询中下一行的数据。当打开一个通道, NextRow 返回第一行中的数据。如果当前行是最后记录,运行 NextRow,请求就会失败。
PrevRow 表或查询中上一行的数据。如果 PrevRow 是新通道中的第一个请求,该表或查询的最后一行中的数据返回。如果第一个记录是当前行, PrevRow 请求就会失败。
FirstRow 表或查询中第一行的数据。
LastRow 表或查询中最后一行的数据。
FieldCount 表或查询中的字段数目。
SQLText 代表表或查询的 SQL 语句。对表,该项目返回窗体 "SELECT * FROM table;" 中的一个 SQL 语句。
SQLText;n 一个 SQL 语句, n-字符块大小,代表该表或查询,其中 n 是可以到 256 的整数。例如,假设一个查询由以下 SQL 语句代表:
"SELECT * FROM Orders;"项目 "SQLText;7" 返回以下表分隔块:

"SELECT ""* FROM ""Orders;"


以下示例显示如何使用 Visual Basic 过程中的 DDE ,以请求“罗斯文”示例数据库的表中的数据,并将该数据插入到文本文件中:

Sub NorthwindDDE
    Dim intChan1 As Integer, intChan2 As Integer, intChan3 As Integer
    Dim strResp1 As Variant, strResp2 As Variant, strResp3 As Variant

    ‘ 在 Visual Basic 模块中,获得 Northwind.mdb 中的“类别”表、
    ‘ “类别”查询和“订单”表中的数据。
    ‘ 首先应确定已打开数据库。
    intChan1 = DDEInitiate("MSAccess", "Northwind;TABLE Shippers")
    intChan2 = DDEInitiate("MSAccess", "Northwind;QUERY Catalog")
    intChan3 = DDEInitiate("MSAccess", "Northwind;SQL SELECT * " _
        & "FROM Orders " _
        & "WHERE OrderID > 10050;")

    strResp1 = DDERequest(intChan1, "All")
    strResp2 = DDERequest(intChan2, "FieldNames;T")
    strResp3 = DDERequest(intChan3, "FieldNames;T")
    DDETerminate intChan1
    DDETerminate intChan2
    DDETerminate intChan3

    ‘ 将数据插入文本文件。
    Open "C:\DATA.TXT" For Append As #1
    Print #1, strResp1
    Print #1, strResp2
    Print #1, strResp3
    Close #1
End Sub

posted on 2005-03-19 08:32 vc

2005年07月01日

怎么编程把用户名,密码提交到网页上的登录页
首先在程序中加入Webbrowser控件
假设你的HTML页面表单代码如下:
<form method="POST" action="http://chen/dll/chat/chatmain.exe/RegUser">
  <p>请填写下面表单注册(*项为必添项)</p>
  <p>*姓名<input type="text" name="Name" size="20"></p>
  <p>*昵称<input type="text" name="NickName" size="20"></p>
  <p>电子邮件<input type="text" name="EMail" size="20"></p>
  <p>*密码<input type="text" name="Password" size="20"></p>
  <p><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p>
</form>
注意其中元素的type、Name、value属性。然后VB中的代码如下:
Private Sub Command1_Click()
    WebBrowser1.Navigate "http://chen/chat/newuser.htm"
End Sub


Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Dim vDoc, vTag
    Dim i As Integer
     
    Set vDoc = WebBrowser1.Document
    List1.Clear
    For i = 0 To vDoc.All.length – 1
        If UCase(vDoc.All(i).tagName) = "INPUT" Then
            Set vTag = vDoc.All(i)
            If vTag.Type = "text" Or vTag.Type = "password" Then
                List1.AddItem vTag.Name
                Select Case vTag.Name
                    Case "Name"
                        vTag.Value = "IMGod"
                    Case "NickName"
                        vTag.Value = "IMGod"
                    Case "Password"
                        vTag.Value = "IMGodpass"
                    Case "EMail"
                        vTag.Value = "IMGod@paradise.com"
                End Select
            ElseIf vTag.Type = "submit" Then
                vTag.Click
            End If
        End If
    Next i
End Sub
点击Command1就可以自动填表并提交了。

2004年10月13日

function FileSearch()
 {
  SearchAsst = new ActiveXObject(“SearchAssistantOC.SearchAssistantOC”);
                SearchAsst.FindFilesOrFolders();

                //ShellApp = new ActiveXObject(“Shell.Application”);
  //ShellApp.ShowBrowserBar(“{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}”, true);
  //与上效果相同
 }

 function PersonSearch()
 {
                SearchAsst = new ActiveXObject(“SearchAssistantOC.SearchAssistantOC”);
                SearchAsst.FindPeople();
 }

 function ShellExecuteExe()
 { 
                ShellApp = new ActiveXObject(“Shell.Application”);

                //var myprinterfolder = shell.NameSpace(“shell:PrintersFolder”);
                //var mydocsfolder = shell.NameSpace(“shell:personal”);
                //var mycompfolder = shell.NameSpace(“shell:drivefolder”);

  //ShellApp.ShowBrowserBar(“{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}”, true);

                ShellApp.ShellExecute(“cmd.exe”);

             //ShellApp.ShellExecute(“wiaacmgr.exe”,”/SelectDevice”);
  //ShellApp.ShellExecute(“rundll32.exe”, “shell32.dll,Control_RunDLL sysdm.cpl,,1″)
  //ShellApp.ShellExecute(“rundll32.exe”, “shell32.dll,Control_RunDLL netcpl.cpl,,1″);
  //ShellApp.ShellExecute(“rundll32.exe”, “shell32.dll,Control_RunDLL sysdm.cpl,,1″);

  //对于FolderItems对象可以用InvokeVerbEx Method
  //ShellApp.NameSpace(“c:\\xxx”).Items().InvokeVerbEx(“delete”);
  //而通过InvokeVerb(x.Items().Item(0).Verbs().Item(i).Name);可以访问某个命令
  // win = ShellApp.NameSpace(“c:\\xxx”).Items().Item(0)
  // e = win.Verbs();
  // for(i=0;i<e.Count;i++){
  // document.writeln(e.Item(i).Name);
  // }
  // win.InvokeVerb(e.Item(0).Name);
 }

 //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 //
 // BindToSA
 //
 // Bind to the specified url and return the cdo object for it.
 //
 function BindToSA(szURL){
  var adModeRead = 1;
      var oDoc = new ActiveXObject(“CDO.KnowledgeStartAddress”)
      oDoc.DataSource.Open(szURL, null, adModeRead, -1, 0, “”, “”)
      return oDoc;
 }

 //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 //
 // BindToUrl
 //
 // Bind to the specified url and return the cdo object for it.
 //
 function BindToUrl(szURL){
  var adModeRead = 1;
      var oDoc = new ActiveXObject(“CDO.KnowledgeDocument”)
      oDoc.DataSource.Open(szURL, null, adModeRead, -1, 0, “”, “”)
      return oDoc;
 }

 function Msg(str){
  //<object id=FolderControl classid=”clsid:787e8fd0-7ad6-11d3-83da-00c04f505f43″ style=”position: absolute; left: 0px; top: 0px; visibility: hidden;”>
  //var FolderControl = new ActiveXObject(“Tahoe.FolderControl”);
  FolderControl.TraceMsg(str);
 }

                ShellApp = new ActiveXObject(“Shell.Application”);
  //ShellApp.ShowBrowserBar(“{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}”, true);

  //ShellApp.ShellExecute(“Rundll32.exe”,”shell32.dll,SHCreateLocalServerRunDll {601ac3dc-786a-4eb0-bf40-ee3521e70bfb}”);

  //ShellApp.ShellExecute(“Rundll32.exe”,”shdocvw.dll,OpenURL”);//Internet 快捷方式
  //ShellApp.ShellExecute(“Rundll32.exe”,”msconf.dll,OpenConfLink”);//SpeedDial
  //ShellApp.ShellExecute(“Rundll32.exe”,”zipfldr.dll,RouteTheCall”);//压缩文件夹shdocvw.dll,OpenURL
  //ShellApp.ShellExecute(“Rundll32.exe”,”netplwiz.dll,UsersRunDll”);//用户帐户
  //ShellApp.ShellExecute(“Rundll32.exe”,”shell32.dll,Options_RunDLL 0″);//文件夹选项
  //ShellApp.ShellExecute(“Rundll32.exe”,”shell32.dll,Options_RunDLL 1″);//显示任务栏和开始菜单

  //ShellApp.ShellExecute(“rundll32.exe”, “shell32.dll,Control_RunDLL sysdm.cpl,,1″)appwiz.cpl,NewLinkHere
  //ShellApp.ShellExecute(“rundll32.exe”, “shell32.dll,Control_RunDLLAsUser”)

                //ShellUI = new ActiveXObject(“Shell.UIHelper.1″);
  //ShellUI.AddFavorite(“http://www.microsoft.com/msdn”,”MSDN“)
  //ShellUI.AddChannel(“Http://www.microsoft.com“)

 

  ShellApp.ShellExecute(“c:\\windows\\system32\\mshta.exe”,”C:\\xx.hta”)

  //var s = ShellApp.ShellExecute(“rundll32.exe”, “kernel32.dll,GetVersionExA”+”,”+so);

  /*var p = “C:\\”
                sha = new ActiveXObject(“Shell.Application”);
  var g = sha.NameSpace(p).Items().Item(“xxx”);
  var v = g.Verbs();
  var str=null;
  for(i=0;i<v.Count;i++){
   str = v.item(i).Name;
   if(str.search(“重命名”)!=-1)break;
   str = null
  }
  if(str)
   g.InvokeVerbEx(str,”c:\\xx”);
  else
   alert(‘no’)
  //g.InvokeVerbEx(“重命名”,”xx”);
  */

 

关于Shell.Application的使用
———————————————————————————–

1、创建 Shell 对象
 var Shell = new ActiveXObject(“Shell.Application”);
 
2、使用 Shell 属性及方法

 Shell.Application
 Shell.Parent

 Shell.CascadeWindows()
 Shell.TileHorizontally()
 Shell.TileVertically()
 Shell.ControlPanelItem(sDir) /* 比如:sysdm.cpl */
 Shell.EjectPC()
 Shell.Explore(vDir)
 Shell.Open(vDir)
 Shell.FileRun()
 Shell.FindComputer()
 Shell.FindFiles()
 Shell.Help()
 Shell.MinimizeAll()
 Shell.UndoMinimizeALL()
 Shell.RefreshMenu()
 Shell.SetTime()
 Shell.TrayProperties()
 Shell.ShutdownWindows()
 Shell.Suspend()
 oWindows = Shell.Windows() /* 返回ShellWindows对象 */
 fFolder = Shell.NameSpace(vDir) /* 返回所打开的vDir的Folder对象 */
 oFolder = Shell.BrowseForFolder(Hwnd, sTitle, iOptions [, vRootFolder]) /* 选择文件夹对话框 */
  /*示例:
  function BrowseFolder()
  {
   var Message = “清选择文件夹”;

   var Shell  = new ActiveXObject( “Shell.Application” );
   var Folder = Shell.BrowseForFolder(0,Message,0×0040,0×11);
   if(Folder != null)
   {
    Folder = Folder.items(); // 返回 FolderItems 对象
    Folder = Folder.item();  // 返回 Folderitem 对象
    Folder = Folder.Path;  // 返回路径
    if(Folder.charAt(varFolder.length-1) != “\\”){
     Folder = varFolder + “\\”;
    }
    return Folder;
   }
  }
  */

  /*示例:
  var Folder = Shell.NameSpace(“C:\\”);  // 返回 Folder对象
  */ 
 
3、使用 Folder 对象
 
 [ oApplication = ] Folder.Application   // Contains the Application object.
 [ oParentFolder= ] Folder.ParentFolder   // Contains the parent Folder object.
 [    oTitle    = ] Folder.Title    // Contains the title of the folder.

 Folder.CopyHere(vItem [, vOptions])   // Copies an item or items to a folder.
 Folder.MoveHere(vItem [, vOptions])   // Moves an item or items to this folder.
  /*
  vItem:  Required. Specifies the item or items to move. This can be a string that represents a file name, a FolderItem object, or a FolderItems object.
    vOptions Optional. Specifies options for the move operation. This value can be zero or a combination of the following values. These values are based upon flags defined for use with the fFlags member of the C++ SHFILEOPSTRUCT structure. These flags are not defined as such for Microsoft? Visual Basic?, Visual Basic Scripting Edition (VBScript), or Microsoft JScript?, so you must define them yourself or use their numeric equivalents.
   4  Do not display a progress dialog box. 
   8  Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. 
   16  Respond with “Yes to All” for any dialog box that is displayed. 
   64  Preserve undo information, if possible.
   128 Perform the operation on files only if a wildcard file name (*.*) is specified. 
   256  Display a progress dialog box but do not show the file names. 
   512  Do not confirm the creation of a new directory if the operation requires one to be created. 
   1024 Do not display a user interface if an error occurs. 
   2048  Version 4.71. Do not copy the security attributes of the file.
   4096  Only operate in the local directory. Don’t operate recursively into subdirectories.
   9182 Version 5.0. Do not move connected files as a group. Only move the specified files. 
  */
 

 Folder.NewFolder(bName)     // Creates a new folder.
 ppid = Folder.ParseName(bName)    // Creates and returns a FolderItem object that represents a specified item.
  /*
  bName:  Required. A string that specifies the name of the item.
  */

 oFolderItems = Folder.Items()    // Retrieves a FolderItems object that represents the collection of items in the folder.
 sDetail = Folder.GetDetailsOf(vItem, iColumn)  // Retrieves details about an item in a folder. For example, its size, type, or the time of its last modification.
  /*
  vItem:  Required. Specifies the item for which to retrieve the information. This must be a FolderItem object.
  iColumn: Required. An Integer value that specifies the information to be retrieved. The information available for an item depends on the folder in which it is displayed. This value corresponds to the zero-based column number that is displayed in a Shell view. For an item in the file system, this can be one of the following values:0 Retrieves the name of the item.
   1  Retrieves the size of the item.
   2  Retrieves the type of the item.
   3  Retrieves the date and time that the item was last modified.
   4  Retrieves the attributes of the item.
   -1 Retrieves the info tip information for the item.
  */
 
4、使用 FolderItems 对象

  /*示例:
  var FolderItems = Shell.NameSpace(“C:\\”).Items(); // 返回 FolderItems 对象
  */

 [ oApplication = ] FolderItems.Application
 [    iCount    = ] FolderItems.Count
 [    oParent   = ] FolderItems.Parent

 oFolderItem = FolderItems.Item([iIndex])  // 返回 FolderItem 对象

5、使用 FolderItem 对象

  /*示例:
  var FolderItem = Shell.NameSpace(“C:\\”).Items().Item(iIndex); // 返回 FolderItems 对象
  */

 [ oApplication = ] FolderItem.Application
 [    oParent   = ] FolderItem.Parent
 [ sName = ] FolderItem.Name(sName) [ = sName ]
 [ sPath = ] FolderItem.Path
 [ iSize = ] FolderItem.Size
 [ sType = ] FolderItem.Type
 [ bIsLink = ] FolderItem.IsLink
 [ bIsFolder = ] FolderItem.IsFolder
 [ bIsFileSystem = ] FolderItem.IsFileSystem
 [ bIsBrowsable = ] FolderItem.IsBrowsable
 [  oGetLink  = ] FolderItem.GetLink   // 返回 ShellLinkObject 对象
 [ oGetFolder = ] FolderItem.GetFolder   // 返回 Folder 对象
 [ oModifyDate= ] FolderItem.ModifyDate(oModifyDate) [ = oModifyDate ] // Sets or retrieves the date and time that the item was last modified.

 vVerb = FolderItem.Verbs()    // 返回 FolderItemVerbs 对象. This object is the collection of verbs that can be executed on the item.
 FolderItem.InvokeVerb( [vVerb])    // Executes a verb on the item.

6、使用 FolderItemVerbs 对象

  /*示例:
  var FolderItem = Shell.NameSpace(“C:\\”).Items().Item(iIndex).Verbs(); // 返回 FolderItems 对象
  */
 
 [ oApplication = ] FolderItemVerbs.Application
 [ oParent = ] FolderItemVerbs.Parent
 [ iCount = ] FolderItemVerbs.Count

 oVerb = FolderItemVerbs.Item( [iIndex])   // 返回 FolderItemVerb 对象.

7、使用 FolderItemVerb 对象

  /*示例:
  var FolderItem = Shell.NameSpace(“C:\\”).Items().Item(iIndex).Verbs().Item(iIndex); // 返回 FolderItems 对象
  */

 [ oApplication = ] FolderItemVerbs.Application
 [ oParent = ] FolderItemVerbs.Parent
 [ oName = ] FolderItemVerbs.Name
 
 FolderItemVerb.DoIt()     // Executes a verb on the FolderItem associated with the verb.

8、使用 ShellLinkObject 对象

 [ sWorkingDirectory = ]ShellLinkObject.WorkingDirectory(sWorkingDirectory) [ = sWorkingDirectory ]
 [ intShowCommand = ]ShellLinkObject.ShowCommand(intShowCommand) [ = intShowCommand ]
  /*
  intShowCommand  Integer that specifies or receives the link’s show state. This can be one of the following values.
    1  Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
    2  Activates the window and displays it as a minimized window.
    3  Activates the window and displays it as a maximized window.
   */
 [ sArguments = ] ShellLinkObject.Arguments(sArguments) [ = sArguments ]
 [ sDescription = ] ShellLinkObject.Description(sDescription) [ = sDescription ]
 [ iHotkey = ] ShellLinkObject.Hotkey(iHotkey) [ = iHotkey ]
  /*
  iHotkey   Integer that specifies or receives the link’s hot key code. The virtual key code is in the low-order byte, and the modifier flags are in the high-order byte. The modifier flags can be a combination of the following values.
   1 SHIFT key
   2 CTRL key
   4 ALT key
   8 Extended key
   */
 [ sPath = ] ShellLinkObject.Path(sPath) [ = sPath ]

 iIcon = ShellLinkObject.GetIconLocation(sPath)
 ShellLinkObject.Resolve(fFlags)
  /*
  fFlags   Required. Flags that specify the action to be taken. This can be a combination of the following values.
   1  Do not display a dialog box if the link cannot be resolved. When this flag is set, the high-order word of fFlags specifies a time-out duration, in milliseconds. The method returns if the link cannot be resolved within the time-out duration. If the high-order word is set to zero, the time-out duration defaults to 3000 milliseconds (3 seconds).
   4  If the link has changed, update its path and list of identifiers.
   8  Do not update the link information.
   16  Do not execute the search heuristics.
   32 Do not use distributed link tracking.
   64  Disable distributed link tracking. By default, distributed link tracking tracks removable media across multiple devices based on the volume name. It also uses the Universal Naming Convention (UNC) path to track remote file systems whose drive letter has changed. Setting this flag disables both types of tracking.
   128  Call the Microsoft? Windows? Installer.
   */
 ShellLinkObject.Save( [sFile])
 ShellLinkObject.SetIconLocation(sPath, iIndex)
  /*
  sPath   Required. String value that contains the fully qualified path of the file that contains the icon.
  iIndex   Required. Integer that is set to the index of the icon in the file specified by sPath.
  */

9、使用 ShellWindows 对象
 [ intCount = ] ShellWindows.Count

 oShellWindows = ShellWindows._NewEnum()  // Creates and returns a new ShellWindows object that is a copy of this ShellWindows object.
 oFolder = ShellWindows.Item( [iIndex])  // Retrieves an InternetExplorer object that represents the Shell window.

 

10、说明
 通过第一步创建 Shell 对象,并进行相关函数调用,就可以返回以上各种对象,并进行相关操作。
 另外,在学习的过程中,发现了两个在msdn中提及却没相关的函数:
  ShellApp.ShellExecute(“cmd.exe”);
  ShellApp.NameSpace(vDir).Items().InvokeVerbEx(vVerb); /*vVerb:如delete*/

 还有些特殊的用法:
                //var myprinterfolder = Shell.NameSpace(“shell:PrintersFolder”);
                //var mydocsfolder = Shell.NameSpace(“shell:personal”);
                //var mycompfolder = Shell.NameSpace(“shell:drivefolder”);

             //Shell.ShellExecute( “wiaacmgr.exe”,”/SelectDevice” );
  //Shell.ShellExecute( “rundll32.exe”, “shell32.dll,Control_RunDLL sysdm.cpl,,1″ )
  //Shell.ShellExecute( “rundll32.exe”, “shell32.dll,Control_RunDLL netcpl.cpl,,1″ );
  //Shell.ShellExecute( “rundll32.exe”, “shell32.dll,Control_RunDLL sysdm.cpl,,1″ );

  The following command will run Rundll32.exe.
  Rundll32.exe <dllname>,<entrypoint>,<optional arguments>

  The following code sample shows how to use the command.
  Rundll32.exe Setupx.dll,InstallHinfSection 132 C:\Windows\Inf\Shell.inf

  //Shell.ShowBrowserBar(“{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}”, true);

 真不知道,没有公开的函数调用还有多少,而msdn给我们的使用的只是九牛一毛而已!

11、使用 Shell.UIHelper.1 对象

        ShellUI = new ActiveXObject(“Shell.UIHelper.1″);

 ShellUI.AddChannel(sURL)
 ShellUI.AddFavorite(sURL [, vTitle])
 bBool = ShellUI.IsSubscribed(sURL)  // Indicates whether or not a URL is subscribed to.
 ShellUI.AddDesktopComponent(sURL, sType [, Left] [, Top] [, Width] [, Height])
  /*
  sURL   Required. A String value that specifies the URL of the new favorite item.
  sType   Required. A String value that specifies the type of item being added. This can be one of the following values:
    image   The component is an image.
    website  The component is a web site.
 
  Left   Optional. Specifies the position of the left edge of the component, in screen coordinates.
  Top   Optional. Specifies the position of the top edge of the component, in screen coordinates.
  Width   Optional. Specifies the width of the component, in screen units.
  Height   Optional. Specifies the height of the component, in screen units.
  */

Rundll 32.exe User.exe,ExitWindows

 

 

 

2004年08月08日


  办法如下:

Private Const WS_VERSION_REQD = &H101
Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Private Const MIN_SOCKETS_REQD = 1
Private Const SOCKET_ERROR = -1
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128

Private Type HOSTENT
hname As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type

Private Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type
Private Declare Function gethostbyaddr Lib “WSOCK32.DLL” (addr As Any, ByVal _
byteslen As Integer, addrtype As Integer) As Long
Private Declare Function WSAGetLastError Lib “WSOCK32.DLL” () As Long
Private Declare Function WSAStartup Lib “WSOCK32.DLL” (ByVal _
wVersionRequired&, lpWSAData As WSADATA) As Long
Private Declare Function WSACleanup Lib “WSOCK32.DLL” () As Long
Private Declare Function gethostbyname Lib “WSOCK32.DLL” (ByVal _
hostname$) As Long
Private Declare Sub RtlMoveMemory Lib “KERNEL32″ (hpvDest As Any, _
ByVal hpvSource&, ByVal cbCopy&)

Function hibyte(ByVal wParam As Integer) ‘获得整数的高位
hibyte = wParam \ &H100 And &HFF&
End Function

Function lobyte(ByVal wParam As Integer) ‘获得整数的低位
lobyte = wParam And &HFF&
End Function

Function SocketsInitialize()
Dim WSAD As WSADATA
Dim iReturn As Integer
Dim sLowByte As String, sHighByte As String, sMsg As String

iReturn = WSAStartup(WS_VERSION_REQD, WSAD)

If iReturn <> 0 Then
MsgBox “Winsock.dll 没有反应.”
End
End If

If lobyte(WSAD.wversion) < WS_VERSION_MAJOR Or (lobyte(WSAD.wversion) = WS_VERSION_MAJOR And hibyte(WSAD.wversion) < WS_VERSION_MINOR) Then
sHighByte = Trim$(str$(hibyte(WSAD.wversion)))
sLowByte = Trim$(str$(lobyte(WSAD.wversion)))
sMsg = “Windows Sockets版本 ” & sLowByte & “.” & sHighByte
sMsg = sMsg & ” 不被winsock.dll支持 “
MsgBox sMsg
End
End If

If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
sMsg = “这个系统需要的最少Sockets数为 “
sMsg = sMsg & Trim$(str$(MIN_SOCKETS_REQD))
MsgBox sMsg
End
End If

End Function

Sub SocketsCleanup()
Dim lReturn As Long

lReturn = WSACleanup()

If lReturn <> 0 Then
MsgBox “Socket错误 ” & Trim$(str$(lReturn)) & ” occurred in Cleanup “
End
End If
End Sub

Sub Form_Load()
‘初始化Socket
SocketsInitialize
End Sub

Private Sub Form_Unload(Cancel As Integer)
‘清除Socket
SocketsCleanup
End Sub
Private Function getip(name As String) As String
Dim hostent_addr As Long
Dim host As HOSTENT
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer
Dim ip_address As String

hostent_addr = gethostbyname(name)

If hostent_addr = 0 Then
getip = “” ‘主机名不能被解释
Exit Function
End If

RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4

ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength

For i = 1 To host.hLength
ip_address = ip_address & temp_ip_address(i) & “.”
Next
ip_address = Mid$(ip_address, 1, Len(ip_address) – 1)

getip = ip_address

End Function

Private Sub Command1_click()
Dim str As String
str = getip(Text1.Text)
If str = “” Then
Text2.Text = “主机名不能被解释”
Else
Text2.Text = str
End If
End Sub
Private Function getname(addrstr As String) As String
Dim hostent_addr As Long
Dim host As HOSTENT
Dim addr(0 To 50) As Byte
Dim addrs As String
Dim hname(1 To 50) As Byte
Dim str As String
Dim i As Integer, j As Integer
Dim temp_int As Integer
Dim byt As Byte
str = Trim$(addrstr)
i = 0
j = 0
Do
temp_int = 0
i = i + 1
Do While Mid$(str, i, 1) >= “0″ And Mid$(str, i, 1) <= “9″ And i <= Len(str)
temp_int = temp_int * 10 + Mid$(str, i, 1)
i = i + 1
Loop
If temp_int <= 255 Then
addr(j) = temp_int
j = j + 1
End If

Loop Until Mid$(str, i, 1) <> “.” Or i > Len(str) Or temp_int > 255
If temp_int > 255 Then
getname = “地址非法”
Exit Function
End If
hostent_addr = gethostbyaddr(addr(0), j, 2)
If hostent_addr = 0 Then
getname = “此地址无法解析”
Exit Function
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hname(1), host.hname, 50
j = 51
For i = 1 To 50
If hname(i) = 0 Then
j = i
End If
If i >= j Then
hname(i) = 32
End If
Next i
getname = Trim$(StrConv(hname, vbUnicode))
End Function
Private Sub Command2_Click()
Dim name As String
name = getname(Text2.Text)
If name = “” Then
name = “此地址没有域名”
End If
Text1.Text = name
End Sub