openfiledialog control set and jobs with credentials

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 5 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: openfiledialog control set and jobs with credentials

Post by jvierra »

Sorry but without some idea of the code that is running there is no way to know what the error means.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: openfiledialog control set and jobs with credentials

Post by jvierra »

ITFTECH wrote: Fri Sep 28, 2018 4:04 pm It's Friday afternoon and I have to leave work, so I'll need to continue this effort in the evening. Will this thread be monitored between now and Monday?
I will be around all weekend in and out. If you post something I will eventually get to it.

Yes. The simplest form that can exhibit the issue is the best way to track down a difficult problem.
User avatar
ITFTECH
Posts: 15
Last visit: Tue Jun 20, 2023 1:38 pm

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH »

OK, this is as simple as it gets...

Mainform:
  1. $form1_Load={
  2.     #TODO: Initialize Form Controls here
  3. }
  4. $buttonCred_Click={
  5.     #TODO: Place custom script here
  6.     $job = start-job -Name "withcreds" -Credential $mycreds -ScriptBlock { "Incredible!" }
  7.     Start-Sleep -Seconds 3
  8.     $textbox1.Text = $job.State + ": " + (Receive-Job -Job $job)
  9. }
  10. $buttonNoCred_Click={
  11.     #TODO: Place custom script here
  12.     $job = Start-Job -Name "nocreds" -ScriptBlock { "Incredulous" }
  13.     Start-Sleep -Seconds 3
  14.     $textbox1.Text = $job.State + ": " + (Receive-Job -Job $job)
  15. }
  16. $buttonTestCreds_Click={
  17.     #TODO: Place custom script here
  18.     $WMI = Get-WmiObject Win32_OperatingSystem -ComputerName "SomeServerInTexas" -Credential $mycreds
  19.     $textbox1.Text = $WMI.caption
  20. }
Globals:
  1. $secpasswd = ConvertTo-SecureString "mypassword" -AsPlainText -Force
  2. $GLOBAL:mycreds = New-Object System.Management.Automation.PSCredential ("myadminaccount", $secpasswd)
That is EVERY line of code I added to the project after PSS built it.

I run the gui with the Run button on the ribbon.

When I click buttonCred, textbox1 = "Failed: " and the output pane shows:
ERROR: [localhost] An error occurred while starting the background process. Error reported: The directory name is invalid.
ERROR: + CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
ERROR: + FullyQualifiedErrorId : -2147467259,PSSessionStateBroken
WithoutControlSet.png
WithoutControlSet.png (3.29 KiB) Viewed 2513 times
When I click buttonNoCred, textbox1 = "Completed: Incredulous"

When I click buttonTestCreds, textbox1 = "Microsoft Windows Server 2012 R2 Datacenter"
This shows that my credential object is valid, as that account is required to hit WMI on that server.

Now here's the magic... follow closely...

1. I close the gui
2. I drag a "Textbox - Browse for File" control set onto the design
3. I immediately run the app with the little green triangle again
4. I click buttonCred, and get the same "Failed: ", and the same 3 errors
4. I click the ... button and double click a file (a full path name fills in the associated textbox)
5. I click buttonCred, and textbox1 = "Completed: Incredible!"
WithControlSet.png
WithControlSet.png (3.88 KiB) Viewed 2513 times
And it is incredible! Not way too over complicating anything, not way too many variable reassignments. Exactly like I said. The first time.

Please:
- Why does adding this control set make it work?
- Why doesn't it work in the first place?
- What do I have to do to this very simple project to get it to work... without my users needing to make a random file selection in a superfluous control?

If there is anything you think might be relevant from my Windows installation, the PSS installation, the project settings, or anything else, I'll be happy to supply it.

If there is another test or some code you think might yield more insights, let me know and I'll try.

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

Re: openfiledialog control set and jobs with credentials

Post by jvierra »

Please post your PSF file.
User avatar
ITFTECH
Posts: 15
Last visit: Tue Jun 20, 2023 1:38 pm

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH »

mainform.psf is attached

I've been playing with debugging. Changed Cred_click to
  1. $buttonCred_Click={
  2.     $textbox1.Text += "`r`n***Cred_click***"
  3.     try { $job = start-job -Name "withcreds" -Credential $mycreds -ScriptBlock { "Incredible!" } -ErrorAction Stop }
  4.     catch{ $textbox1.Text += "`r`nexception from Start-Job`r`n" + $_.Exception }
  5.    
  6.     Start-Sleep -Seconds 3
  7.    
  8.     try { $received = Receive-Job -Job $job -ErrorAction Stop }
  9.     catch { $textbox1.Text += "`r`nexception from Receive-Job`r`n" + $_.Exception }
  10.     $textbox1.Text += "`r`n" + $job.State + "`r`nReceived: $received" + "`r`nHasMoreData" + $job.HasMoreData
  11. }
Oddly, the exception is on Receive-Job. The job has already failed, but I can't find any artifacts of that. Any suggestions on capturing that might help.

***Cred_click***
exception from Receive-Job
System.Management.Automation.Remoting.PSRemotingTransportException: An error occurred while starting the background process. Error reported: The directory name is invalid. ---> System.ComponentModel.Win32Exception: The directory name is invalid
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.CreateAsync()
--- End of inner exception stack trace ---
Failed
Received:
HasMoreDataFalse
Attachments
MainForm.psf
(39.56 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: openfiledialog control set and jobs with credentials

Post by jvierra »

Your file runs with no issues. Perhaps you have a system problem.

I cannot help you if you keep changing the code and coming up with new issues.
Note the $mycreds is not defined anywhere.
User avatar
ITFTECH
Posts: 15
Last visit: Tue Jun 20, 2023 1:38 pm

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH »

Really? You need to be more specific if I'm to understand your help.

The difference between working and not working is a control set from PowerShell Studio. The. Code. Works... The. System. Works. PowerShell Studio, as it's installed on my system, can only find that working condition under specific and seemingly unrelated conditions. That's the question at hand. What about that control set is compensating for my clearly malfunctioning system and poor coding skills?

And I did not change the code. In a separate project I increased the debugging capabilities and sent you additional information. It's not a new issue; it's clarification on the exact issue I brought up in the OP.

$mycreds is defined... in the Globals.ps1, which I sent you in the previous detailed post. I'm assuming you can't do much with my admin credentials. I thought the exact method by which it was defined would suffice. You asked for the psf. I sent it.

You seem irritated, jvierra. Have I done something other than answer your every question in full detail to deserve your condescension? Perhaps there is another tech who can assist with this.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: openfiledialog control set and jobs with credentials

Post by jvierra »

You need to post the complete files/files as you are running them. There is no way to guess at anything with only a couple of pieces of code.

Note that this forum is not a customer support forum. It is a community support forum. I do not work for Sapien. I am just another user like you although I have 30+years of systems engineering and programming experience and have been using PowerShell since before its first public preview. I am also a well experienced Windows Forms programmer.

You need to understand that your issue makes very little sense so it is very likely that something you are dong in another part of the program is causing this. It is also possible that a corrupt file or a corrupt system is the cause. I can try and help you but I cannot guess at the cause. I can only look at and test your files and try to reproduce the issue. If it is a system problem then there will be little that anyone can do to help you and you will have to spend time troubleshooting your system.
User avatar
ITFTECH
Posts: 15
Last visit: Tue Jun 20, 2023 1:38 pm

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH »

My mistake. I posted in Powershell Studio, which seemed to say it was handled by Sapien techs, but apparently got bumped to this forum and didn't realized the difference. This is the first time I've been in these forums for more than "what checkbox makes this happen?" questions. For your time thus far, I thank you.

And yes, my issue makes very little sense. I too have 25 years as a Windows sysadmin, 9 years in PowerShell, have been using Window Forms since '90-something, and I don't even know where to LOOK for this issue. I've combed the windows and powershell event logs, watched processes load and unload, scoured dozens of forums...

I guess on Monday I'll start with re-installing Powershell Studio, maybe look for updates to .net, visual studio, etc... If you have any other suggestions for update and/or reinstall, or if you know a good place to pose this conundrum to other Windows Forms gurus, I'll entertain them.

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

Re: openfiledialog control set and jobs with credentials

Post by jvierra »

If yo u are a programmer of Windows forms sinc the 90's then you know that without your complete code no one can help. I don't understand why you are making it so hard to see the actual code.

Why would a forms programmer with 20 years experience not understand how to tear down and step through your issue. Also why would you not know that the issue has nothing to do with forms or PwoerShell. It is either a coding error, a damaged file or a system error. That has been obvious since the beginning.

My only advice is that you need to start with a new project and add the code in one small piece at a time until the issue happens. Start with no part of the project. Do not use any existing files.

In programming it is often the issue that adding or removing code will move the bad coding issue to a location that we are not looking at. That fools us and appears that the added or removed code is the cause and not just pushing the issue aside.

PowerShell and PSS cannot cause the issue you are seeing. It is either broken code or a system issue. From experience I can say with great certainty that it is likely broken code.

Without your full project there is nothing I or anyone else can do to help.

Sorry.
This topic is 5 years and 5 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