访问线程以允许在PowerShell中访问文件系统

发布于 2025-02-11 03:02:51 字数 1556 浏览 0 评论 0 原文

参考: runspace用于powershell的按钮事件 因此,我相信我的问题是PowerShell无法访问文件系统的内存空间,从我的线程的内存块中,有一种方法可以解决此问题,从多线程中访问文件系统应用? 背景故事: 因此,我运行了一个程序,该程序调用“代码”/命令,从命令提示符(*.exe)(robocopy)(robocopy)一次从服务器复制文件,一次将文件复制到一组计算机。我们的工作中有一个课堂环境,因此我的设置在某种程度上是每个房间都有一个文件夹。我将每个房间的所有地址(静态)保留在其视角文件夹中。我们从开发人员那里有一个更新,我们需要推到所有房间。我们需要缓慢推动,以免打扰生产环境。它是专有的,因此我们不能使用A/任何典型解决方案(例如Microsoft SCCM)。因此,我创建了一个脚本来推到房间。虽然确实有效,但它不是一个平稳的操作。实际上,由于过程缓慢,我并不是强迫更新的人。我只是想为那个要这样做的人制作一个稳定的平稳运行套餐。我的代码在线程之外工作,(i)对其进行了测试,我知道它有效。 因此,我如何得出结论,即我的代码在线程之外工作。 (图片)我使用代码遵循相同的设置(在线程内部单击“按钮”事件,运行表单)。在完成后端操作代码测试后,放置了实际的工作代码(在制作线程之前,在制作线程之前对接口进行了尝试和测试。) (“ Boe's添加”)指BOE Prox,(来自链接) 在他的中,他正在通过线程内运行的函数从命令行/powershell窗口进行更新。我正在从一个按钮,线程内部运行一个事件,并试图运行单独的线程,以进行单击事件。在线外。该活动效果很好,但是在内部,它根本不起作用。 基本代码:

   // Multi thread, thread for the $form, and thread for the event (as per referenced link)
   $var = [PowerShell]::Create().AddScript({ button.Add_Click{
       $var = [PowerShell]::Create().AddScript{<Thread><Robocopy></Thread>}
   })

Actual code showing what the basic is code is supposed to look like

Reference: Runspace for button event in powershell
https://www.foxdeploy.com/blog/part-v-powershell-guis-responsive-apps-with-progress-bars.html
So, I believe my issue is that PowerShell is unable to access the memory space of the file system, from within the memory block, of my thread, is there a way to solve this, to access the file system, from a multi-threaded application?
Back Story:
So, I run a program, that calls upon "code"/command, from the command prompt, (*.exe) (Robocopy) to copy files from a server, to a group of computers, at a time. We have a classroom environment, at my work, so I have my setup, in a way, that I have a folder, per room. I keep a list of all our addresses (static), for each room, in their perspective folders. We have an update, from our developers, that we need to push to all of the rooms. We need to run a slow push, as to not disturb the production environment. It's proprietary, so we can't use a/any typical solution(s), like Microsoft SCCM. So, I created a script to push to the rooms. while it does work, it's not a smooth operation. I'm not actually the one pushing the update, because of the slow process, of updating. I'm just trying to make a stable smooth-running package, for the person, who is going to be doing it. My code works, outside of the thread, (I) tested it, I know it works.
So how I came my conclusion of knowing, that my code works outside of the thread. (The picture) I followed the same setup, with my code, (A button click event inside of a thread, running the form). Placed the actual working code, (tried, and tested, before making a Thread, for the interface, after completing backend operation code testing.)
("Region Boe's Addition") referring to Boe Prox, (from the link)
In his, he is updating from a command line/powershell window, via a function run inside a thread. I'm running an event from a button, inside of a thread and trying to run a separate thread, for the click event(s). Outside of the thread. The event works fine, but inside, it doesn't work, at all..
Basic Code:

   // Multi thread, thread for the $form, and thread for the event (as per referenced link)
   $var = [PowerShell]::Create().AddScript({ button.Add_Click{
       $var = [PowerShell]::Create().AddScript{<Thread><Robocopy></Thread>}
   })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2025-02-18 03:02:51

需要“启动过程” - 等命令来允许列表框,以在副本之间进行更新,以通过循环中的每个步骤确认安装。

    $choice = $comboBox.SelectedItem
    # $drive = Get-Location
    if(!(Test-Path -PathType Container -Path "L:\$choice"))
    {
#        New-Item -ItemType "container" -Path . -Name $choice
        New-Item -ItemType "Directory" -Path . -Name $choice
    }

#        $folder = $_
        # Where is it being stored at?
        [System.IO.File]::ReadLines("Y:\$choice\IPs.txt") | foreach {
            ping -a -n 2 -w 2000 $_ | Out-Null
            Test-Connection -Count 2 -TimeToLive 2 $_ | Out-Null

            if($?)
            {
               RoboCopy /Log:"L:\$folder\$_.log" $source \\$_\c$\tools
               RoboCopy /Log+:"L:\$folder\$folder-MovementLogs.log" $source \\$_\c$\tools
               Start-Process -Wait "P:\psexec.exe" -ArgumentList "\\$_ -d -e -h -s cmd /c reg import C:\tools\dump.reg"
               # Copy-Item -LiteralPath Y:\* -Destination \\$_\c$\tools
               $listBox.Items.Add($_)
            }
        }

Needed the "Start-Process" -Wait command to allow for the listbox, to be updated in-between copies, to confirm installation, through each step in the loop.

    $choice = $comboBox.SelectedItem
    # $drive = Get-Location
    if(!(Test-Path -PathType Container -Path "L:\$choice"))
    {
#        New-Item -ItemType "container" -Path . -Name $choice
        New-Item -ItemType "Directory" -Path . -Name $choice
    }

#        $folder = $_
        # Where is it being stored at?
        [System.IO.File]::ReadLines("Y:\$choice\IPs.txt") | foreach {
            ping -a -n 2 -w 2000 $_ | Out-Null
            Test-Connection -Count 2 -TimeToLive 2 $_ | Out-Null

            if($?)
            {
               RoboCopy /Log:"L:\$folder\$_.log" $source \\$_\c$\tools
               RoboCopy /Log+:"L:\$folder\$folder-MovementLogs.log" $source \\$_\c$\tools
               Start-Process -Wait "P:\psexec.exe" -ArgumentList "\\$_ -d -e -h -s cmd /c reg import C:\tools\dump.reg"
               # Copy-Item -LiteralPath Y:\* -Destination \\$_\c$\tools
               $listBox.Items.Add($_)
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文