- $Child_Shown = {
- $regBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $CompName).OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment")
- $Domain = $regBase.GetValue("Domain")
- $Region = $Domain.Substring(0, 2)
- $Suffix = $regBase.GetValue("Suffix")
- $DivisionSite = $CompName.substring(0, 6)
- $Site = $RegBase.Getvalue("Site").Substring(0, 2)
- $Owner = $regBase.GetValue("Owner")
- Bitlocker_Status $CompName
- Check-OfferHelp $CompName
- Check-admins $CompName
- Log_History $CompName
- $statusbar.Text = "Done...!"
- }
Code runs at least twice
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: Code runs at least twice
Here is the block under shown
Re: Code runs at least twice
Try this:
Change the event from "Shown" to "Activated"
Use this:
Change the event from "Shown" to "Activated"
Use this:
- $Child_Activated = {
- if(-not $script:activated){
- $script:activated = $true
- $regBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $CompName).OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment")
- $Domain = $regBase.GetValue("Domain")
- $Region = $Domain.Substring(0, 2)
- $Suffix = $regBase.GetValue("Suffix")
- $DivisionSite = $CompName.substring(0, 6)
- $Site = $RegBase.Getvalue("Site").Substring(0, 2)
- $Owner = $regBase.GetValue("Owner")
- Bitlocker_Status $CompName
- Check-OfferHelp $CompName
- Check-admins $CompName
- Log_History $CompName
- $statusbar.Text = "Done...!"
- }
- }
Re: Code runs at least twice
Hi Jvierra,
Here is a very basic psf form.
This still takes a long time (till the functions finished) to load.
Thanks for your help.
Here is a very basic psf form.
This still takes a long time (till the functions finished) to load.
Thanks for your help.
- Attachments
-
- child.psf
- (67.78 KiB) Downloaded 155 times
Re: Code runs at least twice
Why are you copying PsExcc to the remote? It serves no purpose.
Why are you using xcopy? Just use Copy-Item.
What is GetInfo?
Why are you using PsExec at all?
If this is slow then you may have network issues.
Why are you using xcopy? Just use Copy-Item.
What is GetInfo?
Why are you using PsExec at all?
If this is slow then you may have network issues.
Re: Code runs at least twice
Why are you copying PsExcc to the remote? It serves no purpose.
--> For the user to be able to use it later when they need it.
Why are you using xcopy? Just use Copy-Item.
--> I had issues with copy-item before. I found that xcopy works better.
What is GetInfo?
--> Getinfo is a PowerShell script that collects the information and I grab that information once it completes.
Why are you using PsExec at all?
--> I first started trying to get all the information I wanted using wmi but it kept giving errors. So I figured I do it locally and grab all the info
If this is slow then you may have network issues.
--> I know for a fact that we don't have any network issues. Also, my test machine is a VM on my local machine.
--> For the user to be able to use it later when they need it.
Why are you using xcopy? Just use Copy-Item.
--> I had issues with copy-item before. I found that xcopy works better.
What is GetInfo?
--> Getinfo is a PowerShell script that collects the information and I grab that information once it completes.
Why are you using PsExec at all?
--> I first started trying to get all the information I wanted using wmi but it kept giving errors. So I figured I do it locally and grab all the info
If this is slow then you may have network issues.
--> I know for a fact that we don't have any network issues. Also, my test machine is a VM on my local machine.
Re: Code runs at least twice
There is no reason for Copy-Item to not work ix xcopy works.
You can use PsExec but any slowness is not due to PowerShell.
What info are you trying to get? Perhaps you exe is not compatible.
There is no technical reason for this to be slow. If you use a job the screen will still be empty until the job completes so there is really nothing you can do about that.
You can use PsExec but any slowness is not due to PowerShell.
What info are you trying to get? Perhaps you exe is not compatible.
There is no technical reason for this to be slow. If you use a job the screen will still be empty until the job completes so there is really nothing you can do about that.
Re: Code runs at least twice
I'm trying to check local groups on the remote computer and add if missing user names I want them to be in.
I have 4 functions like the one below. Doesn't matter what I did, the form either stops responding while the functions are running or doesn't pop-up until it finishes. That's why I keep trying other things.
I tried running the functions in a start-job (Not sure if I did that right) but even that didn't work.
I have 4 functions like the one below. Doesn't matter what I did, the form either stops responding while the functions are running or doesn't pop-up until it finishes. That's why I keep trying other things.
I tried running the functions in a start-job (Not sure if I did that right) but even that didn't work.
- $J = Start-Job -ScriptBlock ${function:Check_Admins} -ArgumentList $ComputerName $UserName
- Wait-Job $J
- function Check_admins ([string]$ComputerName, $UserName)
- {
- $AdminMembers = @()
- $AdminGroup = [ADSI]"WinNT://$ComputerName/Administrators,group"
- $Admin = @($AdminGroup.psbase.Invoke("Members"))
- $Admin | ForEach-Object {
- $AdminMembers += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
- }
- foreach ($Admins in $AdminMembers)
- {
- IF ($txtboxadmins.Text.Contains($Admins) -eq $true)
- {
- Out-Null
- }
- Else
- {
- $txtboxadmins.AppendText($Admins)
- $txtboxadmins.AppendText("`n")
- }
- }
- IF ($txtboxadmins.Text.Contains($UserName) -eq $true)
- {
- $txtboxadmins.Find($UserName)
- $txtboxadmins.SelectionColor = 'Brown'
- }
- ELSE
- {
- Try
- {
- $AdminGroup = [ADSI]"WinNT://$ComputerName/Administrators,group"
- $AdminGroup.psbase.Invoke("Add", ([ADSI]"WinNT://$UserName").path)
- $txtboxadmins.AppendText($UserName)
- $txtboxadmins.Find($UserName)
- $txtboxadmins.SelectionColor = 'Brown'
- }
- Catch
- {
- $txtboxadmins.Text = "ERROR adding $UserName"
- }
- }
- }
Re: Code runs at least twice
A form will always stop responding when it is in an event. When the event complete the form will be available for new events. This is how Windows works.
Read the following to better understand how forms work: https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
Also review all of the following posts: https://www.sapien.com/blog/topics/user ... istrators/
These will help you understand how to use forms and what you can expect with forms behavior.
Read the following to better understand how forms work: https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
Also review all of the following posts: https://www.sapien.com/blog/topics/user ... istrators/
These will help you understand how to use forms and what you can expect with forms behavior.
- jazz albert
- Posts: 16
- Last visit: Sat Nov 05, 2016 3:09 pm
Re: Code runs at least twice
I don't swing that way. It might be due to something else went wrong!gutihz wrote:I tried the shown event too. The child form pops-up after everything has finished.