本文介绍了路径有空格时如何使用process.start(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我真的在努力尝试使用Process.Start(Regedit.exe,/工作的路径+参数。



我没有设置路径,因为用户可以选择导出注册表项的路径。问题是,如果我选择一个名称中不包含空格的文件夹,它可以正常工作。如果我选​​择一个文件夹或创建一个有空格的文件夹,它就不起作用。



为了测试,我在USB记忆棒上创建了2个文件夹;



测试

测试1



以下代码在选择测试时有效,但在选择测试1时则无效





我使用它的唯一方法是将它保存到c:\的根目录然后将其从C:\复制到selectedpath但我知道这是一种愚蠢的方法必须有一些我想念的小东西。



有谁可以请帮我解决一下?我有尝试了我所知道的所有内容。



我尝试了什么:



使用FolderBrowserDialog1

.Description =选择目标文件夹以保存备份。如果你愿意,可以创建一个新文件夹。

.ShowNewFolderButton = True

'打开文件夹对话框选择源文件夹

如果.ShowDialog = Windows.Forms.DialogResult.OK然后

chosenpath = .SelectedPath

finalpath = selectedpath&\ RegBackup.txt HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey



结束如果

结束

'检查是否选择了目的地文件夹或点击了取消

如果selectedpath IsNot Nothing那么

MsgBox(Reg将被导出到& finalpath,MsgBoxStyle.OkOnly)

System.Diagnostics。 Process.Start(Regedit.exe,/ e& finalpath)



ElseIf selectedpath Is Nothing Then

MsgBox(备份已中止。没有目的地选中文件夹。,MsgBoxStyle.Exclamation,标题:=备份已中止!)

退出子

否则

结束如果









我试过以下内容;



在所选路径周围添加引号(正如我发现的帖子所推荐的那样,这是一个非常古老的帖子)

finalpath =&选择路径& & \RegBackup.txt HKEY_LOCAL_MACHINE \ SOFTWARE \ TestRegKey



这不起作用



我还尝试了另一种推荐的解决方案;



string finalpath = string.format(@\ {0} \,selectedpath&\ RegBackup.txt HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey)



这不起作用,



下一页我试过了;



finalpath =@&选择路径& \RegBackup.txt HKEY_LOCAL_MACHINE \ SOFTWARE \ TestRegKey)



这不起作用。

Hi All,


I am really struggling with trying to use Process.Start("Regedit.exe", "/e path + argument) to work.

I do not have a set path as the user is to be able to select a path to export a registry key to. The problem is that if I choose a folder that does not contain a space in the name, it works fine. If I select a folder or create one with a space in it, it does not work.

For testing, I created 2 folders on a USB stick;

Test
Test 1

The code below works when selecting "Test" but not when selecting "Test 1"


The only way I have it working is that I have it save to the root of c:\ and then copy it from C:\ over to "chosenpath" but I know that this is a stupid way to do it. There must be something small I am missing.

Can anyone please please please help me with a solution? I have tried everything I know and can find.

What I have tried:

With FolderBrowserDialog1
.Description = "Select destination folder to save the backup. Create a new folder if you wish."
.ShowNewFolderButton = True
' Opens the folder dialog to select the source folder
If .ShowDialog = Windows.Forms.DialogResult.OK Then
chosenpath = .SelectedPath
finalpath = chosenpath & "\RegBackup.txt HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey"

End If
End With
' Checks to see if a destination folder was selected or "Cancel" was clicked
If chosenpath IsNot Nothing Then
MsgBox("Reg will be exported to " & finalpath, MsgBoxStyle.OkOnly)
System.Diagnostics.Process.Start("Regedit.exe", "/e " & finalpath)

ElseIf chosenpath Is Nothing Then
MsgBox("Backup aborted. No destination folder selected.", MsgBoxStyle.Exclamation, Title:="Backup aborted!")
Exit Sub
Else
End If




I have tried the following;

Adding quotation marks around the chosenpath (As recommended by a post I found however it was a very old post)
finalpath = """" & chosenpath & """" & "\RegBackup.txt HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey"

This did not work

I have also tried another recommended solution I found;

string finalpath = string.format(@"\{0}\", chosenpath & "\RegBackup.txt HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey")

That does not work,

Next I tried;

finalpath = "@" & chosenpath & "\RegBackup.txt HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey")

That does not work.

推荐答案

System.Diagnostics.Process.Start("Regedit.exe", "/e ""D:\Test 1\My file.txt""")



这篇关于路径有空格时如何使用process.start(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:51