Question

What I want to do is when I click button2 it runs a cmd command which is

attrib +s +h "Path here", but it says it can't find specified ""Path here""

This is my Code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If NotHidden.SelectedIndex >= 0 Then
        LogsKeeper.Text = LogsKeeper.Text + TimeOfDay + " | " + "Moved To Hidden: " + NotHidden.SelectedItem.ToString + vbNewLine
        Hidden.Items.Add(NotHidden.SelectedItem)
        Dim path As String = NotHidden.SelectedItem
        My.Settings.TempPath = path
        Process.Start("cmd /C " + "attrib +s +h " + My.Settings.TempPath)
        NotHidden.Items.Remove(NotHidden.SelectedItem)
        WriteTextToLogs()
        MsgBox("Folder is hidden now. if you want to delete it then you need to move it to NotHidden first ")
        HiddenFolders.Text = HiddenFolders.Text + NotHidden.SelectedItem + vbNewLine
        My.Settings.HiddenFolders = HiddenFolders.Text
        My.Settings.Save()
    Else
        MsgBox("You need to select a path first")
    End If
End Sub

And how I add folders to listbox Hidden:

Private Sub AddFolder()
    If SecretFolderPath.Text.Length > 0 Then
        SecretFolderPath.Text = """" + SecretFolderPath.Text + """"
        LogsKeeper.Text = LogsKeeper.Text + TimeOfDay + " | " + SecretFolderPath.Text + vbNewLine
        My.Settings.Logs = LogsKeeper.Text
        My.Settings.Save()
        LogsKeeper.Text = My.Settings.Logs
        Logs.Items.Clear()
        NotHidden.Items.Add(SecretFolderPath.Text)
        For Each line As String In LogsKeeper.Lines
            Logs.Items.Add(line)
        Next
        SecretFolderPath.Clear()
        MsgBox("Folder Added!")
    Else
        MsgBox("Folder path is not correct ")
    End If
End Sub

I need to Execute command : attrib +s +h "Path here", but it says it can find file specified ""Path here"" and I need the double single quotes to run the command.

Was it helpful?

Solution

This is more complicated but definitely does the trick:

Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " /C attrib +s +h " + My.Settings.TempPath
pi.FileName = "cmd.exe"
p.StartInfo = pi
p.Start()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top