locked
input box that reads and writes to registry RRS feed

  • Question

  • Hi.

    I am trying to create a Powershell input box (GUI).  It needs to do the following:

    1. When a user launches it the first time the input field would be blank.  They would then enter a network UNC path and click OK.

    2. When the user launches it the second time they should see the value in the input box they entered in step #1.

    3. When they change the value in the input box and save it by clicking OK, then it should update the value so when they launch the script again they will see the updated value.

    I assumed the registry would be the best place to store the most updated path but I'm not sure if there is a better way.

    I would later use another script to query the registry key and use that value for further actions.

    I hope this makes sense. I can create an input box now but it basically writes the value to a variable.  I would prefer it writes it to a registry key.

    Any help would be much appreciated.

    Thanks!


    Monday, August 10, 2015 8:14 PM

Answers

  • Sure:

    Add-Type -assembly Microsoft.VisualBasic
    $unc=''
    Do {
        
        $unc=[Microsoft.VisualBasic.Interaction]::InputBox('Enter or change UNC', 'Get UNC',$unc)
    
    } Until ($unc)


    • Marked as answer by Rob Irvin Tuesday, August 11, 2015 5:54 PM
    Tuesday, August 11, 2015 5:36 PM

All replies

  • Hi Rob,

    Please post your current script and your errors. We'll need those to help you.

    Personally I wouldn't use the registry for this. I'd just use a simple text file.


    Monday, August 10, 2015 8:20 PM
  • Consider

    Add-Type -assembly Microsoft.VisualBasic
    $unc=''
    $unc=[Microsoft.VisualBasic.Interaction]::InputBox('Enter or change UNC', 'Get UNC',$unc)


    \_(ツ)_/


    • Edited by jrv Monday, August 10, 2015 10:23 PM
    Monday, August 10, 2015 9:37 PM
  • Personally, I'm okay with writing to the registry for some reasons, but there's something to consider before you get too deep into this project (and possibly end up taking Mike's suggestion). Based on my knowledge, you have to consider that a normal user account can't write to just anywhere in the registry, and that you can't read from where they can write, when they're not logged on.

    Jrv's suggestion will work for collecting the UNC, but you'll need two colons before InputBox (....Interaction]::InputBox...).

    If you still want to work with the registry, then start messing around with it. Use Get-Item and Get-ItemProperty until you understand how they work and what they do. Then consider using New-Item and New-ItemProperty until you're comfortable creating new keys and values. Then you'll need to start incorporating some logic: check for the key before you try and create it, check for the value before you create it (overwrite it), etc.



    Monday, August 10, 2015 10:21 PM
  • Thanks - fixed.


    \_(ツ)_/

    Monday, August 10, 2015 10:23 PM
  • Thanks guys.  After thinking about it I think I will go with using the text file rather than the registry due to the reasons mentioned.

    I'm going to give this a try with the different options and see what works best.

    I'll come back and mark the answer soon.

    Thanks!

    Tuesday, August 11, 2015 5:20 PM
  • I think I'm going to go with this.  I can then use the $unc variable o write to the text file.

    One more thing, let's say this box pops up and the user just clicks ok without writing anything?  Can I force it to prompt them until they enter a path?

    Something like if there entry is null then leave the box open?

    Tuesday, August 11, 2015 5:27 PM
  • Sure:

    Add-Type -assembly Microsoft.VisualBasic
    $unc=''
    Do {
        
        $unc=[Microsoft.VisualBasic.Interaction]::InputBox('Enter or change UNC', 'Get UNC',$unc)
    
    } Until ($unc)


    • Marked as answer by Rob Irvin Tuesday, August 11, 2015 5:54 PM
    Tuesday, August 11, 2015 5:36 PM
  • Thanks Mike.  That's exactly what I needed.

    Much appreciated and hopefully I can help out others in this forum in the future.

    Have a great day Mike.

    Tuesday, August 11, 2015 5:56 PM
  • Cheers Rob, you're very welcome.


    Tuesday, August 11, 2015 6:06 PM
  • That may well be exactly what you needed, but it falls short of being exactly what you asked for.
    Thursday, August 13, 2015 2:44 AM