明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1924|回复: 2

[推荐] 如何使用Shell.Application技术 koolfoo(原作)

[复制链接]
发表于 2003-12-2 00:22:00 | 显示全部楼层 |阅读模式
http://www.csdn.net/develop/article/16/16944.shtm
  1. CSDN - 文档中心 - Javascript     
  2.   
  3. 标题     如何使用Shell.Application技术    koolfoo(原作)
  4.   
  5. 关键字     shell,安全,javascript
  6.   


  7. 关于Shell.Application的使用
  8. -----------------------------------------------------------------------------------

  9. 1、创建 Shell 对象
  10. var Shell = new ActiveXObject("Shell.Application");

  11. 2、使用 Shell 属性及方法

  12. Shell.Application
  13. Shell.Parent

  14. Shell.CascadeWindows()
  15. Shell.TileHorizontally()
  16. Shell.TileVertically()
  17. Shell.ControlPanelItem(sDir) /* 比如:sysdm.cpl */
  18. Shell.EjectPC()
  19. Shell.Explore(vDir)
  20. Shell.Open(vDir)
  21. Shell.FileRun()
  22. Shell.FindComputer()
  23. Shell.FindFiles()
  24. Shell.Help()
  25. Shell.MinimizeAll()
  26. Shell.UndoMinimizeALL()
  27. Shell.RefreshMenu()
  28. Shell.SetTime()
  29. Shell.TrayProperties()
  30. Shell.ShutdownWindows()
  31. Shell.Suspend()
  32. oWindows = Shell.Windows() /* 返回ShellWindows对象 */
  33. fFolder = Shell.NameSpace(vDir) /* 返回所打开的vDir的Folder对象 */
  34. oFolder = Shell.BrowseForFolder(Hwnd, sTitle, iOptions [, vRootFolder]) /* 选择文件夹对话框 */
  35.   /*示例:
  36.   function BrowseFolder()
  37.   {
  38.    var Message = "清选择文件夹";

  39.    var Shell  = new ActiveXObject( "Shell.Application" );
  40.    var Folder = Shell.BrowseForFolder(0,Message,0x0040,0x11);
  41.    if(Folder != null)
  42.    {
  43.     Folder = Folder.items(); // 返回 FolderItems 对象
  44.     Folder = Folder.item();  // 返回 Folderitem 对象
  45.     Folder = Folder.Path;  // 返回路径
  46.     if(Folder.charAt(varFolder.length-1) != "\"){
  47.      Folder = varFolder + "\";
  48.     }
  49.     return Folder;
  50.    }
  51.   }
  52.   */

  53.   /*示例:
  54.   var Folder = Shell.NameSpace("C:\");  // 返回 Folder对象
  55.   */

  56. 3、使用 Folder 对象

  57. [ oApplication = ] Folder.Application   // Contains the Application object.
  58. [ oParentFolder= ] Folder.ParentFolder   // Contains the parent Folder object.
  59. [    oTitle    = ] Folder.Title    // Contains the title of the folder.

  60. Folder.CopyHere(vItem [, vOptions])   // Copies an item or items to a folder.
  61. Folder.MoveHere(vItem [, vOptions])   // Moves an item or items to this folder.
  62.   /*
  63.   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.
  64.     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.
  65.    4  Do not display a progress dialog box.  
  66.    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.  
  67.    16  Respond with "Yes to All" for any dialog box that is displayed.  
  68.    64  Preserve undo information, if possible.
  69.    128 Perform the operation on files only if a wildcard file name (*.*) is specified.  
  70.    256  Display a progress dialog box but do not show the file names.  
  71.    512  Do not confirm the creation of a new directory if the operation requires one to be created.  
  72.    1024 Do not display a user interface if an error occurs.  
  73.    2048  Version 4.71. Do not copy the security attributes of the file.
  74.    4096  Only operate in the local directory. Don't operate recursively into subdirectories.
  75.    9182 Version 5.0. Do not move connected files as a group. Only move the specified files.  
  76.   */


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

  82. oFolderItems = Folder.Items()    // Retrieves a FolderItems object that represents the collection of items in the folder.
  83. 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.
  84.   /*
  85.   vItem:  Required. Specifies the item for which to retrieve the information. This must be a FolderItem object.
  86.   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.
  87.    1  Retrieves the size of the item.
  88.    2  Retrieves the type of the item.
  89.    3  Retrieves the date and time that the item was last modified.
  90.    4  Retrieves the attributes of the item.
  91.    -1 Retrieves the info tip information for the item.
  92.   */

  93. 4、使用 FolderItems 对象

  94.   /*示例:
  95.   var FolderItems = Shell.NameSpace("C:\").Items(); // 返回 FolderItems 对象
  96.   */

  97. [ oApplication = ] FolderItems.Application
  98. [    iCount    = ] FolderItems.Count
  99. [    oParent   = ] FolderItems.Parent

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

  101. 5、使用 FolderItem 对象

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

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

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


  120. 6、使用 FolderItemVerbs 对象

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

  124. [ oApplication = ] FolderItemVerbs.Application
  125. [ oParent = ] FolderItemVerbs.Parent
  126. [ iCount = ] FolderItemVerbs.Count

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

  128. 7、使用 FolderItemVerb 对象

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

  132. [ oApplication = ] FolderItemVerbs.Application
  133. [ oParent = ] FolderItemVerbs.Parent
  134. [ oName = ] FolderItemVerbs.Name

  135. FolderItemVerb.DoIt()     // Executes a verb on the FolderItem associated with the verb.

  136. 8、使用 ShellLinkObject 对象

  137. [ sWorkingDirectory = ]ShellLinkObject.WorkingDirectory(sWorkingDirectory) [ = sWorkingDirectory ]
  138. [ intShowCommand = ]ShellLinkObject.ShowCommand(intShowCommand) [ = intShowCommand ]
  139.   /*
  140.   intShowCommand  Integer that specifies or receives the link's show state. This can be one of the following values.
  141.     1  Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
  142.     2  Activates the window and displays it as a minimized window.
  143.     3  Activates the window and displays it as a maximized window.
  144.    */
  145. [ sArguments = ] ShellLinkObject.Arguments(sArguments) [ = sArguments ]
  146. [ sDescription = ] ShellLinkObject.Description(sDescription) [ = sDescription ]
  147. [ iHotkey = ] ShellLinkObject.Hotkey(iHotkey) [ = iHotkey ]
  148.   /*
  149.   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.
  150.    1 SHIFT key
  151.    2 CTRL key
  152.    4 ALT key
  153.    8 Extended key
  154.    */
  155. [ sPath = ] ShellLinkObject.Path(sPath) [ = sPath ]

  156. iIcon = ShellLinkObject.GetIconLocation(sPath)
  157. ShellLinkObject.Resolve(fFlags)
  158.   /*
  159.   fFlags   Required. Flags that specify the action to be taken. This can be a combination of the following values.
  160.    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).
  161.    4  If the link has changed, update its path and list of identifiers.
  162.    8  Do not update the link information.
  163.    16  Do not execute the search heuristics.
  164.    32 Do not use distributed link tracking.
  165.    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.
  166.    128  Call the Microsoft? Windows? Installer.
  167.    */
  168. ShellLinkObject.Save( [sFile])
  169. ShellLinkObject.SetIconLocation(sPath, iIndex)
  170.   /*
  171.   sPath   Required. String value that contains the fully qualified path of the file that contains the icon.
  172.   iIndex   Required. Integer that is set to the index of the icon in the file specified by sPath.
  173.   */

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

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



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

  183. 还有些特殊的用法:
  184.                 //var myprinterfolder = Shell.NameSpace("shell:PrintersFolder");
  185.                 //var mydocsfolder = Shell.NameSpace("shell:personal");
  186.                 //var mycompfolder = Shell.NameSpace("shell:drivefolder");

  187.              //Shell.ShellExecute( "wiaacmgr.exe","/SelectDevice" );
  188.   //Shell.ShellExecute( "rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1" )
  189.   //Shell.ShellExecute( "rundll32.exe", "shell32.dll,Control_RunDLL netcpl.cpl,,1" );
  190.   //Shell.ShellExecute( "rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1" );

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

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


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

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


  197. 11、使用 Shell.UIHelper.1 对象

  198.         ShellUI = new ActiveXObject("Shell.UIHelper.1");

  199. ShellUI.AddChannel(sURL)
  200. ShellUI.AddFavorite(sURL [, vTitle])
  201. bBool = ShellUI.IsSubscribed(sURL)  // Indicates whether or not a URL is subscribed to.
  202. ShellUI.AddDesktopComponent(sURL, sType [, Left] [, Top] [, Width] [, Height])
  203.   /*
  204.   sURL   Required. A String value that specifies the URL of the new favorite item.
  205.   sType   Required. A String value that specifies the type of item being added. This can be one of the following values:
  206.     image   The component is an image.
  207.     website  The component is a web site.

  208.   Left   Optional. Specifies the position of the left edge of the component, in screen coordinates.
  209.   Top   Optional. Specifies the position of the top edge of the component, in screen coordinates.
  210.   Width   Optional. Specifies the width of the component, in screen units.
  211.   Height   Optional. Specifies the height of the component, in screen units.
  212.   */

  213. Rundll 32.exe User.exe,ExitWindows
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2003-12-2 08:19:00 | 显示全部楼层
very good
发表于 2003-12-2 12:00:00 | 显示全部楼层
好东东……
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-2 10:40 , Processed in 0.196159 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表