点击页面中的一按钮,显示计算机桌面
当任务栏里没有“显示桌面图标”时 可在记事本中写:
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop
备注:保存成.scf 格式
javascript:
<script language="JScript">
function fnIShellDispatch4ToggleDesktopJ()
{
var objShell = new ActiveXObject("shell.application");
objShell.ToggleDesktop();
}
</script>
VBScript:
<script language="VBScript">
function fnIShellDispatch4ToggleDesktopVB()
dim objShell
set objShell = CreateObject("shell.application")
objShell.ToggleDesktop
set objShell = nothing
end function
</script>
Visual Basic:
Private Sub fnIShellDispatch4ToggleDesktopVB()
Dim objShell As Shell
Set objShell = New Shell
objShell.ToggleDesktop
Set objShell = Nothing
End Sub
C++实现显示桌面:
/*
程序: 显示桌面 C++ 实现
说明: IShellDispatch4 接口只有WINDOWS XP以上的操作系统才支持,需要 shell32.dll 5.0或以上版本
编译环境: Microsoft Visual Studio 2008
*/
#include <windows.h>
#include <shldisp.h>
int main()
{
CoInitialize(0);
IShellDispatch4 * pdisp=NULL;
CoCreateInstance(CLSID_Shell,NULL,CLSCTX_ALL,__uuidof(IShellDispatch4),(void **)&pdisp);
pdisp->ToggleDesktop();
pdisp->Release();
CoUninitialize();
return 0;
}
C#实现显示桌面: 在vs2003中没有反应,在vs2005中可行,已测试
/*
* 程序 : 显示桌面 C# 实现
* 编译环境 : Microsoft Visual Studio 2008
*/
using System;
using System.Reflection;
namespace CSCONSOLE
{
class Program
{
public static void Main(string [] args)
{
Type oleType=Type.GetTypeFromProgID("Shell.Application");
object oleObject=System.Activator.CreateInstance(oleType);
oleType.InvokeMember("ToggleDesktop",BindingFlags.InvokeMethod,null,oleObject,null);
}
}
}
SCF文件是“WINDOWS资源管理器命令”文件,它也是一种可执行文件.
该类型文件由Windows Explorer Command解释,标准安装,包括下面3个该类型的文件
===========================
1) Explorer.scf(资源管理器)
[Shell]
Command=2
IconFile=explorer.exe,1
[Taskbar]
Command=Explorer
===========================
2)Show Desktop.scf(显示桌面)
格式类似如下:
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop
===========================
3)View Channels.scf(查看频道)
[Shell]
Command=3
IconFile=shdocvw.dll,-118
创建桌面快捷方式
<script language="javascript">
var url = "C:\\Documents and Settings\\Administrator.WBT-E231DA542FA\\Application Data\\Microsoft\\Internet Explorer\\Quick Launch\\显示桌面.scf";
var lnk = "桌面快捷方式";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var DesktopPath = shell.SpecialFolders("Desktop");
if(!fso.FolderExists(DesktopPath))
{
fso.CreateFolder(tagFolder); */
//fso.CreateFolder(DesktopPath);
}
if(!fso.FileExists(DesktopPath + "\\"+lnk+".lnk"))
{
var link = shell.CreateShortcut(DesktopPath + "\\"+lnk+ ".lnk");
link.Description = "用JS生成客户端快捷方式";
link.TargetPath = url;
link.WindowStyle = 1;
link.Save();
}
</script>
System.Diagnostics.Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL");// 控制面板
System.Diagnostics.Process.Start("explorer.exe", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}");// 我的电脑
System.Diagnostics.Process.Start("explorer.exe", "::{645FF040-5081-101B-9F08-00AA002F954E}");// 回收站
System.Diagnostics.Process.Start("explorer.exe", "::{208D2C60-3AEA-1069-A2D7-08002B30309D}");// 网上邻居
System.Diagnostics.Process.Start("rundll32.exe", "devmgr.dll DeviceManager_Execute");// 设备管理器
System.Diagnostics.Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL timedate.cpl");//日期和时间