Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

CMD to VBS

- - - - -

  • Please log in to reply
6 replies to this topic

#1
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 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, 15 September 2012 - 06:51 PM.



How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
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 



GunSmokingMan



#3
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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!

#4
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
Are all the EXE in the same folder and you want to separate KB from Net EXE. to install with different intall switches?


GunSmokingMan



#5
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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, 15 September 2012 - 09:55 PM.


#6
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
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 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, S3, Ts, Var
Ln = "--------------------------------------"
S3 = Space(3)
'-> Create Text File On User Desktop
Set Ts = Fso.CreateTextFile(Txt)
Ts.WriteLine vbTab & "Install Application Log"
Ts.WriteLine Ln
Ts.WriteLine S3 & "Script Run Time : " & Time
Ts.WriteLine S3 & "Script Run Date : " & Date
Ts.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").Files
For Each Obj In Fso.GetFolder(".").Files
'-> Filter Out EXE In The Folder
Var = Right(LCase(Obj),3)
If Var = "exe" Then
call Install_Exe(Obj.Name,Obj.Path)
End If
If Var = "msi" Then
call Install_Exe(Obj.Name,Obj.Path)
End If
Next
'-> Sort The Exe
Function Install_Exe(N,P)
If InStr(1,N,"kb",1) Then
Ts.WriteLine S3 & "Install Update : " & N & vbCrLf & _
S3 & "Update Location : " & P & vbCrLf & _
" Install Switches Places Holder"
'-> Code Here For Kb EXE
ElseIf InStr(1,N,"net",1) Then
Ts.WriteLine S3 & "Install Update : " & N & vbCrLf & _
S3 & "Net Fw Location : " & P & vbCrLf & _
" Install Switches Places Holder"
'-> Code Here For Net EXE
Else
'-> Code Here For Misc EXE
Ts.WriteLine S3 & "Application Name : " & N & vbCrLf & _
S3 & "Application Path : " & P & vbCrLf & _
" Install Switches Places Holder"
End If
' Ts.WriteLine Ln
call Architecture(N,P)
End Function
'-> Sort The Msi
Function Install_Msi(N,P)
If InStr(1,N,"kb",1) Then
Ts.WriteLine S3 & "Install Update : " & N & vbCrLf & _
S3 & "Update Location : " & P & vbCrLf & _
" Install Switches Places Holder"
'-> Code Here For Kb MSI
ElseIf InStr(1,N,"net",1) Then
Ts.WriteLine S3 & "Install Update : " & N & vbCrLf & _
S3 & "Net Fw Location : " & P & vbCrLf & _
" Install Switches Places Holder"
'-> Code Here For Net MSI
Else
'-> Code Here For Misc MSI
Ts.WriteLine S3 & "Application Name : " & N & vbCrLf & _
S3 & "Application Path : " & P & vbCrLf & _
" Install Switches Places Holder"
End If
call Architecture(N,P)
End Function
'-> OS Architecture
Function Architecture(N,P)
' Ts.WriteLine Ln
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 Function
'-> End Of Text File
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



GunSmokingMan



#7
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
i try to understand it, it's not easy for now :lol:

Thank you!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN