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
|