Forms Newbie

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 7 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
phurious
Posts: 15
Last visit: Tue Oct 15, 2019 12:06 pm

Re: Forms Newbie

Post by phurious »

Sorry, the code you posted does not work unless you added more to it that you did not post.
  1. # The $regPath variable is the location where the exported REG file will be saved. Set to D:\ for testing.
  2. # The $regFile variable exists nowhere in my code, so I am not sure what you are using it for.
  3. # In my script this argument statement would read as:
  4. # 'Export',
  5. # ("'{0}'" -f D:\),
  6. # unknown,
  7. # "/Y'
  8. $argList = @(
  9.     'Export',
  10.     ('"{0}"' -f $regPath),
  11.     $regfile,
  12.     '/Y'
  13. )
  14. Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argList -NoNewWindow
Running this gave me no information. I changed it to:
  1. $argList = @(
  2.     'Export',
  3.     ('"{0}"' -f $r),
  4.     "$regPath\HKLM1.REG",
  5.     '/Y'
  6. )
  7. Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argList -NoNewWindow
Even after I changed the code it still returned nothing.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms Newbie

Post by jvierra »

I ran that code with the exact same data and it worked fine.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms Newbie

Post by jvierra »

This one also works for me:
  1. $regPaths = @(
  2.     'HKCU\printers',
  3.     'HKLM\SOFTWARE\Logitech\Logitech Gaming Software'
  4.     )
  5. $filePath = 'D:\'
  6.  
  7. ForEach ($regPath in $regPaths) {
  8.     $regKey = ($regPath -replace '^HKCU', 'HKCU:') -replace '^HKLM', 'HKLM:'
  9.     $regfile = $filePath+($regPath -replace '\\', '-') + '.reg'
  10.     If (Test-Path $regKey) {
  11.         Write-Host "$regKey found!" -fore green
  12.         $regfile = '"'+$filePath + ($regPath -replace '\\', '-') + '.reg"'
  13.         Write-Host $regfile -fore Blue
  14.         $argList = @(
  15.             'Export',
  16.             ('"{0}"' -f $regPath),
  17.             $regfile,
  18.             '/Y'
  19.         )
  20.         Start-Process -FilePath C:\Windows\System32\reg.exe -ArgumentList $argList -NoNewWindow
  21.     } else {
  22.         Write-Host "$regKey NOT found!" -fore red
  23.     }
  24. }
User avatar
phurious
Posts: 15
Last visit: Tue Oct 15, 2019 12:06 pm

Re: Forms Newbie

Post by phurious »

Cut/Paste/and Ran the code you posted and this is what I get:

Image
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms Newbie

Post by jvierra »

The key does not exist on you machine. I cannot help you with that. Either you have the wrong name for the key or it does not exisit on your machine.
User avatar
phurious
Posts: 15
Last visit: Tue Oct 15, 2019 12:06 pm

Re: Forms Newbie

Post by phurious »

You can clearly see in the screencap the code is reporting that the key does not exist, but the window overlaying the Powershell Studio window is the registry editor opened to the exact key in question.
User avatar
phurious
Posts: 15
Last visit: Tue Oct 15, 2019 12:06 pm

Re: Forms Newbie

Post by phurious »

This also helps further illustrate my original question. When the code is "Run" from within Powershell Studio, the script reports the key is not found:

Image



But if the exact same code on the same machine is "Run in Console" from within Powershell Studio, the script finds the key:

Image

The credentials are the same, so why does running the script by clicking "Run" or packaging it into an EXE fail?
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Forms Newbie

Post by monoeagle »

Possibly a problem with the plattform? =)

Your Key is from the x64 Hive, your Script on the first picture is running under v4 x86 plattform.

On your second screen the console is running as x64.

Check your Configuration.
User avatar
phurious
Posts: 15
Last visit: Tue Oct 15, 2019 12:06 pm

Re: Forms Newbie

Post by phurious »

monoeagle wrote:Possibly a problem with the plattform? =)

Your Key is from the x64 Hive, your Script on the first picture is running under v4 x86 plattform.

On your second screen the console is running as x64.

Check your Configuration.
Couldn't see the forest for the trees . . . this is indeed the issue. Thank you Monoeagle!

Next question, this code has to run on both x86 and x64 systems so I am packaging it as 32 bit. How can I successfully export the registry keys on both x64 and x86? I already have a function to determine bitness built into the script but I am unfamiliar with having to address bitness dealing with the registry.
Last edited by phurious on Fri Jun 03, 2016 8:37 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms Newbie

Post by jvierra »

You must specify which hive you are querying.

The key is clearly a main hive key. If you run it as a 64 bit script on a 64 bit machine it will work correctly. The same on a 32 bit machine.
This topic is 7 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked