Plamdi Posted March 23, 2006 Posted March 23, 2006 (edited) This is a VBS program I just wrote, I'd like to get some feedback first. The idea is that for programs that refuse to install without user interaction this program can step in and automate the process. It's not perfect, but it does the job.See post belowSave as oeminst.vbsSee post belowSave as oeminst.iniYou can add as many programs as you like to the .ini, just make sure they're all under their own title in square brackets.You cannot use white space right of the "=", or it will be considered to be part of your expression.OperationTitleXXX and OperationKeysXXX run in chronological order, not necessarily in numerical (or alphabetical) order."@\" at the start of the program name indicates to use the path to the actual vbs file. otherwise specify a complete path, Example: Program=C:\INSTALL\WINAMP295.EXEDo not use quotations around any of the expressions, they are not needed.The "Switches" option is optional, you do not have to use switches with your program for it to work.To use the example I gave you (Winamp 2.95) download WINAMP295.EXE from:http://www.oldversion.com/program.php?n=winampSave in the same directory as OEMINST.VBS and OEMINST.INI, and type:WSCRIPT OEMINST.VBS WINAMPFrom the command prompt.Edit: A quick explination...Winamp installation runs and then displays a window titled "Winamp Setup: Settings" and waits for user input.OEM Installer jumps in, changes some values, for instance "How should Winamp connect to the Internet?" is set to "No internet connection available" to prevent the dialogue box that would pop-up after this step, and some checkboxes are changed. Then it hits Enter and on the next dialogue box, entitled "Winamp Setup: Winamp successfully installed", OEM Installer hits Alt-F4 rather than Enter to prevent Winamp running.This script has excellent Error handling, and will be even more fool proof once I've added the ability to detect if the installation program has unexpectedly ended early and terminate early accordingly.For any other program use the same format in the ini file, and then type:WSCRIPT OEMINST.VBS PROGRAMNAMEFrom the command prompt, where PROGRAMNAME is the name appearing in the square brackets to identify the program you want to install.I'll write some more coherent documentation later.If there are any bugs, or improvements you want to see let me know so I can improve it. It's 95% complete as is right now. Edited March 24, 2006 by Plamdi
mmarable Posted March 23, 2006 Posted March 23, 2006 This is pretty slick. It follows a similar thought process to a script I was working on. I like this.I like what you've done. Real nice work.
Plamdi Posted March 24, 2006 Author Posted March 24, 2006 (edited) Thanks, I'm in my element with VBScript, it has become my favourite programming language - and it's far more powerful then most people realize. Here's an updated version:See post belowThe code will now check (optional) running processes for processes specified in the ini file.Winamp is still an excellent example for this, because first the setup will launch (winamp295.exe), and then winamp.exe will launch (which is actually what is running when we automate the dialogues).So.... the ini file could look like this:See post belowIf neither of the processes is found running then the timeout will begin. This lasts 4-5 seconds before terminating the script. This is to allow for transitional time while neither process is running. The only other feature I intend to add is the ability to terminate a process without using keystrokes. This will be useful because it means that if an installation runs the installed program immediately, then OEM Installer can kill the process before it even has time to fully load. I'm thinking the syntax for this would be:OperationTitle02 =winamp.exeOperationKeys02 =[!]Which could replace:OperationTitle02 =Winamp Setup: Winamp successfully installedOperationKeys02 =%{F4}I chose "[!]" since it would be invalid syntax for sending keystrokes. Of course you probably wouldn't want to use it in this instance with Winamp since you want to give it time to set up the icons and register it's registry settings ... but if it was about to start winamp.exe (instead of already being started) it'd be real handy. Anyhow, work calls... will report in later... Edited March 24, 2006 by Plamdi
Plamdi Posted March 25, 2006 Author Posted March 25, 2006 (edited) There were three small bugs in my previous code, here is the bug-free code.Option ExplicitOn Error Resume NextIf Wscript.Arguments.Count<>1 Then WScript.Quit(0)Dim WshShell,i,j,ini,fso,f,s,s_,p,m1,m2,t,inst(),pCheck,pNames()Dim objWMIService,objProcess,colProcess,ProgName,ProgFlagsSet WshShell=WScript.CreateObject("WScript.Shell")Set fso=CreateObject("Scripting.FileSystemObject")Set objWMIService=GetObject("winmgmts:" _ &"{impersonationLevel=impersonate}!\\.\root\cimv2")ini=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)+_ InStrRev(WScript.ScriptName,".")-Len(WScript.ScriptName))&"INI"p=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-_ Len(WScript.ScriptName))ProgFlags="":pCheck=FalseIf Not fso.fileexists(ini) Then Set WshShell=Nothing:WScript.Quit(0)Set f=fso.OpenTextFile(ini,1)s=VbCrLf&f.ReadAll&VbCrLf&VbCrLff.Closet=VbCrLf&"["&UCase(Wscript.Arguments(0))&"]"m1=InStr(UCase(s),t)+Len(t)If m1=0 Then Set WshShell=Nothing:WScript.Quit(0)m2=InStr(m1+3,s,VbCrLf&"[")If m2=0 Then m2=Len(s)s=Mid(s,m1,m2-m1)&VbCrLfs_=Ucase(s)m1=InStr(s_,VbCrLf&"PROGRAM")If m1=0 Then Set WshShell=Nothing:WScript.Quit(0)m1=InStr(m1+3,s,"=")+1If m1=0 Then Set WshShell=Nothing:WScript.Quit(0)m2=InStr(m1,s,VbCrLf)ProgName=Mid(s,m1,m2-m1)If Left(ProgName,2)="@\" Then ProgName=p&Right(ProgName,Len(ProgName)-2)If Not fso.fileexists(ProgName) Then Set WshShell=Nothing:WScript.Quit(0)Set fso=Nothingm1=InStr(s_,VbCrLf&"SWITCHES")If m1<>0 Then m1=InStr(m1+3,s,"=")+1 If m1<>0 Then m2=InStr(m1,s,VbCrLf) ProgFlags=" "&Mid(s,m1,m2-m1) End IfEnd Ifm1=1:i=-2:m2=0Do m2=InStr(m2+1,s_,VbCrLf&"PROCESSCHECK") If m2=0 Then m1=0 i=i+1Loop While m1If i<>-1 Then j=i:pCheck=True ReDim pNames(i) m1=1:m2=1 For i=0 To j m1=InStr(m1,s_,VbCrLf&"PROCESSCHECK") m1=InStr(m1+3,s,"=")+1 If m1=0 Then Set WshShell=Nothing:WScript.Quit(0) t=InStr(m1+3,s,VbCrLf)+1 pNames(i)=Mid(s,m1,t-m1-1) Next'iEnd Ifm1=1:i=-2:m2=0Do m2=InStr(m2+1,s_,VbCrLf&"OPERATIONTITLE") If m2=0 Then m1=0 i=i+1Loop While m1m1=1:j=-2:m2=0Do m2=InStr(m2+1,s_,VbCrLf&"OPERATIONKEYS") If m2=0 Then m1=0 j=j+1Loop While m1If i<0 OR i<>j Then Set WshShell=Nothing:WScript.Quit(0)ReDim inst(i,1)m1=1:m2=1For i=0 To j m1=InStr(m1,s_,VbCrLf&"OPERATIONTITLE") m1=InStr(m1+3,s,"=")+1 If m1=0 Then Set WshShell=Nothing:WScript.Quit(0) t=InStr(m1+3,s,VbCrLf)+1 inst(i,0)=Mid(s,m1,t-m1-1) m2=InStr(m2,s_,VbCrLf&"OPERATIONKEYS") m2=InStr(m2+3,s,"=")+1 If m2=0 Then Set WshShell=Nothing:WScript.Quit(0) t=InStr(m2,s,VbCrLf)+1 inst(i,1)=Mid(s,m2,t-m2-1)Next'ij=0:s="":s_=""WshShell.Run(""""&ProgName&""""&ProgFlags)For i=0 To UBound(inst) If inst(i,1)="[!]" Then Set colProcess=Nothing Set colProcess=objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = """&inst(i,0)&"""") For Each objProcess in colProcess objProcess.Terminate() Next Else Do until WshShell.AppActivate(inst(i,0)) WScript.Sleep 300 If pCheck Then If CheckForProcess() Then j=0 Else j=j+1 If j=14 Then Set WshShell=Nothing:WScript.Quit(1) End If End If Loop WshShell.SendKeys inst(i,1) End IfNext'iSet WshShell=NothingWScript.Quit(1)Function CheckForProcess() CheckForProcess=False For Each t in pNames Set colProcess=Nothing Set colProcess=objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = """&t&"""") For Each objProcess in colProcess CheckForProcess=True Exit Function Next NextEnd FunctionSave as OEMINST.VBS[Winamp]Program =@\WINA295.EXESwitches =/SProcessCheck01 =WINA295.EXEProcessCheck02 =WINAMP.EXEOperationTitle01 =Winamp Setup: SettingsOperationKeys01 ={TAB}{TAB}N{TAB} {UP} {UP}{UP}{UP} ~OperationTitle02 =Winamp Setup: Winamp successfully installedOperationKeys02 =%{F4}Save as OEMINST.INIThe ability to terminate processes has been added, syntax is:OperationTitle=notepad.exeOperationKeys=[!]That would be suitable for killing notepad if that's launched at the end of installation (keep in mind EVERY instance of notepad running will be ended).Commented source code and documentation will come next. Enjoy.Note:Some dialogues don't actually get focus when WshShell.AppActivate is run. To test any automated installation always alt-tab to give another application focus as soon as you've run oeminstaller. This is not an error in OEM Installer, but rather a limitation of WScript. If the automation fails then do this:[CloneDVD]Program =@\SetupCloneDVD2Slysoft.exeSwitches =/SProcessCheck =SetupCloneDVD2Slysoft.exeOperationTitle =CloneDVD2 SetupOperationKeys =N(OLD) For some reason WshShell.AppActivate("CloneDVD2 Setup") will return true, but not pass focus on to the dialogue. You can test this. [CloneDVD]Program =@\SetupCloneDVD2Slysoft.exeSwitches =/SProcessCheck =SetupCloneDVD2Slysoft.exeOperationTitle01 =CloneDVD2 SetupOperationKeys01 =%{TAB}OperationTitle02 =SetupCloneDVD2Slysoft.exeOperationKeys02 =[!](NEW) This will cause OEM Installer to wait until the final dialogue is displayed, hit Alt-Tab (a non-invasive command, you can put whatever you like) - and then terminate the SetupCloneDVD2Slysoft.exe process. Edited March 25, 2006 by Plamdi
Plamdi Posted April 5, 2006 Author Posted April 5, 2006 Final Version. You may download it, extract it and use it to your will. Source code is fully commented.Features:The ability to automate nearly any installation.Excellent error-handling.Program can detect if the installation has abnormally terminated and quit early if necessary.Configuration file may be compressed with makecab for that professional touch.Benefits:Open-source, freeware.Universal - configuration file can hold as many programs and commands as needed.Simple configuration, and command-line usage.The Bottom Line:It's a script that I wrote over 3 days. Many other people have used VBS on this forum to automate installations for single programs only - this can be used for all those programs. Many forum members also wrote linear code which doesn't allow for the program to accurately wait for a dialogue window to appear - which is what oem installer is capable of.Download now, and enjoy. Do not use the code posted in the previous post as it's out of date (however it has no errors in it so I feel free leaving it up).oeminstaller.rar
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now