- ERROR: You cannot call a method on a null-valued expression.
- MainForm.psf (190, 4): ERROR: At Line: 190 char: 4
- ERROR: + $timerJobTracker.Start()
- ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~
- ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
- ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
Studio Issue or Code?
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.
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.
Re: Studio Issue or Code?
I think the above errors were a result of me replacing the file he sent. I copy and pasted into he existing after backing up and got the below. The only errors are the modifications that Alcha212 has made for the jobs.
Re: Studio Issue or Code?
Is this related to the modification that were made using the jobs?
https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
Re: Studio Issue or Code?
I am going to rebuild with some error control and look into adding the job functions in. Not sure how long it will take me but I would appreciate it if you guys look glance over my code when completed to offer any suggestions or if I even did it properly. Will write back up here when completed.
While I am working on that do either of you have a suggestion on how I can add a proper progress bar in there with the reduction of object processed and ensure it does not bug out when a new group of objects is added? As you can see in my code I go a bit backwards with my for statement.
While I am working on that do either of you have a suggestion on how I can add a proper progress bar in there with the reduction of object processed and ensure it does not bug out when a new group of objects is added? As you can see in my code I go a bit backwards with my for statement.
Re: Studio Issue or Code?
Sorry about that, I forgot to account for the update script being run in the background and didn't actually get to test the script. I'd modify it and fix it but it seems you're taking a new direction.branhama wrote:After replacing the file I get the below errors in the console: I have just been running from the designer, but I did export to EXE and try with the same result. It seems all actions are completing properly.
ERROR: Exception calling "AppendText" with "1" argument(s): "Object reference not set to an instance of an object." MainForm.psf (98, 3): ERROR: At Line: 98 char: 3 ERROR: + $tb_Activity.AppendText($Output) ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException ERROR: + FullyQualifiedErrorId : NullReferenceException ERROR: ERROR: Exception calling "AppendText" with "1" argument(s): "Object reference not set to an instance of an object." MainForm.psf (98, 3): ERROR: At Line: 98 char: 3 ERROR: + $tb_Activity.AppendText($Output) ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException ERROR: + FullyQualifiedErrorId : NullReferenceException ERROR:
In regards to the blog post you linked for responsive forms, that is indeed where I got most of the code. It's a helpful blog article for learning how to use jobs to prevent forms freezing up.
As for this, there is a control set that will help you out with this if you'd like to look into it. Here's a screenshot to show you where to find it:branhama wrote:I am going to rebuild with some error control and look into adding the job functions in. Not sure how long it will take me but I would appreciate it if you guys look glance over my code when completed to offer any suggestions or if I even did it properly. Will write back up here when completed.
While I am working on that do either of you have a suggestion on how I can add a proper progress bar in there with the reduction of object processed and ensure it does not bug out when a new group of objects is added? As you can see in my code I go a bit backwards with my for statement.
Re: Studio Issue or Code?
To also help you get started, here are two entries on info.sapien.com that cover the Progress Bar:
Spotlight Article: http://info.sapien.com/index.php/guis/g ... 9ncmVzcyJd
Creating Responsive Loops: http://info.sapien.com/index.php/guis/g ... 9ncmVzcyJd
Spotlight Article: http://info.sapien.com/index.php/guis/g ... 9ncmVzcyJd
Creating Responsive Loops: http://info.sapien.com/index.php/guis/g ... 9ncmVzcyJd
Re: Studio Issue or Code?
I can see an umber of errors in your code. You are never handling errors. In many cases you are just using ErrorAction to turn off error reporting. For TAKEWON you are just ignoring the errors.
One big design flaw is that altering ownership and removing ALL rules on a deep hierarchy can freeze depending on the current state of the security settings. If there are any links in the folder group then you could get it to a circular resolution black hoe if you don't skip the links.
My first question would be - why are you trying to do this? It appears that you are trying to fix something. IF you have a corrupt folder structure then this wil not work and will likely cause even more damage as you are not attempting to set any inheritance or propagation strategy. This might appear to work on folders that are not damaged or where the folders are small and not deep. Large folder hierarchy will likely fail and may well just cause you to freeze on a single call.
There is a utility that will fix the permissions. It is simple and runs very fast. Actually there are two utilities. One is SUBINACL and the other is FIXACL. YOU might want to look into using those tools.
In most cases yuo can correctly set and repair a folder hierarchy by setting and propagating the root in one call. It can still take a long time in deep folder sets.
I would suggest redesigning this to run as a job at a command prompt. The logging to the screen can be accomplished by outputting messages to the console which can be used to log to the screen when run from a form.
When setting ownership and permissions in a hierarchy we do not do this to all contained files and folder explicitly. We would just set the root folder and propagate it.
Yu also have to be careful with the current inheritance settings of the root folder as it can be in conflict with setting new permissions. You need to decide how you want to handle this issue or it can cause you to freeze when trying to fix large folder sets.
The Windows permissions wizard does all of this for you and has a nice GUI. It also guards against most mistakes and will not process links. Even the wizard can have issues if the underlying folders have problems although Microsoft has invested years in this utility and most of the issues have been addressed in the newer OS versions. In W2K the wizard would often freeze or totally destroy the ACLs if there was an issue. Don't try to re-invent the wizard. You will likely have to go through a big learning curve before you have a safe tool.
Look into ICACLS as another mostly safe tool to set a set of permissions on a hierarchy. ICACLS has also been deigned to prevent most issues with changing permissions on large folders sets. It is also much faster then using the Net Framework and can set the owner and will not set an incorrect ACL order or process links.
You should also set the initial owner on TAKEOWN to the admin group for safety.
Objects created by the system or Trusted Installer may not be easily modified. Some cannot be changed without booting into a repair prompt.
One big design flaw is that altering ownership and removing ALL rules on a deep hierarchy can freeze depending on the current state of the security settings. If there are any links in the folder group then you could get it to a circular resolution black hoe if you don't skip the links.
My first question would be - why are you trying to do this? It appears that you are trying to fix something. IF you have a corrupt folder structure then this wil not work and will likely cause even more damage as you are not attempting to set any inheritance or propagation strategy. This might appear to work on folders that are not damaged or where the folders are small and not deep. Large folder hierarchy will likely fail and may well just cause you to freeze on a single call.
There is a utility that will fix the permissions. It is simple and runs very fast. Actually there are two utilities. One is SUBINACL and the other is FIXACL. YOU might want to look into using those tools.
In most cases yuo can correctly set and repair a folder hierarchy by setting and propagating the root in one call. It can still take a long time in deep folder sets.
I would suggest redesigning this to run as a job at a command prompt. The logging to the screen can be accomplished by outputting messages to the console which can be used to log to the screen when run from a form.
When setting ownership and permissions in a hierarchy we do not do this to all contained files and folder explicitly. We would just set the root folder and propagate it.
Yu also have to be careful with the current inheritance settings of the root folder as it can be in conflict with setting new permissions. You need to decide how you want to handle this issue or it can cause you to freeze when trying to fix large folder sets.
The Windows permissions wizard does all of this for you and has a nice GUI. It also guards against most mistakes and will not process links. Even the wizard can have issues if the underlying folders have problems although Microsoft has invested years in this utility and most of the issues have been addressed in the newer OS versions. In W2K the wizard would often freeze or totally destroy the ACLs if there was an issue. Don't try to re-invent the wizard. You will likely have to go through a big learning curve before you have a safe tool.
Look into ICACLS as another mostly safe tool to set a set of permissions on a hierarchy. ICACLS has also been deigned to prevent most issues with changing permissions on large folders sets. It is also much faster then using the Net Framework and can set the owner and will not set an incorrect ACL order or process links.
You should also set the initial owner on TAKEOWN to the admin group for safety.
Objects created by the system or Trusted Installer may not be easily modified. Some cannot be changed without booting into a repair prompt.
Re: Studio Issue or Code?
Found it:
https://gallery.technet.microsoft.com/S ... r-ff4db177
Here is a utility written in PowerShell that can explicitly set ownership on a file or folder recursively if needed. When we have an object this allows us to trap for errors and to also set the owner as opposed to just taking ownership.
In your case I would add the C# code to the global scope and also add the account with full control to the object. This script can be modified very easily to do this. It also allows us to avoid throwing away the errors.
When recursively taking ownership TAKSOWN is likely faster and safer as long as you capture and react to any errors before continuing to try and modify ACLs.
$results = TAKEOWN /F <object> /A /R
$LASTEXITCODE # check for non-zero
https://gallery.technet.microsoft.com/S ... r-ff4db177
Here is a utility written in PowerShell that can explicitly set ownership on a file or folder recursively if needed. When we have an object this allows us to trap for errors and to also set the owner as opposed to just taking ownership.
In your case I would add the C# code to the global scope and also add the account with full control to the object. This script can be modified very easily to do this. It also allows us to avoid throwing away the errors.
When recursively taking ownership TAKSOWN is likely faster and safer as long as you capture and react to any errors before continuing to try and modify ACLs.
$results = TAKEOWN /F <object> /A /R
$LASTEXITCODE # check for non-zero
Re: Studio Issue or Code?
To the both of you thanks a ton for the help. My main reason for making this is work. We have network shares that were mismanaged in the past so there are tons of folder which admins no longer have access to that we need to repair. These folders could go 10+ levels in. The main problem that I have had so far with all tools I have used it that they seem to perform like a Get-ChildItem, which will ONLY get those objects you can see at the time, it will repair those and stop. Then you are forced to execute the same process over and over again until you have drilled through all the levels. Just one round of this can take 5+ hours to perform so I wanted something that would work until the job is done.
@jvierra I will check out that script and see what it is capable of however so far I have found none that actually perform the way I am needing it to. If anything it may help in adding proper error control to mine.
@Alcha212 Thanks for showing me that code for the jobs, I have noticed that some of my GUI apps seem to lockup while they are performing their actions. Hopefully this will get me in the right track to fix that and have better responding tools.
@jvierra I will check out that script and see what it is capable of however so far I have found none that actually perform the way I am needing it to. If anything it may help in adding proper error control to mine.
@Alcha212 Thanks for showing me that code for the jobs, I have noticed that some of my GUI apps seem to lockup while they are performing their actions. Hopefully this will get me in the right track to fix that and have better responding tools.
Re: Studio Issue or Code?
OK, working on the ProgressBar - Responsive Loop and have run into a couple snags I am having issues with.
Attached is my script export and also the folder structure I am using. Just some folders and blank txt documents.
My main issue right now seems to be the for loop. If I change the max to a high number is will cover all the folders/files. However if I attempt to set this to the number is should be it stops short even thought it doesn't seem to hit the max number.
And I am aware that my error control should be much better, just trying to work on the bugs before I complete everything.
Attached is my script export and also the folder structure I am using. Just some folders and blank txt documents.
My main issue right now seems to be the for loop. If I change the max to a high number is will cover all the folders/files. However if I attempt to set this to the number is should be it stops short even thought it doesn't seem to hit the max number.
And I am aware that my error control should be much better, just trying to work on the bugs before I complete everything.
- Attachments
-
- two.zip
- (11.38 KiB) Downloaded 147 times
-
- Repair-FolderPermissions.Export.ps1
- (17.44 KiB) Downloaded 145 times
Re: Studio Issue or Code?
Uh, disregard the above post. I found the issue in my for statement. Will just have to figure out how to change it up so the progress bar work properly. Thanks to you both for the help!