变量无法嵌入 [英] Variables cant get embedded
问题描述
我试图编写一个程序,将给定的应用程序(已经完成)和自定义URL添加到桌面上的上下文菜单中
I am trying to write a programm that adds given Apps (already done) and custom URLs to the context menu on the desktop
当我运行程序并选择自定义,输入所需的参数,它将创建所需的Launcher Batch脚本,注册表项,但没有添加定义Name的变量namedName,并且文件名为 .bat,或者没有生成第一个Key(需要名称)。
When I run the programm and choose custom, enter the needed parameters, it creates the needed Launcher Batch script the registry key but the variable givenName which defines the Name wasnt added and the files are called ".bat" or the first Key doesnt gets generated (which needs the name).
需要将其保存在Batch脚本中以启动所选URL的URL也是一样
the same is going on with the URL that needs to be saved in the Batch script to launch the chosen URL
这是发生此情况的表单代码:
This is the Code for the Form where this is happening:
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
我尝试添加带有 +的变量,并且知道真的知道为什么它不能访问pt
I tried to add the variable with a "+" and know really know why it doesnt accept it
[已解决]在GitHub上可用: https://github.com/amir00t/LvL-up
[SOLVED] Availible on GitHub: https://github.com/amir00t/LvL-up
推荐答案
这将设置 文本框 文本到变量中:
This sets the text boxes' text to your variables:
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.
编辑:
要设置(默认)
注册表项的值,您只需为值名称指定一个空字符串即可。
To set the value of the (Default)
registry key you shall just specify an empty string for the value name.
例如:
My.Computer.Registry.ClassesRoot.OpenSubKey("DesktopBackground\Shell\" + givenName, True).SetValue("", "@shell32.dll")
注意 SetValue
的第一个参数中没有文本:
Notice how there's no text in the first parameter of SetValue
:
.SetValue("", "@shell32.dll")
' ^ Empty string.
编辑2:
您知道吗,您可以使用 ElseIf
关键字在 If
语句:
Just so you know, there is the ElseIf
keyword that you can use to specify an alternative check in your If
-statement:
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 。
这篇关于变量无法嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!