Crete user with parameter gui

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 4 years and 4 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
cedkan
Posts: 7
Last visit: Tue Dec 26, 2023 2:36 am

Crete user with parameter gui

Post by cedkan »

Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.167
OS: Windows 10 Pro (64 Bit)
Build: v10.0.17763.0


Hi I have a question.
If I have a gui with two textboxes and one button what is the easiest way to create a local windows user without create a password for that user.My textboxes are one for username and one for description. I have also created a regular consolescript whith two mandatory parameters. what I have tried so far are creating a empty form with the control mentioned above but nothing happening. The creating process for users involves admin rights and add the user to a groupe but my ps1 script is taking care o that.

for the moment I am not able to upload the form.

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

Re: Crete user with parameter gui

Post by jvierra »

Hi cdkan. What is the issue. What have you in the button click code and what is it that is not happening? Do you get errors?
cedkan
Posts: 7
Last visit: Tue Dec 26, 2023 2:36 am

Re: Crete user with parameter gui

Post by cedkan »

Hi

My issue is the nothing happened unfortunately I removed the code but shouldn't I be able to write something like

the textbox.textproperty and pass that to the button.click event? I don't get any error back but when I check in the control panel under users nothing the. and when I run my regular script I get success

so new-local user -Name = $textbox.text -description $textboxdescription.text -nopasword | out-string or are I am missing something?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Crete user with parameter gui

Post by jvierra »

What is the error? Place the code in a try/catch block and get the error which will also be displayed on the console.
cedkan
Posts: 7
Last visit: Tue Dec 26, 2023 2:36 am

Re: Crete user with parameter gui

Post by cedkan »

Hi

i have to come back with that soon. i an not on my main computer now but i will try your suggestion and post the result as soon as possible thanks for help so far.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Crete user with parameter gui

Post by jvierra »

Here is a quick example:

Code: Select all

Try{
    New-LocalUser -Name $textboxName.Text -Description $textboxDescription.Text -NoPassword -ErrorAction Stop
}
Catch{
    [System.Windows.Forms.MessageBox]::Show($_)
}
cedkan
Posts: 7
Last visit: Tue Dec 26, 2023 2:36 am

Re: Crete user with parameter gui

Post by cedkan »

Hi again

An update on my issue. First the try catch block worked should though of that earlier. Second somehow I have referenced to control that doesn't exist so I referenced to another name for my button controll. I checked in the designer on my button control and the name was different. Anyway thanks for your help that put me in the right direction really helpful. the next thing is to put the user in the users group so it becomes active but that will be for another day again thanks again :D
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Crete user with parameter gui

Post by jvierra »

Good luck.
This topic is 4 years and 4 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