如何用VB建立快捷方式
下面的代码向你演示在VB中如何创建一个快捷方式。Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Sub Command1_Click()Dim lReturn As Long注释:添加到桌面
lReturn = fCreateShellLink("..\..\Desktop", "Shortcut to Calculator", "c:\windows\calc.exe", "")
注释:添加到程序组
lReturn = fCreateShellLink("", "Shortcut to Calculator", "c:\windows\calc.exe", "")
注释:添加到启动组
lReturn = fCreateShellLink("\Startup", "Shortcut to Calculator", "c:\windows\calc.exe", "")End Sub
下面的代码向你演示在VB中如何创建一个快捷方式。Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Sub Command1_Click()Dim lReturn As Long注释:添加到桌面
lReturn = fCreateShellLink("..\..\Desktop", "Shortcut to Calculator", "c:\windows\calc.exe", "")
注释:添加到程序组
lReturn = fCreateShellLink("", "Shortcut to Calculator", "c:\windows\calc.exe", "")
注释:添加到启动组
lReturn = fCreateShellLink("\Startup", "Shortcut to Calculator", "c:\windows\calc.exe", "")End Sub
Dim StrURLFile As String
Dim StrURLTarget As String
Dim FileNum As IntegerStrURLFile = "C:\Windows\Desktop\强强小屋.url" '桌面目录和标题
StrURLTarget = "http://qqxw.yeah.net" '地址
FileNum = FreeFile'Write the Internet Shortcut file
Open StrURLFile For Output As FileNum
Print #FileNum, "[InternetShortcut]"
Print #FileNum, "URL=" & StrURLTarget
Close FileNum
Sub CreateProgManGroup(DDELabel As Label, groupname As String, GroupPath As String)
Screen.MousePointer = 11
On Error Resume Next
DDELabel.LinkTopic = "ProgMan|Progman"
DDELabel.LinkMode = 2
For i% = 1 To 10 '' Loop to ensure that there is enough time to
Z% = DoEvents() '' process DDE Execute. This is redundant but needed
Next '' for debug windows.
DDELabel.LinkTimeout = 100
DDELabel.LinkExecute "[CreateGroup(" + groupname$ + Chr$(44) + GroupPath$ + ")]"
DDELabel.LinkTimeout = 50
DDELabel.LinkMode = 0
Screen.MousePointer = 0
End Sub
''创建快捷方式:
Sub CreateProgManItem(DDELabel As Label, groupname As String, CmdLine As String, IconTitle As String)
Dim i%
Dim Z%
Screen.MousePointer = 11
On Error Resume Next
DDELabel.LinkTopic = "ProgMan|Progman"
DDELabel.LinkMode = 2
For i% = 1 To 10 '' Loop to ensure that there is enough time to
Z% = DoEvents() '' process DDE Execute. This is redundant but needed
Next '' for debug windows.
DDELabel.LinkTimeout = 100
DDELabel.LinkExecute "[AddItem(" + """" + CmdLine + """" + Chr$(44) + IconTitle + Chr$(44) + ",,)]"
DDELabel.LinkExecute "[ShowGroup(groupname, 1)]"
DDELabel.LinkTimeout = 50
DDELabel.LinkMode = 0
Screen.MousePointer = 0
End Sub
''删除程序组:
Sub DeleteProgManGroup(DDELabel As Label, groupname As String)
Dim i%
Dim Z%
Screen.MousePointer = 11
On Error Resume Next
DDELabel.LinkTopic = "ProgMan|Progman"
DDELabel.LinkMode = 2
For i% = 1 To 10 '' Loop to ensure that there is enough time to
Z% = DoEvents() '' process DDE Execute. This is redundant but needed
Next '' for debug windows.
DDELabel.LinkTimeout = 100
DDELabel.LinkExecute "[DeleteGroup(" + groupname$ + ")]"
DDELabel.LinkTimeout = 50
DDELabel.LinkMode = 0
Screen.MousePointer = 0 End Sub
Sub RestoreProgMan()
On Error GoTo RestoreProgManErr
AppActivate "Program Manager" '' Activate Program Manager.
SendKeys "%{ }{Enter}", True '' Send Restore keystrokes.
RestoreProgManErr:
Exit Sub
End Sub
http://www.csdn.net/expert/topic/214/214456.shtm