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.
jvierra
Posts: 13889
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: openfiledialog control set and jobs with credentials

Post by jvierra » Fri Sep 28, 2018 4:11 pm

Sorry but without some idea of the code that is running there is no way to know what the error means.

jvierra
Posts: 13889
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: openfiledialog control set and jobs with credentials

Post by jvierra » Fri Sep 28, 2018 4:52 pm

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
Joined: Mon Dec 08, 2014 10:30 am

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH » Sat Sep 29, 2018 4:17 pm

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

Mainform:
  1. $form1_Load={
  2.  
  3.     #TODO: Initialize Form Controls here
  4.  
  5. }
  6.  
  7. $buttonCred_Click={
  8.  
  9.     #TODO: Place custom script here
  10.  
  11.     $job = start-job -Name "withcreds" -Credential $mycreds -ScriptBlock { "Incredible!" }
  12.  
  13.     Start-Sleep -Seconds 3
  14.  
  15.     $textbox1.Text = $job.State + ": " + (Receive-Job -Job $job)
  16.  
  17. }
  18.  
  19. $buttonNoCred_Click={
  20.  
  21.     #TODO: Place custom script here
  22.  
  23.     $job = Start-Job -Name "nocreds" -ScriptBlock { "Incredulous" }
  24.  
  25.     Start-Sleep -Seconds 3
  26.  
  27.     $textbox1.Text = $job.State + ": " + (Receive-Job -Job $job)
  28.  
  29. }
  30.  
  31. $buttonTestCreds_Click={
  32.  
  33.     #TODO: Place custom script here
  34.  
  35.     $WMI = Get-WmiObject Win32_OperatingSystem -ComputerName "SomeServerInTexas" -Credential $mycreds
  36.  
  37.     $textbox1.Text = $WMI.caption
  38.  
  39. }
Globals:
  1. $secpasswd = ConvertTo-SecureString "mypassword" -AsPlainText -Force
  2.  
  3. $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 811 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 811 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: 13889
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: openfiledialog control set and jobs with credentials

Post by jvierra » Sat Sep 29, 2018 4:26 pm

Please post your PSF file.

User avatar
ITFTECH
Posts: 15
Joined: Mon Dec 08, 2014 10:30 am

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH » Sat Sep 29, 2018 5:22 pm

mainform.psf is attached

I've been playing with debugging. Changed Cred_click to
  1. $buttonCred_Click={
  2.  
  3.     $textbox1.Text += "`r`n***Cred_click***"
  4.  
  5.     try { $job = start-job -Name "withcreds" -Credential $mycreds -ScriptBlock { "Incredible!" } -ErrorAction Stop }
  6.  
  7.     catch{ $textbox1.Text += "`r`nexception from Start-Job`r`n" + $_.Exception }
  8.  
  9.    
  10.  
  11.     Start-Sleep -Seconds 3
  12.  
  13.    
  14.  
  15.     try { $received = Receive-Job -Job $job -ErrorAction Stop }
  16.  
  17.     catch { $textbox1.Text += "`r`nexception from Receive-Job`r`n" + $_.Exception }
  18.  
  19.     $textbox1.Text += "`r`n" + $job.State + "`r`nReceived: $received" + "`r`nHasMoreData" + $job.HasMoreData
  20.  
  21. }
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 28 times

jvierra
Posts: 13889
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: openfiledialog control set and jobs with credentials

Post by jvierra » Sat Sep 29, 2018 5:41 pm

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
Joined: Mon Dec 08, 2014 10:30 am

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH » Sat Sep 29, 2018 6:10 pm

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: 13889
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: openfiledialog control set and jobs with credentials

Post by jvierra » Sat Sep 29, 2018 6:18 pm

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
Joined: Mon Dec 08, 2014 10:30 am

Re: openfiledialog control set and jobs with credentials

Post by ITFTECH » Sat Sep 29, 2018 6:46 pm

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: 13889
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: openfiledialog control set and jobs with credentials

Post by jvierra » Sat Sep 29, 2018 8:12 pm

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.

Locked