當我的程序想要爲Win 7(或Vista)中的所有用戶添加啓動快捷方式時,它有一個「未經授權的訪問例外」,即使我以管理員身份登錄。獲得授權所有用戶的啓動快捷方式
如何在我的程序中爲所有用戶授予訪問權限?
下面是代碼:
Imports IWshRuntimeLibrary
公共類Form1中
Dim AppName As String = "StartUp ShortCut"
Dim startUpFolderPathALLUSERfWin7 As String = Environment.GetEnvironmentVariable(("ALLUSERSPROFILE") & "\Microsoft\Windows\Start Menu\Programs\Startup")
Private Sub Create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lnkPathAllUserWin7 As String = startUpFolderPathALLUSERfWin7 & "\" & AppName & ".lnk" 'need permission
Dim appPath As String = My.Computer.FileSystem.CurrentDirectory & "\" & AppName & ".exe"
Try
Dim wshs As IWshShell_Class = New IWshShell_Class
Dim shortcut As IWshShortcut_Class = TryCast(wshs.CreateShortcut(lnkPathAllUserWin7), IWshShortcut_Class)
shortcut.Description = "This is a shortcut to " & AppName
shortcut.TargetPath = appPath
shortcut.IconLocation = appPath + ",0"
shortcut.Save()
MsgBox("ShortCut File Created")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
末級
你嘗試了什麼,看到你的代碼可能會有所幫助。添加代碼 – 2010-11-04 03:46:22
(請參閱上文)。 – jameslcs 2010-11-04 19:22:55