问题描述
我们使用的软件具有内置同步机制,可检查本地文件夹是否与位于服务器上的源文件夹相同。该软件将仅基于本地文件夹中的文件工作。这样,内容只能安装在 1 个位置,而不是单独安装在每个工作站上。
问题是应用程序在同步文件时不会锁定自己,并且必须在启动同步过程之前打开应用程序。
现在每个人都在家工作,同步过程需要很多时间。而且你看不出它是只是检查,还是复制。如果用户仍然决定使用该应用程序,该应用程序将崩溃,在此过程中,文件可能最终损坏。
我还可以配置服务器文件夹与本地文件夹相同。这样它根本不会同步。所以,我想使用一个启动脚本,它的工作原理与应用程序本身相同,但用户不需要先打开应用程序。我想确保脚本在它复制的每个文件之后检查用户是否开始使用该应用程序以及它是否会连同消息框一起终止该应用程序,用户应该稍后再试。
我被卡住了,因为我不知道某个位置有多少个子文件夹,也不知道如何确保将子文件夹及其内容复制到目标位置。
这就是我所拥有的:
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Destination = "C:\Application\"
$Source = "J:\"
$SourceFoldersTocopy = gci $Source -recurse | where-Object {$_.PsIsContainer} | Select Name
ForEach ($file in $SourceFoldersTocopy){
$ApplicationIsRunning = Get-Process cwin64 -ErrorAction SilentlyContinue
$SourceFolder = Join-Path -Path $Source -Childpath $file.Name -Resolve
$DestinationSubfolder = Join-Path -path $Destination -Childpath $file.Name -ErrorAction SilentlyContinue -Resolve
while ($ApplicationIsRunning){
Stop-Process $ApplicationIsRunning -Force
$oReturn=[System.Windows.Forms.MessageBox]::Show("This is a message from your Application Manager. As a workaround for the long synchronizations,a background script is running. This script will detect automatically whether server files are missing. So,when you get this prompt,vital @R_417_4045@ion
is being copied and therefore the document has been closed. Once the script finishes,you are free to use it again.
In the meantime,please don't restart your computer")
If (!($DestinationSubfolder)){
copy-item -path $SourceFolder -Destination $Destination -Recurse -verbose
}
}
If (!($DestinationSubfolder)){
copy-item -path $SourceFolder -Destination $Destination -Recurse -verbose
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)