简体   繁体   English

vb.net 找不到指定的文件“”C:\\Users“”

[英]vb.net Cannot find file specified “”C:\Users“”

What I want to do is when I click button2 it runs a cmd command which is我想要做的是当我点击 button2 它运行一个 cmd 命令是

attrib +s +h "Path here" , but it says it can't find specified ""Path here"" attrib +s +h "Path here" ,但它说找不到指定的 ""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.我需要执行命令: attrib +s +h "Path here" ,但它说它可以找到指定的文件 ""Path here"",我需要双单引号来运行命令。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM