Shell.Application 对象由 Shell32.dll 提供,这次用更专业的 OleView 查看,可以获得这个对象有以下接口函数(省略 IDispatch 接口函数):

[id(0x60020000), propget, helpstring("Get Application object")]
HRESULT Application( [out, retval] IDispatch** ppid );
[id(0x60020001), propget, helpstring("Get Parent object")]
HRESULT Parent( [out, retval] IDispatch** ppid );
[id(0x60020002), helpstring("Get special folder from ShellSpecialFolderConstants")]
HRESULT NameSpace(
[in] VARIANT vDir,
[out, retval] Folder** ppsdf);
[id(0x60020003), helpstring("Browse the name space for a Folder")]
HRESULT BrowseForFolder(
[in] long Hwnd,
[in] BSTR Title,
[in] long Options,
[in, optional] VARIANT RootFolder,
[out, retval] Folder** ppsdf);
[id(0x60020004), helpstring("The collection of open folder windows")]
HRESULT Windows( [out, retval] IDispatch** ppid );
[id(0x60020005), helpstring("Open a folder")]
HRESULT Open( [in] VARIANT vDir );
[id(0x60020006), helpstring("Explore a folder")]
HRESULT Explore( [in] VARIANT vDir );
[id(0x60020007), helpstring("Minimize all windows")]
HRESULT MinimizeAll();
[id(0x60020008), helpstring("Undo Minimize All")]
HRESULT UndoMinimizeALL();
[id(0x60020009), helpstring("Bring up the file run")]
HRESULT FileRun();
[id(0x6002000a), helpstring("Cascade Windows")]
HRESULT CascadeWindows();
[id(0x6002000b), helpstring("Tile windows vertically")]
HRESULT TileVertically();
[id(0x6002000c), helpstring("Tile windows horizontally")]
HRESULT TileHorizontally();
[id(0x6002000d), helpstring("Exit Windows")]
HRESULT ShutdownWindows();
[id(0x6002000e), helpstring("Suspend the pc")]
HRESULT Suspend();
[id(0x6002000f), helpstring("Eject the pc")]
HRESULT EjectPC();
[id(0x60020010), helpstring("Bring up the Set time dialog")]
HRESULT SetTime();
[id(0x60020011), helpstring("Handle Tray properties")]
HRESULT TrayProperties();
[id(0x60020012), helpstring("Display shell help")]
HRESULT Help();
[id(0x60020013), helpstring("Find Files")]
HRESULT FindFiles();
[id(0x60020014), helpstring("Find a computer")]
HRESULT FindComputer();
[id(0x60020015), helpstring("Refresh the menu")]
HRESULT RefreshMenu();
[id(0x60020016), helpstring("Run a Control Panel Item")]
HRESULT ControlPanelItem( [in] BSTR szDir );
[id(0x60030000), helpstring("get restriction settings")]
HRESULT IsRestricted(
[in] BSTR Group,
[in] BSTR Restriction,
[out, retval] long* plRestrictValue);
[id(0x60030001), helpstring("Execute generic command")]
HRESULT ShellExecute(
[in] BSTR File,
[in, optional] VARIANT vArgs,
[in, optional] VARIANT vDir,
[in, optional] VARIANT vOperation,
[in, optional] VARIANT vShow);
[id(0x60030002), helpstring("Find a Printer in the Directory Service")]
HRESULT FindPrinter(
[in, optional] BSTR Name,
[in, optional] BSTR location,
[in, optional] BSTR model);
[id(0x60030003), helpstring("Retrieve info about the user's system")]
HRESULT GetSystemInformation(
[in] BSTR Name,
[out, retval] VARIANT* pv);
[id(0x60030004), helpstring("Start a service by name, and optionally set it to autostart.")]
HRESULT ServiceStart(
[in] BSTR ServiceName,
[in] VARIANT Persistent,
[out, retval] VARIANT* pSuccess);
[id(0x60030005), helpstring("Stop a service by name, and optionally disable autostart.")]
HRESULT ServiceStop(
[in] BSTR ServiceName,
[in] VARIANT Persistent,
[out, retval] VARIANT* pSuccess);
[id(0x60030006), helpstring("Determine if a service is running by name.")]
HRESULT IsServiceRunning(
[in] BSTR ServiceName,
[out, retval] VARIANT* pRunning);
[id(0x60030007), helpstring("Determine if the current user can start/stop the named service.")]
HRESULT CanStartStopService(
[in] BSTR ServiceName,
[out, retval] VARIANT* pCanStartStop);
[id(0x60030008), helpstring("Show/Hide browser bar.")]
HRESULT ShowBrowserBar(
[in] BSTR bstrClsid,
[in] VARIANT bShow,
[out, retval] VARIANT* pSuccess);
[id(0x60040000), helpstring("Add an object to the Recent Docuements")]
HRESULT AddToRecent(
[in] VARIANT varFile,
[in, optional] BSTR bstrCategory);
[id(0x60050000), helpstring("Windows Security")]
HRESULT WindowsSecurity();
[id(0x60050001), helpstring("Raise/lower the desktop")]
HRESULT ToggleDesktop();
[id(0x60050002), helpstring("Return explorer policy value")]
HRESULT ExplorerPolicy(
[in] BSTR bstrPolicyName,
[out, retval] VARIANT* pValue);
[id(0x60050003), helpstring("Return shell global setting")]
HRESULT GetSetting(
[in] long lSetting,
[out, retval] VARIANT_BOOL* pResult);
下面给例子,ShellApp.VBS,在 Win2003 测试通过:
Dim objSHA
Set objSHA = CreateObject( "Shell.Application" )
' 层叠窗口
objSHA.CascadeWindows
' 打开“Internet 选项”控制面板
objSHA.ControlPanelItem( "inetcpl.cpl" )
' 日期和时间 属性
objSHA.SetTime
' 打开任务栏属性
objSHA.TrayProperties
' 打开 C 盘
objSHA.Explore "C:\"
' 运行
objSHA.FileRun
'关机对话框
objSHA.ShutdownWindows
' 搜索文件
objSHA.FindFiles
' 打开 “我的电脑”
objSHA.ShellExecute "explorer.exe", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
' 检测打印机服务是否在运行
MsgBox objSHA.IsServiceRunning( "Spooler" )
' 显示桌面
objSHA.ToggleDesktop
' Windows 安全
' 这个功能很多人用模拟 Ctrl+Alt+Del 的办法实现,代码千百行,难怪人称牛人!
' Shell.Application 版本 4 有方法可以直接调用了!
objSHA.WindowsSecurity
Set objSHA = Nothing
还是一句话:百度一下这些函数名,会有很多例子的!