Extracting .exe file using powershell
Asked Answered
U

3

5

I am trying to extract .exe file using powershell without any other tools.

I tried to use System.IO.Compression.ZipFile, but that works only for .zip files..

$zip_file = Get-Item ("C:\Users\00WORK\gs\gs.exe")
$destination = Get-Item ("C:\Users\tuna")
[System.IO.Compression.ZipFile]::ExtractToDirectory($zip_file,$destination)

Also tried this, but without any success

start-process C:\Users\Downloads\gs.exe -Argumentlist "/a"

Tried also this but once again without any succes

$shell = new-object -com shell.application
$zip = $shell.NameSpace(“C:\Users\00WORK\gs\gs.exe”)
foreach($item in $zip.items())
{
$shell.Namespace(“C:\Users\tuna”).copyhere($item)
}

Thanks for help.

Urga answered 23/3, 2016 at 8:49 Comment(1)
what is gs.exe? Is this a self-extracting zip file? I would think you could extract the contents by running it.Meryl
H
4

If you have tried

start-process C:\Setup.exe -Argumentlist "/a"

Then it is not possible using powershell, this command is completely dependant on how the file was packaged, if all else fails I personally would use a utility like 7-Zip, but as you said you would not like to use utilities.

Hat answered 23/3, 2016 at 10:22 Comment(0)
G
4

I had this same problem recently as well. Dewi's answer would not have worked for me. I solved it like this:

mv gs.exe gs.zip
Expand-Archive -Path gs.zip

Optionally, you can rename it back when you're done, if you need the exe for other purposes.

mv gs.zip gs.exe

Note that you'll need PowerShell 5 or newer to use Expand-Archive. Thankfully, this is available as a download all the way back to Win 7 as Microsoft KB3191566.

Gans answered 27/3, 2018 at 21:40 Comment(0)
A
2

Yeah well powershell doesn't recognize all compression algorithms. I am trying to do this with an HP driver pack file which comes in a self extracting .exe file. Even if you change the filename to a .zip it will not extract the files and instead throws a New-Object exception error.

Arcograph answered 11/10, 2019 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.