2017-04-21 56 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