/build/static/layout/Breadcrumb_cap_w.png

VB Script for SCCM deployment + Generating mif file.

Hi there,

I need some help on vbscript which install some stuff and then generate a mif file with the status so that SCCM can pick up the mif reporting.

I've done some basic scripting as follows (sorry this is my first script and if I didn't do it correctly, please feel free to comment). The mif file was generated in c:\temp\product.mif but SCCM is picking up the exit code from the vbscript and ignoring the mif file. I am sure that's some stupid mistake... so if anyone come across this, please kindly advice?




' Constants and Variables
Const cProductAction = "Install"
Const Product = "Access_Runtime"
Const Version = "2007"
Const Manufacturer = "Microsoft"
Const TemporaryFolder = 2
ProductPackageName = Manufacturer & "_" & Product & "_" & Version
Dim InstallStatus

'Log File Information
Dim LogFilename
LogFilename = ProductPackageName & "_" & cProductAction & ".log"

' Initilizing Installer
LogToFile " ---------------------------------------------------------------- "
Wscript.StdOut.WriteLine " >> Initializing installer... "
LogToFile "Initializing Installer ..."
'Create shell ect
Set WshShell = CreateObject("WScript.Shell")
Set FileSys = CreateObject("Scripting.FileSystemObject")
'Set Current Working Directory to where script is running from
Dim CWD : CWD = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
wshshell.currentdirectory = CWD
'InstallStep01 'Step01 was removed.
InstallStep02

'Check install results
If InstallStatus = 0 Then
CheckExitCode InstallStatus, "Installation success. InstallStatus: " & InstallStatus, True
Else
CheckExitCode InstallStatus, "Installation failed. InstallStatus: " & InstallStatus, False
End If
wscript.sleep 5000
wscript.quit 0

'-------------------------------------------------------------
'Step 02 - Installing Microsoft Access 2007 Runtime
'-------------------------------------------------------------
Sub InstallStep02()

Wscript.StdOut.Writeline " >> Installing Microsoft Access 2007 Runtime... "
'LogToFile "Installing Microsoft Access 2007 Runtime ..."
Set oExecShell = WshShell.Exec ("c:\windows\system32\msiexec.exe /i AccessRT.msi /l* c:\windows\logs\MicrosoftAccess2007Runtime.log ALLUSER=1 /passive /norestart")
Do While oExecShell.Status = 0: WScript.Sleep 50: Loop
If oExecShell.ExitCode = 3010 Then
errReturn = 0
Else
errReturn = oExecShell.ExitCode
End If
WScript.StdOut.Writeline " >> Exit Code: (" & oExecShell.ExitCode & ")"
LogToFile "Installing Microsoft Access 2007 Runtime | Exit Code: " & errReturn
InstallStatus = errReturn
End Sub



'-------------------------------------------------------------
'Functions - Begin
'-------------------------------------------------------------
Sub LogToFile (LogMessage)
Const ForAppending = 8
Const TemporaryFolder = 2
Dim LogFile, FileSys
Dim TempDir
Set FileSys = CreateObject("Scripting.FileSystemObject")
TempDir = FileSys.GetSpecialFolder(TemporaryFolder)
Set LogFile = FileSys.OpenTextFile("c:\windows\logs\" & LogFilename, ForAppending, True)
LogFile.Writeline (Date & vbTab & Time & vbTab & LogMessage)
LogFile.Close
End Sub

Sub CheckExitCode(ExitCode, ExitMessage, bSuccess)
if ExitCode = 0 then
SMSWriteStatusMIF Manufacturer, Product, Version, "Install success. InstallStatus: " & ExitMessage, bSuccess
LogToFile ExitMessage
LogToFile " ---------------------------------------------------------------- "
wscript.sleep 5000
wscript.quit (ExitCode)
Else
SMSWriteStatusMIF Manufacturer, Product, Version, "FATAL ERROR (" & ExitCode & ") -> " & ExitMessage, bSuccess
LogToFile ExitMessage
LogToFile " ---------------------------------------------------------------- "
wscript.sleep 5000
wscript.quit (ExitCode)
End If
End Sub

Sub SMSWriteStatusMIF(Manufacturer, Product, Version, Results, bSuccess)
' Writing a status MIF for SWDist to return a success or a failure to execute
' Product is the name of the Script and MIF file.
' Results is the status returned
' bSuccess is True/False of success
Const ForWriting = 2
Const TemporaryFolder = 2
Dim mifFile
Dim TempDir
TempDir = FileSys.GetSpecialFolder(TemporaryFolder)
Set mifFile = FileSys.CreateTextFile(TempDir & "\" & ProductPackageName & ".mif", ForWriting)
mifFile.Writeline ("START COMPONENT")
mifFile.Writeline ("NAME = ""WORKSTATION""")
mifFile.Writeline (" START GROUP")
mifFile.Writeline (" NAME = ""ComponentID""")
mifFile.Writeline (" ID = 1")
mifFile.Writeline (" CLASS = ""DMTF|ComponentID|1.0""")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Manufacturer""")
mifFile.Writeline (" ID = 1")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(64)")
mifFile.Writeline (" VALUE = """ & Manufacturer & """")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Product""")
mifFile.Writeline (" ID = 2")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(64)")
mifFile.Writeline (" VALUE = """ & Product & """")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Version""")
mifFile.Writeline (" ID = 3")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(64)")
mifFile.Writeline (" VALUE = """ & Version & """")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Locale""")
mifFile.Writeline (" ID = 4")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(16)")
mifFile.Writeline (" VALUE = ""ENU""")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Serial Number""")
mifFile.Writeline (" ID = 5")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(64)")
mifFile.Writeline (" VALUE = """"")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Installation""")
mifFile.Writeline (" ID = 6")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(64)")
mifFile.Writeline (" VALUE = ""DateTime""")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" END GROUP")
mifFile.Writeline (" START GROUP")
mifFile.Writeline (" NAME = ""InstallStatus""")
mifFile.Writeline (" ID = 2")
mifFile.Writeline (" CLASS = ""MICROSOFT|JOBSTATUS|1.0""")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Status""")
mifFile.Writeline (" ID = 1")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(32)")

' Pass or fail this status mif?
If bSuccess = true then
mifFile.Writeline (" VALUE = ""Success""")
else
mifFile.Writeline (" VALUE = ""Failed""")
End if

mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" START ATTRIBUTE")
mifFile.Writeline (" NAME = ""Description""")
mifFile.Writeline (" ID = 2")
mifFile.Writeline (" ACCESS = READ-ONLY")
mifFile.Writeline (" STORAGE = SPECIFIC")
mifFile.Writeline (" TYPE = STRING(256)")
mifFile.Writeline (" VALUE = """ & Results & """")
mifFile.Writeline (" END ATTRIBUTE")
mifFile.Writeline (" END GROUP")
mifFile.Writeline ("END COMPONENT")
mifFile.Close
End Sub

0 Comments   [ + ] Show comments

Answers (10)

Posted by: anonymous_9363 14 years ago
Red Belt
2
Functionality-wise, I can't tell why the file might be being ignored: I'm remote at the moment and have no means to test.

(sorry this is my first script and if I didn't do it correctly, please feel free to comment).  My comment would, as ever, be that, in common with many beginners, you have ZERO error-trapping. In any programming, you shoudl always, ALWAYS assume that nothing will work.

For example, every time you create an object - no matter if it's the most basic/common object (e.g. FileSystemObject) - your code should check that the object was, in fact, created. If the code creates a file (e.g. a log file), did the file get written? You get the idea...

Also, when using an object a lot, try and get into the habit of specifying it once to save the engine having to go back and refer to its pointer each time by using the 'With...End With' construct. So, instead ofmifFile.Writeline ("START COMPONENT")
mifFile.Writeline ("NAME = ""WORKSTATION""")
mifFile.Writeline (" START GROUP")
'// and so on and so on and so on...
you have:With mifFile
.Writeline ("START COMPONENT")
.Writeline ("NAME = ""WORKSTATION""")
.Writeline (" START GROUP")
End With


Next, use time-savers. NotLogToFile " ---------------------------------------------------------------- " but LogToFile String(33, "-")


Lastly, remember (what purports to be) garbage collection:Set miffile = Nothing and similar for all objects your script creates.
Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
0
Have you set up the status mif as the target in the Package itself yet? I also assume you've checked for the mif and verified that it's populated and formatted properly. I haven't used SCCM extensively (still stuck with SMS 2003) but that's the very first thing that has to be done to get Mif's to report correctly.
Posted by: ahcash 14 years ago
Orange Belt
0
ORIGINAL: Jsaylor

Have you set up the status mif as the target in the Package itself yet? I also assume you've checked for the mif and verified that it's populated and formatted properly. I haven't used SCCM extensively (still stuck with SMS 2003) but that's the very first thing that has to be done to get Mif's to report correctly.


Yes I have. I have setup the package to use the mif file for reporting. The mif file was created and populated correctly and I've checked the format which was created by SMS Installer and they are the same. Problem is that when I used SMS Installer to run the program and report the status with Mif and Package is setup to use mif reporting, it worked fine. Therefore, I am suspecting the script ran but the SCCM is picking up the status of the execution but not the mif reporting.
Posted by: ahcash 14 years ago
Orange Belt
0
Hey Thanks VBScab. Your comments are noted.
Posted by: packgedude 14 years ago
Yellow Belt
0
I can tell you exactly why it doesn't work: http://www.mombu.com/microsoft/sms-admin/t-create-custom-mif-using-vbscript-429194.html

The problem was that my MIF contained blank
fields.

Example: VALUE = ""

Apparently this is a no-no but not documented ANYWHERE. Under normal
circumstances you would not have this problem as MIF generators (such
as the ISMIFCOM.dll included with the SMS 2003 SDK) replace blank
values that are passed with something like ""x\*\*\*x\*\*\*\*\*\*".
Given that I am trying to create my MIF using the OpenTextFile
function in VBSCript I was missing that one bit of information.


Hope this helps!
Posted by: ahcash 14 years ago
Orange Belt
0
hey, packagedude. Thanks for the advice.

I replace the blanks with the follwing..
.Writeline (" START ATTRIBUTE")
.Writeline (" NAME = ""Locale""")
.Writeline (" ID = 4")
.Writeline (" ACCESS = READ-ONLY")
.Writeline (" STORAGE = SPECIFIC")
.Writeline (" TYPE = STRING(16)")
.Writeline (" VALUE = ""NIL""")

I am still getting the same result.

Looking at the execmgr.log
It shows:

Raised Program Started Event for Ad:C0120BA6, Package:C0100360, Program: runmiftest
Program exit code 0
Looking for MIF file to get program status
Script for Package:C0100360, Program: runmiftest succeeded with exit code 0

If it works, it will say something time Mif File Found or something like that if I recall.


The mif was created on c:\temp\miftest.mif
and I've configure the package to look for the miftest.mif

Same results.
Posted by: jpoandl 14 years ago
Yellow Belt
0
ahcash,

Did you ever figure this out? I am running into the same situation where the package status mif is not being reported in SCCM. (The exact same program in SMS 2003 works fine...the mif status is sent back and I see this in the report.)

However, the package does not work in SCCM. The program runs fine..but the mif status is never reported. The MIF file is left in the C:\windows\temp directory.
Posted by: equebal 13 years ago
Yellow Belt
0
This is working fine for me in SCCM. I have made a little bit changes in the script. Functionality wise, only change is that MIF file will be created in Windows directory.

SCCM is not picking the MIF file from Temp directory while it is picking the same from Windows directory.Don't know the reson behind this. Anyway this script serve my purpose.

Please see the below link for more details.

http://equebalahmad.blogspot.com/2010/11/sccm-deployment-generating-mif-file_28.html


Thanks
Posted by: sunnyy31 12 years ago
Yellow Belt
0
Hello

Can somone give me script to create the package and installation program name in SCCM 2007.Thanks in advance..!!
Posted by: kiran1472001 12 years ago
Yellow Belt
0
HI All,
I m new to SCCM, In my case i ve other issue, few clients are not generating MIF file, if i copy them manually it gets deleted.
Scenario Overview

Advertisement pushes definitation update package for MSFCS. with two scripts , one delpoys latest definiation, other updates the registry and MIF value.

Client server communication works fine, i ve tried reinstalling SCCM client, no luck .please help me to get this resolve as it is affecting my compliance report.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ