Closed uffemcev closed 11 months ago
Of course, automatically closing conflicting processes is not always safe. Maybe you can make a new parameter for your script, for example "-ignoreconflicts", so this may be optional.
NICE. I'm so glad you mentioned this. I was having this issue on my computer as well, but not all the time.
I ran it on my computer, but then it caused Windows Terminal to close entirely.
I then ran the same script in PowerShell (not inside of Windows Terminal) and it worked.
See if you can run this and tell me if it works on your end?
irm https://raw.githubusercontent.com/asheroto/winget-install/Test-ForceApplicationShutdown/winget-install.ps1 | iex
Or download the script from here and run: https://github.com/asheroto/winget-install/blob/Test-ForceApplicationShutdown/winget-install.ps1
I found that in pwsh (PowerShell 7) and Terminal it closed itself and failed the install. So I'm not sure if we can do this afterall...
When vclibs or xaml are installing, terminal is conflicted process too, so with ForceApplicationShutdown param it's just closing. Using conhost instead terminal when installing decides problem for me.
Hmm.. so if using conhost.exe
with that parameter it works? But not in Terminal?
Yes it is. The terminal is another conflicting process. I tested your script in conhost, conflicting processes are automatically closed, winget is installed successfully.
Okay so maybe what I could do is let it error out without the use of the parameter, and then in the warning text explain to use conhost
with the -ForceClose argument. Then by using that it would enable the -ForceApplicationShutdown
param. Thoughts?
That restarts the script via conhost, if it was launched in the terminal. Please try it, does it work for you? Tested in powershell 5.1. Source: https://stackoverflow.com/questions/72574412/how-to-distinguish-if-console-program-is-opened-in-powershell-or-in-windows-term
Okay, I will check it out.
While I like that solution, I don't know if we'd be able to use it by default, because IT administrators may be running the script remotely on dozens of computers, and if the process just exits/ends, they will think it didn't work. But as a workaround, I could include text in the warning message that explains to run winget-install with the -UseConhost
param or something. Because then they would be expecting it. Not sure, will look at this a little closer later on today.
Thanks for the info, glad to have someone contributing some good ideas! 😊
Maybe the -ForceClose
and -UseConhost
arguments can be combined into one? It seems they will be useless without each other 😅
Hello, please test it. You can run it like powershell -ExecutionPolicy Bypass .\winget-install.ps1 -Force -ForceClose
. The only problem is that it closes immediately when it's complete or when using -ForceClose
without -Force
. So I added pause at the end for visibility.
Here I'm using a new terminal verification method. It's easier and guarantees proper work:
I also added a -ForceClose
argument check to all Add-AppxPackage
cmdlets:
You can see full script here:
While the pause
at the end would work well for people running the script while on the computer itself, it would not work well for IT administrators who are running the script remotely. Because if someone executes the script from a remote computer, it would just show that the script is running indefinitely. Adding a timeout
is a good workaround to that, though.
I've made some changes to the code, inspired by your example: https://github.com/asheroto/winget-install/blob/Test-ForceApplicationShutdown/winget-install.ps1
as well as this: https://github.com/asheroto/winget-install/blob/7c24d0ffa29b53fc31ad8afe7da6a8029c3552dd/winget-install.ps1#L509
amongst others.
I also made it so that there is a 10 second delay for all exits, except when relaunching with conhost.
Also, on GitHub you can edit the code yourself, then submit a "pull request" for the repo owner to see the proposed changed. If you use VS Code, you can do most of it from within the editor. More info
That script works for me. Please let me know if it works for you too?
Strange, but i still get this error about conflict processes.
winget-install 3.2.0
To check for updates, run winget-install -CheckForUpdate
##########################################
# Downloading & installing x64 VCLibs... #
##########################################
Installing x64 VCLibs...
ПРЕДУПРЕЖДЕНИЕ: Resources modified are in-use. Try closing Windows Terminal / PowerShell / Command Prompt and try again.
ПРЕДУПРЕЖДЕНИЕ: Windows Terminal sometimes has trouble installing winget. If you are using Windows Terminal and the problem persists, run the script with the -ForceClose parameter which will relaunch the script in conhost.exe and
automatically end active processes associated with winget that could interfere with the installation.
Add-AppxPackage : Сбой развертывания с HRESULT: 0x80073D02, Не удалось установить пакет, так как изменяемые им ресурсы в настоящее время используются.
Ошибка 0x80073D02: не удалось выполнить установку, так как требуется закрыть следующие приложения: MicrosoftWindows.Client.WebExperience_423.23500.0.0_x64__cw5n1h2txyewy.
ПРИМЕЧАНИЕ. Чтобы получить дополнительные сведения, найдите [ActivityId] 8efd512e-0103-000a-7283-138f0301da01 в журнале событий или введите в командной строке Get-AppxLog -ActivityID 8efd512e-0103-000a-7283-138f0301da01.
строка:682 знак:102
+ ... ApplicationShutdown } else { Add-AppxPackage $url -ErrorAction Stop }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (http://tlu.dl.d...eFR2Oxftg%3d%3d:String) [Add-AppxPackage], Exception
+ FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand
###################################################
# WARNING! An error occurred during installation! #
###################################################
ПРЕДУПРЕЖДЕНИЕ: If messages above don't help and the problem persists, please read the Troubleshooting section
of the README: https://github.com/asheroto/winget-install#troubleshooting
ПРЕДУПРЕЖДЕНИЕ: Make sure you have the latest version of the script by running this command: winget-install -CheckForUpdate
Waiting for 10 seconds before exiting...
I think it's the reason:
if ($currentProcessModuleName -ne "conhost") {
# Remove -ForceClose from the command line, case-insensitive
$newInvocationLine = $MyInvocation.Line -replace '(?i)-ForceClose', ''
Even when it launches in conhost?
Oh right, because then it won't end the other processes. Okay I'll fix when I get back home later tonight.
Yes, with -ForceClose param
I tested your Get-CurrentProcessModuleName function and i have few problems:
$newInvocationLine = $MyInvocation.Line -replace '(?i)-ForceClose', ''
does not make sense, because after relaunch script will skip if ($ForceClose) { Add-AppxPackage $url -ErrorAction Stop -ForceApplicationShutdown }
and just do { Add-AppxPackage $url -ErrorAction Stop }
On the computer you're getting that on, is it Windows 10 or Windows 11?
Windows 11.
Okay will check it out later today.
https://github.com/asheroto/winget-install/pull/23
It works. For testing, you can launch notepad or store and see how they close while the script is running.
Only problem is that script ignores new commands in cmd or ps1 file if there is a restart in conhost. For example:
This problem is specific, perhaps in this case you can simply leave a warning message.
Any thoughts?
Thanks, merged! Working on moving it to the main branch now.
Hello,
I added a few minor additions. Now if someone uses the $Force
variable rather than -Force
it will relaunch with conhost
as expected. Before it would only relaunch if you specified with -Force
. That way they can use the one-line version.
Can you please retest by downloading the script and running it? I also changed the Write-Output
to a Write-Warning
for the conhost
messages.
Could you please test to confirm it is still working on your end?
The one line method doesn't work right now but I will try to fix it before I do a release...
$Force = $true
$ForceClose = $true
irm https://raw.githubusercontent.com/asheroto/winget-install/Test-ForceApplicationShutdown/winget-install.ps1 | iex
I went ahead and updated the main script. Just didn't publish a release yet. Let me know what you think.
This works great, thanks for your work! Also thanks for adding me as an author! :)
What do you think about this one-liner? I think it's simpler and more convenient. This makes it easier to specify parameters. The url can be made shorter, but you need the path to the file, not a redirect. That's why asheroto.com/winget
does not work in this case.
Github allows you to create your own websites for free based on the repository: https://pages.github.com https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site
Using this you can make a website, for example asheroto.github.io/winget-install/winget-install.ps1
Yeah that works, take a look at the one line on the readme. I wanted to make it easy to remember but can't seem to use the $Force with that line. I'm out an about so haven't figured it out yet.
Github allows you to create your own websites for free based on the repository: https://pages.github.com https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site
I've used that on other repos but with this one I couldn't make a redirector with GitHub pages.
What do you think about this one-liner? I think it's simpler and more convenient. This makes it easier to specify parameters. The url can be made shorter, but you need the path to the file, not a redirect. That's why
asheroto.com/winget
does not work in this case.
Hi again. I discovered that I was wrong. This one-liner is fully functional. Just need to update the code in the link asheroto.com/winget
to 3.2.0 version.
&([ScriptBlock]::Create((irm asheroto.com/winget))) -Force -ForceClose
That URL just goes to the latest release file. I didn't release 3.2.0 officially yet just in the repo source. 😊
That could work. I was thinking something simple that people could easily remember which is why I wanted to get the global vars working.
It's weird because if you run it locally by calling the script, the global vars work. Just not irm/iex.
Maybe something like this? All these options are working.
iex "& { $(iwr -useb 'asheroto.com/winget') } -Force"
iex "& { $(iwr -useb asheroto.com/winget) } -Force"
iex "& { $(iwr asheroto.com/winget) } -Force"
That might work. The idea wasn't just to be short, but to be easy to remember. But might be the best option available for now! Okay cool, I will release it later tonight. Thanks again.
Yep just confirmed there appears to be no way around this. When using Invoke-Expression
it creates a new scope local only to the script block and does not inherit variables from the PowerShell session, therefore what you mentioned is the best method.
Releasing 3.2.0
in a few minutes, closing for now. 😊
What about this part, is it still needed?
# Append parameters if their corresponding variables are $true and not already in the command
if ($Force -and !($command -imatch '\s-Force\b')) { $command += " -Force" }
if ($ForceClose -and !($command -imatch '\s-ForceClose\b')) { $command += " -ForceClose" }
if ($DebugMode -and !($command -imatch '\s-DebugMode\b')) { $command += " -DebugMode" }
It could be used if they are using global variables, like running the script locally rather than irm/iex. So still valid because conhost
cannot see the global variables, so if global vars are used they are converted into parameter versions.
What do you think about the delay in exiting functions, like -Version
which is instant exit versus -UpdateSelf
which has a 10 second delayed exit? Meanwhile -CheckForUpdate
is instant.
I'm thinking we try to avoid having the delay except for the script itself, or for -Force
or -ForceClose
. Thoughts?
Что вы думаете о задержке выхода из функций, например,
-Version
о мгновенном выходе или-UpdateSelf
о выходе с задержкой в 10 секунд? Между тем-CheckForUpdate
мгновенно. Я думаю, мы постараемся избежать задержек, за исключением самого сценария или-Force
или-ForceClose
. Мысли?
This seems reasonable, agree with you. Perhaps in the future it will be possible to implement a more universal method.
Excellent. Thank you. 😊
What You Are Seeing?
Hello again. This time I had a problem during installation: "The modified resources are in use. Try closing Windows Terminal/PowerShell/Command Prompt and try again." This problem affects many other applications that interfere with installation: store, notepad, webexperience, and so on. These processes often hang in the background and have to be closed through the task manager. Restarting the PC does not always help.
Example
ПРЕДУПРЕЖДЕНИЕ: Resources modified are in-use. Try closing Windows Terminal / PowerShell / Command Prompt and try again. ПРЕДУПРЕЖДЕНИЕ: If the problem persists, restart your computer. Add-AppxPackage : Сбой развертывания с HRESULT: 0x80073D02, Не удалось установить пакет, так как изменяемые им ресурсы в настоящее время используются. Ошибка 0x80073D02: не удалось выполнить установку, так как требуется закрыть следующие приложения: Microsoft.WindowsNotepad_11.2307.27.0_x64__8wekyb3d8bbwe MicrosoftWindows.Client.WebExperience_423.23500.0.0_x64__cw5n1h2txyewy. ПРИМЕЧАНИЕ. Чтобы получить дополнительные сведения, найдите [ActivityId] 9eea3719-0014-000a-9100-eb9e1400da01 в журнале событий или введите в командной строке Get-AppxLog -ActivityID 9eea3719-0014-000a-9100-eb9e1400da01. строка:680 знак:9 \+ Add-AppxPackage $url -ErrorAction Stop \+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \+ CategoryInfo : NotSpecified: (http://tlu.dl.d...q2KJ%2fSg%3d%3d:String) [Add-AppxPackage], Exception \+ FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommandI would like to suggest using the "-ForceApplicationShutdown" parameter with all Add-AppxPackage cmdlets to automatically shut down conflicting processes. More about this: https://learn.microsoft.com/en-us/powershell/module/appx/add-appxpackage?view=windowsserver2022-ps#-forceapplicationshutdown
What do you think about this?
System Details
Script verson 3.1.1 Windows 11 22H2 UAC disable Powershell 5.1 Run as administrator