Variable Within Job

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 3 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
DFIR-CLE
Posts: 12
Last visit: Mon Oct 10, 2022 8:40 am

Variable Within Job

Post by DFIR-CLE »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: 5.6.169
32 or 64 bit version of product: 64
Operating system: Win10
32 or 64 bit OS: 64

I have a very simple script that pulls artifacts and compresses them. The script defaults to collect to the root of C: based on a pre-populated text box and didn't allow the user to edit the file path until I had a request to make the box dynamic. I have enabled the textbox (disabled the read only function) and I now have a folder modern browser dialog so it can be dynamically populated.

My main button is a job button which keeps the form responsive, great. But the job doesn't seem to like taking the $path variable. Path is assigned to "$path = textbox1.text" which is populated from the user selection for where the logs need to go.

The catch is that if I take the exact same code, remove it from the job button, and put it in a standard button, it works. I can place my output in the downloads folder, on the desktop, etc. As soon as I try the exact same code in the job, it reverts back to the root of C: for some unknown reason.

I had two thoughts: 1. for a job, maybe I need to declare a global variable although $path is declared upon button press 2. The old variable for $path was "$path = C:" and I thought that may be cached somewhere? Thoughts?
Attachments
ScriptGUI.PNG
ScriptGUI.PNG (2.96 KiB) Viewed 1338 times
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 8:47 am
Answers: 39
Been upvoted: 30 times

Re: Variable Within Job

Post by brittneyr »

[Topic was moved by moderator to PowerShell GUI forum]
Brittney
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Variable Within Job

Post by jvierra »

Hi DFIR-CLE,

It sounds like a scope issue. When calling the job you should just use the textbox as a source for thepath as the textbox is always the current value aas selected. In programming we try to not use interim variables as they are seldom needed and lead to errors like you are seeing.

Since we don't have your code it is impossible to know what your full issue is since a null variable will behave like a root path is the current path is at the root.

I suspect this is how you are passing the variable:

-ArgumentList $path

This should be:

-ArgumentList $textbox1.Text

I also recommend renaming all controls to names that indicate their purpose such as "$folderBrowserTextbox".
This topic is 4 years and 3 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