Forms Newbie
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Forms Newbie
I am attempting to export some registry settings in one of the routines in my form. The routine gets the content of a text file, which is a list of registry keys, and then uses REG.EXE /EXPORT to complete the export. When I run the packaged script most keys seem to export correctly, but the few which have a space in them fail. What is more strange is that if I copy and paste the code directly into a console all keys export successfully, even those with spaces. In an attempt to work around the issue, I had the script output the REG commands to a BAT file which I then called from the script. The exact same issue occurred; any registry key with a space in the path failed to export. However, if I run the BAT file created by the script manually all registry key export successfully. What am I missing?
Re: Forms Newbie
I have put together an example that demonstrates what I am seeing:
If the code is "Run" from within Powershell Studio only the first registry key, the one without a space in the path, is exported. If it is packaged into an EXE and run, same thing. However, if you choose to "Run in console" within Powershell Studio both registry keys export successfully.
- $aRegistry = @("HKCU\printers","HKLM\SOFTWARE\Logitech\Logitech Gaming Software")
- $regPath = "D:\"
- $i = 0
- $j = 0
- ForEach ($r in $aRegistry)
- {
- If ($r.Substring(0, 4) -eq "HKCU")
- {
- [String]$reg = ($r -replace 'HKCU','HKCU:')
- If (Test-Path $reg)
- {
- Write-Host "True"
- $argument = "Export $([char]34)$r$([char]34) $([char]34)$regPath\HKCU$i.reg$([char]34)"
- Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argument
- $i++
- }
- }
- Else
- {
- [String]$reg = ($r -replace 'HKLM', 'HKLM:')
- If (Test-Path $reg)
- {
- Write-Host "True"
- $argument = "Export $([char]34)$r$([char]34) $([char]34)$regPath\HKLM$j.reg$([char]34)"
- Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argument
- $j++
- }
- }
- }
Re: Forms Newbie
Like this:
- #ArgumentList is an array if you want Windows to manage the strings.
- $filePath='d:\pathfile.reg'
- $argList = @(
- 'Export',
- $r,
- $filePath
- )
- Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argsList
Re: Forms Newbie
I changed the code as you have described and it is still not working.
I assumed the abbreviated line in your code read:
I assumed the abbreviated line in your code read:
- Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argsList
Re: Forms Newbie
You may need to do it like this:
- $argList = @(
- 'Export',
- ('"{0}"' -f $regPath),
- $regfile,
- '/Y'
- )
- Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argList -NoNewWindow
Re: Forms Newbie
I ran the following command:
The error I am receiving is:
ERROR: The system was unable to find the specified registry key or value.
Because I am 100% certain the registry key exists it would seem to indicate there is something wrong with the quotations on the command line. Not sure what I can change . . .
- $RegError = cmd /c reg.exe export "$r" "$regPath\HKLM$j.reg" 2`>`1
ERROR: The system was unable to find the specified registry key or value.
Because I am 100% certain the registry key exists it would seem to indicate there is something wrong with the quotations on the command line. Not sure what I can change . . .
Re: Forms Newbie
I am sorry but I cannot help you if you do not follow instructions.
Please try the code I just posted. YU cannot just make up strings t test when you are trying to understand what the code is doing. You will just end up chasing new and unrelated errors.
Please try the code I just posted. YU cannot just make up strings t test when you are trying to understand what the code is doing. You will just end up chasing new and unrelated errors.