熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

Shell.Application對象使用

2022-06-13   來源: .NET編程 

  創建 Shell 對象
var Shell = new ActiveXObject(ShellApplication);

  使用 Shell 屬性及方法

  ShellApplication
ShellParent

  ShellCascadeWindows()
ShellTileHorizontally()
ShellTileVertically()
ShellControlPanelItem(sDir) /* 比如sysdmcpl */
ShellEjectPC()
ShellExplore(vDir)
ShellOpen(vDir)
ShellFileRun()
ShellFindComputer()
ShellFindFiles()
ShellHelp()
ShellMinimizeAll()
ShellUndoMinimizeALL()
ShellRefreshMenu()
ShellSetTime()
ShellTrayProperties()
ShellShutdownWindows()
ShellSuspend()
oWindows = ShellWindows() /* 返回ShellWindows對象 */
fFolder = ShellNameSpace(vDir) /* 返回所打開的vDir的Folder對象 */
oFolder = ShellBrowseForFolder(Hwnd sTitle iOptions [ vRootFolder]) /* 選擇文件夾對話框 */
/*示例
function BrowseFolder()
{
var Message = 清選擇文件夾;

  var Shell = new ActiveXObject( ShellApplication );
var Folder = ShellBrowseForFolder(Messagexx);
if(Folder != null)
{
Folder = ems(); // 返回 FolderItems 對象
Folder = em(); // 返回 Folderitem 對象
Folder = FolderPath; // 返回路徑
if(FoldercharAt(varFolderlength) != \\){
Folder = varFolder + \\;
}
return Folder;
}
}
*/

  /*示例
var Folder = ShellNameSpace(C:\\); // 返回 Folder對象
*/

  使用 Folder 對象

  [ oApplication = ] FolderApplication // Contains the Application object
[ oParentFolder= ] FolderParentFolder // Contains the parent Folder object
[ oTitle = ] FolderTitle // Contains the title of the folder

  FolderCopyHere(vItem [ vOptions]) // Copies an item or items to a folder
FolderMoveHere(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
Do not display a progress dialog box
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
Respond with Yes to All for any dialog box that is displayed
Preserve undo information if possible
Perform the operation on files only if a wildcard file name (**) is specified
Display a progress dialog box but do not show the file names
Do not confirm the creation of a new directory if the operation requires one to be created
Do not display a user interface if an error occurs
Version Do not copy the security attributes of the file
Only operate in the local directory Dont operate recursively into subdirectories
Version Do not move connected files as a group Only move the specified files
*/

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

  oFolderItems = FolderItems() // Retrieves a FolderItems object that represents the collection of items in the folder
sDetail = FolderGetDetailsOf(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 zerobased column number that is displayed in a Shell view For an item in the
file system this can be one of the following values: Retrieves the name of the item
Retrieves the size of the item
Retrieves the type of the item
Retrieves the date and time that the item was last modified
Retrieves the attributes of the item
Retrieves the info tip information for the item
*/

  使用 FolderItems 對象

  /*示例
var FolderItems = ShellNameSpace(C:\\)Items(); // 返回 FolderItems 對象
*/

  [ oApplication = ] FolderItemsApplication
[ iCount = ] FolderItemsCount
[ oParent = ] FolderItemsParent

  oFolderItem = FolderItemsItem([iIndex]) // 返回 FolderItem 對象

  使用 FolderItem 對象

  /*示例
var FolderItem = ShellNameSpace(C:\\)Items()Item(iIndex); //
 返回 FolderItems 對象
*/

  [ oApplication = ] FolderItemApplication
[ oParent = ] FolderItemParent
[ sName = ] FolderItemName(sName) [ = sName ]
[ sPath = ] FolderItemPath
[ iSize = ] FolderItemSize
[ sType = ] FolderItemType
[ bIsLink = ] FolderItemIsLink
[ bIsFolder = ] FolderItemIsFolder
[ bIsFileSystem = ] FolderItemIsFileSystem
[ bIsBrowsable = ] FolderItemIsBrowsable
[ oGetLink = ] FolderItemGetLink // 返回 ShellLinkObject 對象
[ oGetFolder = ] FolderItemGetFolder // 返回 Folder 對象
[ oModifyDate= ] FolderItemModifyDate(oModifyDate) [ = oModifyDate ] // Sets or retrieves the date and time that the item was last modified

  vVerb = FolderItemVerbs() // 返回 FolderItemVerbs 對象 This obj
ect is the collection of verbs
that can be executed on the item
FolderItemInvokeVerb( [vVerb]) // Executes a verb on the item

  使用 FolderItemVerbs 對象

  /*示例
var FolderItem = ShellNameSpace(C:\\)Items()Item(iIndex)Verbs(); // 返回 FolderItems 對象
*/

  [ oApplication = ] FolderItemVerbsApplication
[ oParent = ] FolderItemVerbsParent
[ iCount = ] FolderItemVerbsCount

  oVerb = FolderItemVerbsItem( [iIndex]) // 返回 FolderItemVerb 對象

  使用 FolderItemVerb 對象

  /*示例

  var FolderItem = ShellNameSpace(C:\\)Items()Item(iIndex)
Verbs()Item(iIndex); // 返回 FolderItems 對象
*/

  [ oApplication = ] FolderItemVerbsApplication
[ oParent = ] FolderItemVerbsParent
[ oName = ] FolderItemVerbsName

  FolderItemVerbDoIt() // Executes a verb on the FolderItem as
sociated with the verb

  使用 ShellLinkObject 對象

  [ sWorkingDirectory = ]ShellLinkObjectWorkingDirectory(sWork
ingDirectory) [ = sWorkingDirectory ]
[ intShowCommand = ]ShellLinkObjectShowCommand(intShowCommand)
 [ = intShowCommand ]
/*
intShowCommand Integer that specifies or receives the links s
how state This can be one of the
following values
Activates and displays a window If the window is minimized
or maximized the system restores
it to its original size and position
Activates the window and displays it as a minimized window
Activates the window and displays it as a maximized window
*/
[ sArguments = ] ShellLinkObjectArguments(sArguments) [ = sArguments ]
[ sDescription = ] ShellLinkObjectDescription(sDescription) [ = sDescription ]
[ iHotkey = ] ShellLinkObjectHotkey(iHotkey) [ = iHotkey ]
/*
iHotkey Integer that specifies or receives the links hot key
 code The virtual key code is in
the loworder byte and the modifier flags are in the higho
rder byte The modifier flags can be a
combination of the following values
SHIFT key
CTRL key
ALT key
Extended key
*/
[ sPath = ] ShellLinkObjectPath(sPath) [ = sPath ]

  iIcon = ShellLinkObjectGetIconLocation(sPath)
ShellLinkObjectResolve(fFlags)
/*
fFlags Required Flags that specify the action to be taken This can
 be a combination of the following values
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 timeout duration in milliseconds
 The method returns if the link
cannot be resolved within the timeout duration If the highorder
word is set to zero the timeout
duration defaults to milliseconds ( seconds)
If the link has changed update its path and list of identifiers
Do not update the link information
Do not execute the search heuristics
Do not use distributed link tracking
Disable distributed link tracking By default distributed link tracking tracks removable
media across multiple devices based on the volume name It also use
s the Universal Naming Convention
(UNC) path to track remote file systems whose drive letter has cha
ged Setting this flag disables
both types of tracking
Call the Microsoft? Windows? Installer
*/
ShellLinkObjectSave( [sFile])
ShellLinkObjectSetIconLocation(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
*/

  使用 ShellWindows 對象
[ intCount = ] ShellWindowsCount

  oShellWindows = ShellWindows_NewEnum() // Creates and returns a new
 ShellWindows object that is a copy of this ShellWindows object
oFolder = ShellWindowsItem( [iIndex]) // Retrieves an InternetE
xplorer object that represents the Shell window

  說明
通過第一步創建 Shell 對象並進行相關函數調用就可以返回以上各種對象並進行相關操作
另外在學習的過程中發現了兩個在msdn中提及卻沒相關的函數
ShellAppShellExecute(cmdexe);
ShellAppNameSpace(vDir)Items()InvokeVerbEx(vVerb); /*vVerb:如delete*/

  還有些特殊的用法
//var myprinterfolder = ShellNameSpace(shell:PrintersFolder);
//var mydocsfolder = ShellNameSpace(shell:personal);
//var mycompfolder = ShellNameSpace(shell:drivefolder);

  //ShellShellExecute( wiaacmgrexe/SelectDevice );
//ShellShellExecute( rundllexe shelldllControl_RunDLL
sysdmcpl )
//ShellShellExecute( rundllexe shelldllControl_RunDLL
netcplcpl );
//ShellShellExecute( rundllexe shelldllControl_RunDLL
sysdmcpl );

  The following command will run Rundllexe
Rundllexe <dllname><entrypoint><optional arguments>

  The following code sample shows how to use the command
Rundllexe SetupxdllInstallHinfSection C:\Windows\Inf\Shellinf

  //ShellShowBrowserBar({CEEFDBECACADA} true);

  真不知道沒有公開的函數調用還有多少而msdn給我們的使用的只是九牛一毛而已!

  使用 ShellUIHelper 對象

  ShellUI = new ActiveXObject(ShellUIHelper);

  ShellUIAddChannel(sURL)
ShellUIAddFavorite(sURL [ vTitle])
bBool = ShellUIIsSubscribed(sURL) // Indicates whether or not a URL
 is subscribed to
ShellUIAddDesktopComponent(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 com
ponent in screen coordinates
Top Optional Specifies the position of the top edge of the componen
t 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 exe UserexeExitWindows

  function FileSearch()
{
SearchAsst = new ActiveXObject(SearchAssistantOCSearchAssistantOC);
SearchAsstFindFilesOrFolders();
//ShellApp = new ActiveXObject(ShellApplication);
//ShellAppShowBrowserBar({CEEFDBECACADA} true);
//與上效果相同
}

  function PersonSearch()
{
SearchAsst = new ActiveXObject(SearchAssistantOCSearchAssistantOC);
SearchAsstFindPeople();
}

  function ShellExecuteExe()
{
ShellApp = new ActiveXObject(ShellApplication);

  //var myprinterfolder = shellNameSpace(shell:PrintersFolder);
//var mydocsfolder = shellNameSpace(shell:personal);
//var mycompfolder = shellNameSpace(shell:drivefolder);

  //ShellAppShowBrowserBar({CEEFDBECACADA} true);

  ShellAppShellExecute(cmdexe);

  //ShellAppShellExecute(wiaacmgrexe/SelectDevice);
//ShellAppShellExecute(rundllexe shelldllControl_RunDLL
sysdmcpl)
//ShellAppShellExecute(rundllexe shelldllControl_RunDLL
netcplcpl);
//ShellAppShellExecute(rundllexe shelldllControl_RunDLL
sysdmcpl);

  //對於FolderItems對象可以用InvokeVerbEx Method
//ShellAppNameSpace(c:\\xxx)Items()InvokeVerbEx(delete);
//而通過InvokeVerb(xItems()Item()Verbs()Item(i)Name);可以訪問某個命令
// win = ShellAppNameSpace(c:\\xxx)Items()Item()
// e = winVerbs();
// for(i=;i<eCount;i++){
// documentwriteln(eItem(i)Name);
// }
// winInvokeVerb(eItem()Name);


}

  //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
//
// BindToSA
//
// Bind to the specified url and return the cdo object for it
//
function BindToSA(szURL){
var adModeRead = ;
var oDoc = new ActiveXObject(CDOKnowledgeStartAddress)
oDocDataSourceOpen(szURL null adModeRead )
return oDoc;
}

  //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
//
// BindToUrl
//
// Bind to the specified url and return the cdo object for it
//
function BindToUrl(szURL){
var adModeRead = ;
var oDoc = new ActiveXObject(CDOKnowledgeDocument)
oDocDataSourceOpen(szURL null adModeRead )
return oDoc;
}

  function Msg(str){
//<object id=FolderControl classid=clsid:efdadddacff >
//var FolderControl = new ActiveXObject(TahoeFolderControl);
FolderControlTraceMsg(str);
}

  ShellApp = new ActiveXObject(ShellApplication);
//ShellAppShowBrowserBar({CEEFDBECACADA} true);

  //ShellAppShellExecute(RundllexeshelldllSHCreateLocalServerRunDll
{acdcaebbfeeebfb});

  //ShellAppShellExecute(RundllexeshdocvwdllOpenURL);//Internet 快捷方式
//ShellAppShellExecute(RundllexemsconfdllOpenConfLink);//SpeedDial
//ShellAppShellExecute(RundllexezipfldrdllRouteTheCall);//壓縮文件夾shdocvwdllOpenURL
//ShellAppShellExecute(RundllexenetplwizdllUsersRunDll);//用戶帳戶
//ShellAppShellExecute(RundllexeshelldllOptions_RunDLL
);//文件夾選項
//ShellAppShellExecute(RundllexeshelldllOptions_RunDLL
);//顯示任務欄和開始菜單

  //ShellAppShellExecute(rundllexe shelldllControl_RunDLL sysdmcpl)appwizcplNewLinkHere
//ShellAppShellExecute(rundllexe shelldllControl_RunDLLAsUser)

  //ShellUI = new ActiveXObject(ShellUIHelper);
//ShellUIAddFavorite(MSDN)
//ShellUIAddChannel()

  ShellAppShellExecute(c:\\windows\\system\\mshtaexeC:\\xxhta)

  //var s = ShellAppShellExecute(rundllexe kerneldllGetVersionExA++so);

  /*var p = C:\\
sha = new ActiveXObject(ShellApplication);
var g = shaNameSpace(p)Items()Item(xxx);
var v = gVerbs();
var str=null;
for(i=;i<vCount;i++){
str = em(i)Name;
if(strsearch(重命名)!=)break;
str = null
}
if(str)
gInvokeVerbEx(strc:\\xx);
else
alert(no)
//gInvokeVerbEx(重命名xx);
*/


From:http://tw.wingwit.com/Article/program/net/201311/13008.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.