Multi-Form - credential passing

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 5 years and 2 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
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Multi-Form - credential passing

Post by lontru »

Hi working on a tool :D
I want this functionality:
Main form get user credential : get-credential
Launch a child form with these credential.

So somehow do a runas on the childForm would be great but how?

Code: Select all

$buttonCallChildForm_Click={
	#TODO: Place custom script here
	if((Show-ChildForm_psf) -eq 'OK')
	{
		
	}
}
The child form is a tool for deleting device in SCCM so the user need access right to the configmgr module and the cmsite psdrive.
What solutions is possible to achieve above functionality
Attachments
2019-01-02_07-51-43.gif
2019-01-02_07-51-43.gif (45.17 KiB) Viewed 2587 times
Multi-Form - credential passing.zip
(104.04 KiB) Downloaded 122 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form - credential passing

Post by jvierra »

You cannot do this. You can only start a completely new process with new credentials.
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Multi-Form - credential passing

Post by lontru »

Have sleep on this and come up with to ways

1. Call another exe with start-process -credential
a single form exe created from psf can you pass param to this exe or do you need to build it as a project?

2. Convert the project main to support param.
Main call it self with start-process -credential but with param to start up the right sub psf inside the main.

way 1 would be easy to do but then i have a lot of files to manage. way 2 keep it all in same project....simpler to manage

is above solutions possible?
Attachments
jewoV5Hu7W.png
jewoV5Hu7W.png (59.92 KiB) Viewed 2544 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form - credential passing

Post by jvierra »

Here is perhaps a better way to do this. See the attached project.

THis is the only way to pass objects to a new process. With Start-Process you can only pass strings.
Attachments
Test-NewCreds.zip
(86.34 KiB) Downloaded 126 times
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Multi-Form - credential passing

Post by lontru »

it work like a charm...

have work a little with your demo...is there a way open more then one sub psf form? right now it lock so you need to close a open subform before you can start a new subform?

Code: Select all

$buttonCallChildForm_Click={
    $sb = ${function:Show-ChildForm_psf}
    $obj = [pscustomobject]@{Text = 'Hello World!'}
    $job = Start-Job -ScriptBlock $sb -Credential $cred -ArgumentList $obj
    $job | Wait-Job | Remove-Job
}

$buttonGetCredential_Click={
	$script:cred = Get-Credential -ErrorAction SilentlyContinue
	$buttonGetCredential.Text = $cred.UserName
}
Attachments
Test-NewCreds.zip
(263.3 KiB) Downloaded 112 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form - credential passing

Post by jvierra »

lontru wrote: Fri Jan 04, 2019 2:57 am
have work a little with your demo...is there a way open more then one sub psf form
Comment the line:

$job | Wait-Job | Remove-Job

You can now open multiple forms. Run a timer to remove jobs that complete when the child form is closed.
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Multi-Form - credential passing

Post by lontru »

_How do i perform a cleanup routine when the childform is closing?

So i need to pass a unique id to the childform as a argument and pass that to remove-job when the child form is closing?

Or does all the jobs disappear when the mainform closeds?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form - credential passing

Post by jvierra »

You can give a job a name.
When the job is complete you can detect that it is complete and remove it.
This topic is 5 years and 2 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