我正在尝试编写一个程序,将给定的应用程序(已完成)和自定义URL添加到桌面上下文菜单中
当我运行程序并选择自定义时,输入所需的参数,它会创建所需的Launcher Batch脚本注册表项,但是未添加定义名称的变量givenName,文件名为“.bat”或第一个键没有生成(需要名称)。
同样的情况是,需要在Batch脚本中保存的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
答案 0 :(得分:0)
这会将 文本框' 文本设置为您的变量:
TextBox2.Text = givenURL
TextBox1.Text = givenName
你想要反过来:
givenURL = TextBox2.Text
givenName = TextBox1.Text
变量的分配方式如下:
<variable to set> = <value to give the variable>
例如:
Dim MyString1 As String = "1"
Dim MyString2 As String = "2"
Dim MyString3 As String = "3"
MyString1 = "Hello!" 'Sets "MyString1" to "Hello!".
MyString3 = MyString2 'Sets "MyString3" to the value of "MyString2".
MyString2 = "This is text" 'Sets "MyString2" to "This is text"
MessageBox.Show(MyString1) 'Shows: Hello!
MessageBox.Show(MyString2) 'Shows: This is text
MessageBox.Show(MyString3) 'Shows: 2
"Oh hi!" = MyString3 'Syntax error.
修改强>
要设置(Default)
注册表项的值,您只需为值名称指定一个空字符串。
例如:
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName, True).SetValue("", "@shell32.dll")
注意SetValue
的第一个参数中没有文字:
.SetValue("", "@shell32.dll")
' ^ Empty string.
编辑2:
您知道吗,您可以使用ElseIf
关键字在If
声明中指定替代检查:
If RadioButton1.Checked Then
Position = "Middle"
ElseIf RadioButton2.Checked Then
Position = "Bottom"
End If
用法:
If condition1 Then
'Code...
ElseIf condition2 Then
'Code...
ElseIf condition3 Then
'Code...
ElseIf condition... Then
'Code...
End If
有关MSDN的更多信息。