VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 在桌面上添加程序的快捷方式
发表评论(0)作者:, 平台:, 阅读:9475, 日期:2000-03-12


请问用VB编程如何实现在桌面上添加程序的快捷方式(如程序为C:\Program

Files\MyProg\Prog.exe,需加参数/Para)。

- 蔡培


A:

新键一个项目,添加命令按钮和标签各一个,把下面的代码加上去,一运行,你

将如愿以偿!


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

End If

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


-星泽(xing) vbxing@990.net