Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting .exe file using powershell

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.

like image 846
russianmysticpopOP Avatar asked Feb 08 '23 10:02

russianmysticpopOP


1 Answers

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.

like image 145
Haydentech Avatar answered Feb 15 '23 18:02

Haydentech