S
S
Stan Marsh2022-04-08 09:56:21
cmd/bat
Stan Marsh, 2022-04-08 09:56:21

How to pack a script into an exe?

Hello. Uniform State Health Information System distributes new certificates without which federal sites do not work. How can I pack a certificate and a bat script into an exe for installation on computers that are not in a domain?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaxKozlov, 2022-04-08
@MaxKozlov

Will a Powershell script work?

# PSv7   $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -AsByteStream), 'InsertLineBreaks')
# PSv5.1 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -Encoding Byte), 'InsertLineBreaks')
$Cert = @"
MIILYgIBAzCCCx4GCSqGSIb3DQEH
.....
.....
.....
1y1lZqkQICB9A=
"@

#LocalMachine
$location = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser

#ls Cert:\CurrentUser\
#ls Cert:\LocalMachine\
$storeName = 'TrustedPublisher'

$store = [System.Security.Cryptography.X509Certificates.X509Store]::new($storeName, $location)
$store.Open('ReadWrite')
[byte[]]$content = [Convert]::FromBase64String($cert)
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($content)
$store.Add($certificate)
$store.Close()

The comments above show how to get the contents of the certificate, which must be substituted in $cert
The comments to $location show what else happens
The comments to $storeName Show where to get it from
Supports both importing a simple certificate and pfx with a key
The password for pfx has not been checked , but in theory it will work if it is specified as new($content, $password )

A
Alexander, 2022-04-08
@Adler_lug

The easiest option is a self-extracting archive (WinRar, 7Zip, 7Zip SFX Mod, etc.). Make it unpacked into a temporary folder, for example, and run from there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question