【发布时间】:2017-04-21 13:06:16
【问题描述】:
我正在尝试编写一个程序,将给定的应用程序(已经完成)和自定义 URL 添加到桌面上的上下文菜单中
当我运行程序并选择自定义时,输入所需的参数,它会创建所需的 Launcher Batch 脚本和注册表项,但未添加定义名称的变量 givenName 并且文件称为“.bat”或第一个键不会生成(需要名称)。
同样需要保存在批处理脚本中以启动所选 URL 的 URL
这是发生这种情况的表单的代码:
Public Class FormCustom
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Hide()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim DirExists As Boolean = Nothing
If My.Computer.FileSystem.DirectoryExists("C:\ShortCut") Then
DirExists = True
End If
If DirExists = False Then
My.Computer.FileSystem.CreateDirectory("C:\ShortCut")
End If
Dim Position As String = Nothing
If RadioButton1.Checked Then
Position = "Middle"
Else
If RadioButton2.Checked Then
Position = "Bottom"
End If
End If
Dim givenName As String = Nothing
Dim givenURL As String = Nothing
TextBox2.Text = givenURL
TextBox1.Text = givenName
Dim sb As New System.Text.StringBuilder
sb.AppendLine("@echo off")
sb.Append("start " + givenURL)
IO.File.WriteAllText("C:\ShortCut\" + givenName + ".bat", sb.ToString())
My.Computer.Registry.ClassesRoot.CreateSubKey("DesktopBackground\Shell\" + givenName)
My.Computer.Registry.ClassesRoot.CreateSubKey("DesktopBackground\Shell\" + givenName + "\command")
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName, True).SetValue("(Default)", "@shell32.dll")
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName + "\command", True).SetValue("(Default)", "@shell32.dll")
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName, True).SetValue("icon", "explorer.exe")
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName, True).SetValue("Position", Position)
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName + "\command", True).SetValue("(Default)", "C:\ShortCut\" + givenName + ".bat")
End Sub
End Class
我尝试用“+”添加变量并且知道它为什么不接受它
[已解决] 可在 GitHub 上找到:https://github.com/amir00t/LvL-up
【问题讨论】:
标签: vb.net registry contextmenu