Universal Silent Switch Finder - USSF() - For Use With Installers

Post your working scripts, libraries and tools for AHK v1.1 and older
0x00
Posts: 89
Joined: 22 Jan 2019, 13:12

Universal Silent Switch Finder - USSF() - For Use With Installers

23 Feb 2019, 00:17

There was an application by the same name(USSF.exe) which was a gui application to find silent installation param's,it was poorly written & was bloated by any standard so...

I wrote this so it's Modular & Extensible,without reinventing any wheels. It uses the strings utility from sysinternals which must be placed in the system path or script directory.
My attempts at a native solution to extracting strings from binary in ahk were impractically too slow,so using something that's free & from Microsoft.

I Use It To Create Installation Packages,where i just plop all installers in a folder & perform Silent Installation Of All in folder...

https://download.sysinternals.com/files/Strings.zip


Cheers.

Code: Select all

CoordMode, ToolTip, Screen
installersDirectory = D:\@Applications.Core

Loop %installersDirectory%\*.*
	If ( thisSwitch := UniversalSilentSwitchFinder(A_LoopFileFullPath) )
		ToolTip % installers .= thisSwitch "`n",0,50
MsgBox


UniversalSilentSwitchFinder(filePath,debugMode:=false){
	SplitPath, filePath, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
	If (OutExtension = "reg"){
		silentSwitchParam = regedit.exe /s "%filePath%"	;Registry Data File"
	}Else If (OutExtension = "inf"){
		silentSwitchParam = rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 "%filePath%"	;Information or Setup File"
	}Else If (OutExtension = "msi"){
		silentSwitchParam = msiexec /i "%filePath%" ALLUSERS=1 /qn /norestart	;Windows installer (msiexec)"
	}Else If (OutExtension = "exe"){
		silentSwitchParam := (thisSwitch:=ExeInstallerIs(filePath)) ? filePath . thisSwitch : ""
	}
	Return silentSwitchParam
}

ExeInstallerIs(filePath){
	If RunCommand("strings /accepteula """ filePath """ |findstr /i ""nsis""|findstr /i ""nullsoft""")
		Return " /S"	;NSIS	- NSIS allows /SD (no message boxes at all)
	If RunCommand("strings /accepteula """ filePath """ |findstr /i ""inno""|findstr /v /i ""< window""")
		Return " /VERYSILENT /SUPPRESSMSGBOXES /NORESTART"	;InnoSetup
	If RunCommand("strings /accepteula """ filePath """ |findstr /i ""7-Zip 7zS.sfx.exe""")
		Return " -gm2"	;Gnu SelfExtracting 7z Archive
	If RunCommand("strings /accepteula """ filePath """ |findstr /i ""RarSfx WinRAR""")
		Return " -s"	;WinRAR Self Extracting Archive
	;InstallShield
}

RunCommand(command) {
	DetectHiddenWindows, On
	Run, % ComSpec,, Hide, vPID
	WinWait, % "ahk_pid " vPID
	DllCall("kernel32\AttachConsole", UInt,vPID),oShell := ComObjCreate("WScript.Shell"),oExec := oShell.Exec(ComSpec " /c " command ),vStdOut := ""
	while !oExec.StdOut.AtEndOfStream
		vStdOut := oExec.StdOut.ReadAll()
	DllCall("kernel32\FreeConsole")
	Process, Close, % vPID
	Return vStdOut
}


It's only compatible with installers i happen to have,so please post your updated versions if you happen to encounter a different installer with different switches,..., It should be intuitive how to update the function,i hope,It's quiet a simple function.


Cheers.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Universal Silent Switch Finder - USSF() - For Use With Installers

23 Feb 2019, 20:41

This is quite interesting and thanks for sharing. However, I'm intrigued by your comments that AHK was too slow for extracting strings from binaries. I've seem to remember various scripts on the forum, where it was doing such, though I can't account for how fast they were. Perhaps a DllCall of some type might work.

There is a program called Strings2, based off of Sysinternals Strings, where you can get the source code. https://github.com/glmcdona/strings2 How it compares to the original, will take a bit of testing.

It appears that Sysinternal tools originally came with source code, but Microsoft removed such when they bought the company. It might be possible to get the source code for a much older version of Strings (pre Microsoft buy) to see how it works.
0x00
Posts: 89
Joined: 22 Jan 2019, 13:12

Re: Universal Silent Switch Finder - USSF() - For Use With Installers

24 Feb 2019, 06:53

Hi, i too actually do prefer strings2 as it can dump strings from memory as well, but i figured people would be more likely already have the Sysinternals strings anyhow,and it's signed by Microsoft was well so,..., some people are sticklers for that sort of thing.

And as for the speed,i was a tad surprised as well, ahk is usually fast enough for my needs. But I've posted my attempt: Attempting Sysinternals Strings.exe writeup in Native Ahk... Too Slow.. If it comes to nothing,I'll certainly Rewrite it with DllCalls.

Cheers.
TeamVeg
Posts: 1
Joined: 06 Feb 2020, 15:42

Re: Universal Silent Switch Finder - USSF() - For Use With Installers

06 Feb 2020, 15:57

Hello,

I landed upon this looking for a way to expose all command line arguments of an .exe file which I cannot locate any documentation for. Unfortunately -h, --help, /? do not work.

Is the aim of this tool to be an autoinstaller of some type, rather than a reporter of the command line switches which is what I am after?
I ask because I see in your code it includes entries such as:

Code: Select all

If (OutExtension = "reg"){
		silentSwitchParam = regedit.exe /s "%filePath%"	;Registry Data File"
I am definitely not wishing to silently import items to the registry without more knowledge.
Apologies in advance for the questions, I have not tested your code.
Instead I figured it would be easier to ask first.

Thank you
0x00
Posts: 89
Joined: 22 Jan 2019, 13:12

Re: Universal Silent Switch Finder - USSF() - For Use With Installers

18 Feb 2020, 03:57

TeamVeg wrote:
06 Feb 2020, 15:57
Hello,

I landed upon this looking for a way to expose all command line arguments of an .exe file which I cannot locate any documentation for. Unfortunately -h, --help, /? do not work.

Is the aim of this tool to be an autoinstaller of some type, rather than a reporter of the command line switches which is what I am after?
Yes, it attempts to find what type of installer you're passed to the function & return the supported parameters for the installer in question, i pretty much use it to auto-install all installers in a folder for instance.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 102 guests