Jump to content

CMD to VBS


Recommended Posts

Hi guys, as from title, i need a complete conversion of one of my batch file. Could you help me please?

@ECHO OFF
ECHO=_%~1|FINDSTR/X "_ _">NUL 2>&1||GOTO Error
SETLOCAL ENABLEEXTENSIONS
SET "_="
PUSHD %~dp0

:: Title

FOR /R %%A IN (file*.EXE) DO (
SET _=T
ECHO=Installation of %%~nA ...>>install.log
>NUL PING -n 4 127.0.0.1
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (
START "" /MIN /WAIT REG ADD "HKLM\SOFTWARE\Key" /v "Key" /t REG_DWORD /d 20991231 /f)
IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
START "" /MIN /WAIT REG ADD "HKLM\SOFTWARE\Wow6432Node\Key" /v "Key" /t REG_DWORD /d 20991231 /f)
START "" /MIN /WAIT "%%A" /param)

IF NOT DEFINED _ GOTO Error
ECHO=Installation completed.>>install.log
>NUL PING -n 4 127.0.0.1
EXIT
GOTO :EOF

:Error
ECHO=Install error.>>install.log
>NUL PAUSE

Thank you in advance for your help!

Edited by Caml Light
Link to comment
Share on other sites


Here this will list all the EXE in the folder that you place this script in. It will produce a text file

of what exe where process. Try this out, then if it does what you want then we can add the

registry stuff later.

Save As Install_Demo.vbs


'-> Objects For Runtime
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Sys :Set Sys = Act.Environment("System")
Dim Txt :Txt = Act.SpecialFolders("Desktop") & "\Install_Log.txt"
'-> Varibles For Runtime
Dim Ln, Obj, Ts
Ln = "--------------------------------------"
'-> Create Text File On User Desktop
Set Ts = Fso.CreateTextFile(Txt)
Ts.WriteLine vbTab & "Install Application Log"
Ts.WriteLine Ln
Ts.WriteLine Space(3) & "Script Run Time : " & Time
Ts.WriteLine Space(3) & "Script Run Date : " & Date
Ts.WriteLine Space(3) & "Cpu Architecture : " & Sys("PROCESSOR_ARCHITECTURE")
Ts.WriteLine Ln
'-> Path With The Script In Folder = Fso.GetFolder(".").Files
'-> Path To The Folder To Process = Fso.GetFolder("PATH_TO_FOLDER_TO_PROCESS").Files
For Each Obj In Fso.GetFolder(".").Files
'-> Filter Out EXE In The Folder
If Right(LCase(Obj),3) = "exe" Then
Ts.WriteLine Space(3) & "Installation Of : " & Obj.Name
Ts.WriteLine Space(3) & "Application Path : " & Fso.GetFolder(".").Path
Select Case LCase(Sys("PROCESSOR_ARCHITECTURE"))
Case "x86"
'-> Code Here 64 Bit
Ts.WriteLine Space(3) & "Processing 32 Bit Section"
Case "amd64"
'-> Code Here 64 Bit
Ts.WriteLine Space(3) & "Processing 64 Bit Section"
End Select
Ts.WriteLine Ln
End If
Next
' WScript.Echo Ln
Ts.Close
'-> Open Text File
Act.Run(Txt),1,True
'-> Ask To Keep Or Delete File
If MsgBox(_
"Would you like to keep this file? Yes to Keep, No to Delete" & vbCrLf & _
Txt,4132,"Keep Or Delete File") = 7 Then Fso.DeleteFile(Txt), True

Link to comment
Share on other sites

Thank you gunsmokingman! I've a question for you. If i wish to add other commands... for example to install other type of files, is it possible?

Example:

Windows Updates:

KB123456

KB234567

KB345678

...

IE9

.NET 4.0

and so on...

With the bath i can do:

FOR /R %%A IN (KB*.EXE) DO (
...
START "" /MIN /WAIT "%%A" /param1)

FOR /R %%A IN (IE9*.EXE) DO (
...
START "" /MIN /WAIT "%%A" /param2)

FOR /R %%A IN (NET*.EXE) DO (
...
START "" /MIN /WAIT "%%A" /param3)

You're the guru of VBS, so i hope you can solve my problem. :yes:

Thank you for now!

Link to comment
Share on other sites

Exactly! Anyway i also have some MSI files to install. Imagine to do a complete software installation on a PC, starting from all Windows Updates until to the common use applications. What is the easiest way? I'd like to learn VBS, so i hope it's not too difficult to understand.

Edited by Caml Light
Link to comment
Share on other sites

Here try this script it should sort ot KB Net and misc exe or msi

Save As Install_Demo_V2.vbs

'-> This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.'-> This is only posted as example code and meant only to used as such.'-> Objects For RuntimeDim Act :Set Act = CreateObject("Wscript.Shell")Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim Sys :Set Sys = Act.Environment("System")Dim Txt :Txt = Act.SpecialFolders("Desktop") & "\Install_Log.txt"'-> Varibles For RuntimeDim Ln, Obj, S3, Ts, VarLn = "--------------------------------------"S3 = Space(3)'-> Create Text File On User DesktopSet Ts = Fso.CreateTextFile(Txt)Ts.WriteLine vbTab & "Install Application Log"Ts.WriteLine LnTs.WriteLine S3 & "Script Run Time : " & TimeTs.WriteLine S3 & "Script Run Date : " & DateTs.WriteLine S3 & "Cpu Architecture : " & Sys("PROCESSOR_ARCHITECTURE")Ts.WriteLine Ln'-> Path With The Script In Folder = Fso.GetFolder(".").Files'-> Path To The Folder To Process = Fso.GetFolder("PATH_TO_FOLDER_TO_PROCESS").FilesFor Each Obj In Fso.GetFolder(".").Files'-> Filter Out EXE In The FolderVar = Right(LCase(Obj),3)If Var = "exe" Thencall Install_Exe(Obj.Name,Obj.Path)End IfIf Var = "msi" Thencall Install_Exe(Obj.Name,Obj.Path)End IfNext'-> Sort The ExeFunction Install_Exe(N,P)If InStr(1,N,"kb",1) ThenTs.WriteLine S3 & "Install Update : " & N & vbCrLf & _S3 & "Update Location : " & P & vbCrLf & _" Install Switches Places Holder"'-> Code Here For Kb EXEElseIf InStr(1,N,"net",1) ThenTs.WriteLine S3 & "Install Update : " & N & vbCrLf & _S3 & "Net Fw Location : " & P & vbCrLf & _" Install Switches Places Holder"'-> Code Here For Net EXEElse'-> Code Here For Misc EXETs.WriteLine S3 & "Application Name : " & N & vbCrLf & _S3 & "Application Path : " & P & vbCrLf & _" Install Switches Places Holder"End If' Ts.WriteLine Lncall Architecture(N,P)End Function'-> Sort The MsiFunction Install_Msi(N,P)If InStr(1,N,"kb",1) ThenTs.WriteLine S3 & "Install Update : " & N & vbCrLf & _S3 & "Update Location : " & P & vbCrLf & _" Install Switches Places Holder"'-> Code Here For Kb MSIElseIf InStr(1,N,"net",1) ThenTs.WriteLine S3 & "Install Update : " & N & vbCrLf & _S3 & "Net Fw Location : " & P & vbCrLf & _" Install Switches Places Holder"'-> Code Here For Net MSIElse'-> Code Here For Misc MSITs.WriteLine S3 & "Application Name : " & N & vbCrLf & _S3 & "Application Path : " & P & vbCrLf & _" Install Switches Places Holder"End Ifcall Architecture(N,P)End Function'-> OS ArchitectureFunction Architecture(N,P)' Ts.WriteLine LnSelect Case LCase(Sys("PROCESSOR_ARCHITECTURE"))Case "x86"'-> Code Here 64 BitTs.WriteLine Space(3) & "Processing 32 Bit Section"Case "amd64"'-> Code Here 64 BitTs.WriteLine Space(3) & "Processing 64 Bit Section"End SelectTs.WriteLine LnEnd Function'-> End Of Text FileTs.Close'-> Open Text FileAct.Run(Txt),1,True'-> Ask To Keep Or Delete FileIf MsgBox(_"Would you like to keep this file? Yes to Keep, No to Delete" & vbCrLf & _Txt,4132,"Keep Or Delete File") = 7 Then Fso.DeleteFile(Txt), True
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...