编辑 2010 年 6 月:我创建的 MSI 在 Windows XP 上的 VS 2005 下。当我尝试在 Vista 下使用相同的 MSI 安装/卸载时,卸载不是很干净。我没有评估其程度或原因,但我不建议在没有进一步调查的情况下在 Vista 上使用此解决方案。
原帖:
我仍然没有找到真正解决我的问题的方法,尽管解决方法——有点破解——对于我的目的来说已经足够好了。我在其他网站上找到了这个建议(如果我能再次找到它,我会发布一个链接)。
我创建了一个具有两个功能的 VBS 文件:一个创建快捷方式,另一个根据需要创建目录结构。当文件执行时,它会根据开发人员认为合适的次数调用 MakeShortcut。
第二个 VBS 文件的工作方式相同,但删除了快捷方式。
我将第一个文件称为安装文件夹中自定义操作的一部分(右键单击安装项目、查看、自定义操作)。我在卸载文件夹中调用第二个。
问题是这两个 VBS 文件被安装到目标目录以及程序的其余部分。可能有办法摆脱它们,但我真的不在乎它们留在那里。同样,这有点像 hack,并不像我希望的那样优雅,但在我找到更好的解决方案之前它运行得很好。
这是两个文件,以防有人想使用它们:
'创建快捷方式.VBS
MakeShortcut "%AllUsersProfile%\Start Menu\Programs\My Prog Folder", _
"My Prog", _
"%ProgramFiles%\My prog\prog.exe"
Function MakeShortcut (location, text, target)
Dim objShortcut
Dim objShell
Dim expLocation
Set objShell = CreateObject("WScript.Shell")
expLocation = objShell.ExpandEnvironmentStrings(location)
expTarget = objShell.ExpandEnvironmentStrings(target)
MakeDirectory(expLocation)
set objShortcut = objShell.CreateShortcut(expLocation & "\" & text & ".lnk")
objShortcut.TargetPath = expTarget
objShortcut.Save
End Function
Function MakeDirectory (newPath)
Dim objFSO
Dim arrPath
Dim length
Dim count
Dim path
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(newPath) Then
Exit Function
End If
path = ""
count = 0
arrPath = split(newPath, "\")
length = ubound(arrPath)
While count <= length
path = path + arrPath(count) + "\"
count = count + 1
If Not objFSO.FolderExists(path) Then
objFSO.CreateFolder(path)
End If
Wend
End Function
删除快捷方式.VBS
DeleteShortcut "%AllUsersProfile%\Start Menu\Programs\My Prog Folder", _
"My Prog.lnk", _
True
Function DeleteShortcut (location, shortcut, delLoc)
Dim objShortcut
Dim objShell
Dim expLocation
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
expLocation = objShell.ExpandEnvironmentStrings(location)
DeleteDirectory(expLocation)
If objFSO.FileExists(expLocation) Then
objFSO.DeleteFile expLocation & "\" & shortcut
End If
If delLoc = True Then
DeleteDirectory location
End If
End Function
Function DeleteDirectory (path)
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(path) Then
objFSO.DeleteFolder path, True
End If
End Function