变量无法嵌入
Variables cant get embedded
我正在尝试编写一个程序,将给定的应用程序(已经完成)和自定义 URLs 添加到桌面上的上下文菜单
当我 运行 程序并选择自定义时,输入所需的参数,它会创建所需的 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
这会将 文本框的 文本设置为您的变量:
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 的更多信息。
我正在尝试编写一个程序,将给定的应用程序(已经完成)和自定义 URLs 添加到桌面上的上下文菜单
当我 运行 程序并选择自定义时,输入所需的参数,它会创建所需的 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
这会将 文本框的 文本设置为您的变量:
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 的更多信息。