来源:www.cncfan.com | 2006-9-22 | (有1859人读过)
创建开始菜单快捷方式 Option Explicit
Private Sub Command1_Click()
CreateProgManGroup Me, "测试", "test.grp" CreateProgManItem Me, "d:\ghost.exe", "Ghost" CreateProgManItem Me, "d:\setupQQ.exe", "QQ"
End Sub
Sub CreateProgManGroup(X As Form, GroupName$, GroupPath$) Dim i As Integer X.Label1.LinkTopic = "ProgMan|Progman" X.Label1.LinkMode = 2 Rem 空循环使DDE有时间执行 For i = 1 To 10 DoEvents Next X.Label1.LinkTimeout = 100 Rem LinkExecute 是在DDE通道中传送这样的命令 '──建立一个名为GroupName $的程序组。 X.Label1.LinkExecute "[ CreateGroup (" + GroupName$ + Chr$(44) + GroupPath$ + ") ]" X.Label1.LinkTimeout = 50 '恢复Label1 的属性值 X.Label1.LinkMode = 0 End Sub
Sub CreateProgManItem(X As Form, CmdLine$, IconTitle$) Dim i As Integer X.Label1.LinkTopic = "ProgMan|Progman" X.Label1.LinkMode = 2 For i = 1 To 10 DoEvents Next X.Label1.LinkTimeout = 100 X.Label1.LinkExecute "[AddItem(" + CmdLine$ + Chr$(44) + IconTitle$ + Chr$(44) + ", ,) ]" X.Label1.LinkTimeout = 50 '恢复Label1 的属性值 X.Label1.LinkMode = 0 Screen.MousePointer = 0 End Sub
将程序建立成“启动”文件夹的捷径 Text1.LinkTopic = "Progman|Progman" Text1.LinkMode = 2 '手动 Text1.LinkExecute "[ShowGroup(启动, 4)]" Text1.LinkExecute "[AddItem(可执行文件完整路径, 捷径名称)]"
假设我们想把“c:\vb5db\myprog.exe”建立成“启动”资料夹名称为“我的程序”的捷径,则最后一行的 LinkExecute 应该如下:
Text1.LinkExecute "[AddItem(c:\vb5db\myprog.exe, 我的程序)]"
在桌面上添加程序的快捷方式 假如程序为C:\Program Files\MyProg\Prog.exe,需加参数/Para 新键一个项目,添加命令按钮和标签各一个,把下面的代码加上去,一运行,你将如愿以偿! Option Explicit Private Sub Command1_Click() CreateGroup "MyProg", "", "", 2, True CreateGroup "MyProg", "C:\ProgramFiles\MyProg\Prog.exe/Para", _ "Para", 3, True End Sub Sub CreateGroup(ByVal strGroup As String, ByVal strCmd As String, ByVal _ strTitle As String, ByVal intDDE As Integer, ByVal fLog As Boolean) Const strCOMMA$ = "," Const strRESTORE$ = ", 1)]" Const strACTIVATE$ = ", 5)]" Const strENDCMD$ = ")]" Const strSHOWGRP$ = "[ShowGroup(" Const strADDGRP$ = "[CreateGroup(" Const strREPLITEM$ = "[ReplaceItem(" Const strADDITEM$ = "[AddItem("
Dim i As Integer Dim Sourcefile As String, Destinationfile As String
Form1.Label1.LinkMode = 0 For i% = 1 To 20 On Error Resume Next Form1.Label1.LinkTopic = "PROGMAN|PROGMAN" '设置发送端应用程序和主题 If Err = 0 Then Exit For DoEvents Next Form1.Label1.LinkMode = 2 '采用手动方式建立连接 For i% = 1 To 10 DoEvents Next Form1.Label1.LinkTimeout = 100 '设置等待 DDE 响应消息的时间。
If Err = 0 Then Select Case intDDE Case 1 '建立程序项 Form1.Label1.LinkExecute strADDGRP & strGroup & strENDCMD Form1.Label1.LinkExecute strADDITEM & strCmd & strCOMMA & _ strTitle & String$(3, strCOMMA) & strENDCMD Case 2 '建立程序组 Form1.Label1.LinkExecute strADDGRP & strGroup & strENDCMD Form1.Label1.LinkExecute strSHOWGRP & strGroup & strRESTORE Case 3 '建立程序项,并复制一份添加到桌面 Form1.Label1.LinkExecute strADDGRP & strGroup & strENDCMD Form1.Label1.LinkExecute strADDITEM & strCmd & strCOMMA & _ strTitle & String$(3, strCOMMA) & strENDCMD Sourcefile = "C:\WINDOWS\Start Menu\Programs\" & strGroup & _ "\" & strTitle & ".lnk" ' 指定源文件名。 Destinationfile = "C:\WINDOWS\DESKTOP\" & strTitle & ".lnk" '指定目的文件名。 FileCopy Sourcefile, Destinationfile End Select End If
'断开DDE联接 Form1.Label1.LinkMode = 0 Form1.Label1.LinkTopic = "" End Sub
|