MSFN Forum: CMD to VBS - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CMD to VBS Rate Topic: -----

#1 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 15 September 2012 - 06:50 PM

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!

This post has been edited by Caml Light: 15 September 2012 - 06:51 PM



#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 15 September 2012 - 08:58 PM

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 



#3 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 15 September 2012 - 09:35 PM

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 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 15 September 2012 - 09:48 PM

Are all the EXE in the same folder and you want to separate KB from Net EXE. to install with different intall switches?

#5 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 15 September 2012 - 09:54 PM

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.

This post has been edited by Caml Light: 15 September 2012 - 09:55 PM


#6 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 15 September 2012 - 10:53 PM

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

Save As Install_Demo_V2.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, 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 









Rename Install_Demo_V2.vbs.txt to Install_Demo_V2.vbs to make active
Attached File  Install_Demo_V2.vbs.txt (3.37K)
Number of downloads: 5

#7 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 15 September 2012 - 11:52 PM

i try to understand it, it's not easy for now :lol:

Thank you!!

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy