2017-04-21 27 views
0

我想写桌面变量不能得到嵌入

当我运行PROGRAMM上,增加了给应用程序一个PROGRAMM(已完成)以及自定义网址到上下文菜单,并选择自定义,输入所需参数,它创建所需的启动器批处理脚本的注册表项,但定义名称的变量givenName未添加,文件被称为“.bat”或第一个密钥没有生成(需要名称)。

同样是怎么回事,需要保存在批处理脚本启动所选择的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

这设置文本框文字到您的变量:

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 

用法:上MSDN

If condition1 Then 
    'Code... 
ElseIf condition2 Then 
    'Code... 
ElseIf condition3 Then 
    'Code... 
ElseIf condition... Then 
    'Code... 
End If 

更多信息。

+0

对不起,让你问一个新的问题,但在看到代码之前我不可能知道问题是这么简单。:) –

+0

没问题,但我认为我发现了另一件事,我应该先修复 – Max

+0

我没有,它修复了它,但批处理脚本不会保存在注册表项的默认位置,而不是它自己创建一个 – Max