Mike Ben

Mike Ben

  • NA
  • 8
  • 7.1k

C# running a BAT file on an embeded VBS script

Sep 2 2011 6:56 PM
Crazy yes but needfull unless there's another way.

I can run the bat file and call the VBS file if it's in the same directory no problem. I can run the VBS file as well from c# but I am trying to find a way to run the bat on an embeded VBS file, aka I import it in as a resource, so that everything is in one exe.

The bat file runs

CD /D %~dp0
IF /I "%~1" NEQ "" CD /D %1
FOR /F "tokens=* delims=" %%A IN ('DIR *.MSI /B /S') DO (
  cscript.exe myfile.vbs "%%A" //Nologo >> Some.txt
  )

Then runs the VBS file and out puts the text file, actualy the bat file outputs the text file.

What it does. It goes out and scans MSI files for all of thier product codes and returns them in a text file. For now anyway. One by one is not an option or I would use other tools.

The end goal. Scan the MSI files accross networked and local drives and return the product codes (GUIDS) and them either I import them into an SQL Server or do a direct update.

The bat file and VBS do the scanning very well but if there's already an example out there that has this or close to this feature set I would be very interested in checking it out.

I also have this that retives One MSI file info and outputs it to a CSV file (or txt) and I am stuck trying to find a way to have it loop through and entire directoy or drive and return all of the MSI files it finds and the properties.


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using WindowsInstaller;
//You will need to add a Reference to WindowsInstaller by selecting references add reference COM and finding Microsoft Windows Installer Object Library in the list

namespace ConsoleApplication1
{
[System.Runtime.InteropServices.ComImport(), System.Runtime.InteropServices.Guid("000C1090-0000-0000-C000-000000000046")]
class Installer { }

class Program
{
static void Main(string[] args)
{
// WHERE THE FILE OUTPUT WILL GO, you can also change it to txt
using (StreamWriter writer = new StreamWriter(@"f:\temp\out.csv"))
{
WindowsInstaller.Installer ins = (WindowsInstaller.Installer)new Installer();
/// WHAT MSI FILE WILL BE CHECKED, IF IT'S NOT THERE IT WON'T WORK
///
Database db = ins.OpenDatabase(@"f:\temp\Minitab 15 English.msi", WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

View vw = db.OpenView("Select `Property`,`Value`,'ProductVersion' FROM `Property`");


vw.Execute(null);
Record rcrd = vw.Fetch();
while (rcrd != null)
{
Console.WriteLine(rcrd.get_StringData(1) + "|" + rcrd.get_StringData(2));

{
Console.SetOut(writer);

}
rcrd = vw.Fetch();
}

vw.Close();

}
}
}

}


Thanks

Micheal

Answers (6)