Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 12-Aug-16 18:48pm
v4

You want the double quotes around the whole path, not a portion of it, so that the whole text is treated as a single parameter:
VB
System.Diagnostics.Process.Start("Regedit.exe", "/e ""D:\Test 1\My file.txt""")
 
Share this answer
 
Comments
Member 12682970 13-Aug-16 0:44am    
That did not really answer my question however after messing around with the code and I tried the double quotes (as you suggested) instead of 4, I was able to get this to work.

Thanks for the advice though.
This is how I finally got it to work..

System.Diagnostics.Process.Start("Regedit.exe", "/e """ & chosenpath & "\RegBackup.txt""" + " HKEY_LOCAL_MACHINE\SOFTWARE\TestRegKey")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900