Using WfWI object in vbscripts
I am new to writing vbscript and was wondering if anyone knows of a good resource that can help in making changes to the wsi via a vbscript or the Macro function in WfWI?
I have been trying to do the following:
Any help would be greatly appreciated.
Mike -
I have been trying to do the following:
I am trying to change the SourcePath column in the WiseSourcepath table, from [ProgramFiles] to a relative path ".\Source\". My directory structure is like this:
Project Folder
\Dev
Project.wsi (file here)
\Source file(s) here
I can read the rows in make the modification but then it seems to write but the wsi is not changed.
Function ProjectWSP()
Set tblWSrcPath = objWfWI.WTables("WiseSourcePath")
Set rowwsp= tblwsrcpath.NewWRow
rowwsp.WColumns("File_").Data="TESTFILE"
rowwsp.WColumns("SourcePath").Data="TESTPATH"
rowwsp.WColumns("Date").Data=1062129600
rowwsp.WColumns("Attributes").Data=0
tblWSrcPath.WRows.AddRow rowwsp
Exit Function
For Each rowWsp In tblWSrcPath.WRows
If Left(rowWsp.wcolumns("SourcePath").Data,14)="[ProgramFiles]" Then
tTest=".\Source\" & Right(rowWsp.wcolumns("SourcePath").Data,Len(rowWsp.wcolumns("SourcePath").Data)-14)
rowWsp.wcolumns("SourcePath").Data=tTest
' MsgBox rowWsp.wcolumns("SourcePath").Data
End If
Next
Any help would be greatly appreciated.
Mike -
0 Comments
[ + ] Show comments
Answers (22)
Please log in to answer
Posted by:
MPA2012
16 years ago
AngleID,
Can you tell me how I would run a query against AD in the Wise Macro? I have it as a function in my vbscript but when I past it in the macro it gives my a message "Syntax error" Source line: Function GetpackagerName(StrUserName).
I have also added my code.
Can you tell me how I would run a query against AD in the Wise Macro? I have it as a function in my vbscript but when I past it in the macro it gives my a message "Syntax error" Source line: Function GetpackagerName(StrUserName).
I have also added my code.
Sub AddSummaryinfo
'This adds DTE information to the MSI Summary Information.
Dim objShl
Dim arAdinfo, strUserName, strContact, strChkValue, strAuthor, strAuthorDif, strResponse
Dim strConsultant, rowSumry
Set objShl = CreateObject("WScript.Shell")
strChkValue = 0
strAuthorDif = 0
strConsultant =0
strUserName = objShl.ExpandEnvironmentStrings("%USERNAME%")
If strUserName = "mpNTID" Then
strResponse = MsgBox("Are you packaging for your self?",4 ,"Helping Packagers")
If strResponse <> 6 Then 'User select "yes"
strResponse = InputBox("Enter the Number next to your name:" &_
vbCrLf & "1 - " & "LName, Alex C." &_
vbCrLf & "2 - " & "LName, Tom C." &_
vbCrLf & "3 - " & "LName, Todd E." &_
vbCrLf & "4 - " & "LName, Jonathan R." &_
vbCrLf & "5 - " & "LName, John R.")
Select Case strResponse
Case "1"
strUserName = "acNTID"
Case "2"
strUserName = "tcNTID"
Case "3"
strUserName = "teNTID"
Case "4"
strUserName = "jrNTID"
Case "5"
strUserName = "jrNTID"
End Select
End If
'Add consultanst USERID here for packaging
ElseIf strUserName = "rcNTID" then
strConsultant = 1
ElseIf strUserName = "lbNTID" then
strConsultant = 1
End If
Set arAdinfo=GetPackagerName(strUserName)
Set tblSummary = WTables("Summary")
For Each rowSumry In tblSummary.WRows
If rowSumry("Field") = ("Comments") Then
If InStr(1, rowSumry("Value"), "ontact:")>1 Then
strChkValue = 1
End If
End If
Next
If strChkValue = 0 Then
For Each rowSumry In tblSummary.WRows
If rowSumry("Field") = ("Title") Then
rowSumry("Value") = strPkgFileName
ElseIf rowSumry("Field") = ("Author") Then
rowSumry("Value") = arAdinfo("Name")
ElseIf rowSumry("Field") = ("Comments") Then
rowSumry("Value") = "Contact: Desketop Engineer -" &_
vbCrLf & arAdinfo("Email") &_
vbCrLf & "x-" & arAdinfo("Phone")
End If
Next
Else
For Each rowSumry In tblSummary.WRows
If rowSumry("Field") = ("Title") Then
rowSumry("Value") = strPkgFileName
ElseIf rowSumry("Field") = ("Author") Then
strAuthor = rowSumry("Value")
If strAuthor = arAdinfo("Name") Then 'Checks that pacakger Name is different
rowSumry("Value") = arAdinfo("Name")
Else
strResponse = MsgBox("Would you like to change the current Packager Info(" & strAuthor & ")to your Info?", 4, "Pacakger Info.")
If strResponse = 6 Then 'User selected "Yes".
strAuthorDif = 1
rowSumry("Value") = arAdinfo("Name")
End If
End If
ElseIf rowSumry("Field") = ("Comments") Then
If strAuthorDif = 1 Then
rowSumry("Value") = "Contact: Desketop Engineer -" &_
vbCrLf & arAdinfo("Email") &_
vbCrLf & "x-" & arAdinfo("Phone")
ElseIf strConsultant = 1 Then
rowSumry("Value") = "Contact: Desketop Engineer -" &_
vbCrLf & "MPNTID@xxx.com" &_
vbCrLf & "x-" & "nnnn" &_
vbCrLf & "Packaged by a consultant"
End If
End If
Next
End If
MsgBox arAdinfo("Name")
MsgBox arAdinfo("Phone")
MsgBox arAdinfo("Email")
'//////////////////////////////////////////////////////////
'Get Packagers Information from AD
Function GetPackagerName(strUserName)
Dim objConn, objRS, objUser, strTelephoneNumber, aADSInfo, adsroot, ads, sSQL
Set aADSInfo=CreateObject("Scripting.Dictionary")
Set ADS = GetObject("LDAP://rootDSE")
adsroot=ads.Get("defaultNamingContext")
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "ADs Provider"
sSql = "<LDAP://" & adsroot & ">;(samaccountname=" & strUserName & ");distinguishedname,ADsPath;subtree"
'MsgBox ssql
Set objRS = objConn.Execute(sSQL)
Set objUser = GetObject(objRS("adsPath")) ' or objRS.Fields(0) - same thing
aADSInfo("Name")= objUser.DisplayName
aADSInfo("Phone")= objUser.telephoneNumber
aADSInfo("Email")= objUser.mail
Set GetPackagerName=aADSInfo
Set objUser = Nothing
Set objRS = Nothing
Set objConn = Nothing
End Function
End Sub
Posted by:
AngelD
16 years ago
Posted by:
MPA2012
16 years ago
I tried that, but it seems the Wise Macro Editor will not let you do things outside the sub routine.
Can I make a call to another sub routine within a sub routine? That is what I am going to test next.
Thank you, for all your help.
I am trying to learn how to use the Macro Editor. Is there any tool that you use that is better?
Can I make a call to another sub routine within a sub routine? That is what I am going to test next.
Thank you, for all your help.
I am trying to learn how to use the Macro Editor. Is there any tool that you use that is better?
Posted by:
Robo Scripter
16 years ago
I make great use of the Wise Macro editer. Converting the WiseSourcePath in the wsi is one of my manual macros.
Please feel free to use it.
Please feel free to use it.
Sub ConvertWiseSourcePathPropertiesRelative
Dim tblWiseSourcePath : Set tblWiseSourcePath = Wtables("WiseSourcePath")
Dim rowSource
For Each rowSource In tblWiseSourcePath.WRows ' process each row in WiseSourcePath table
If instr(rowSource("SourcePath"), "[ProgramFiles]") <> 0 Then
rowSource("SourcePath") = Replace(rowSource("SourcePath"), "[ProgramFiles]", ".\Source\Program Files\")
End If
If instr(rowSource("SourcePath"), "[WindowsFolder]") <> 0 Then
rowSource("SourcePath") = Replace(rowSource("SourcePath"), "[WindowsFolder]", ".\Source\Windows\")
End If
If instr(rowSource("SourcePath"), "[SystemFolder]") <> 0 Then
rowSource("SourcePath") = Replace(rowSource("SourcePath"), "[SystemFolder]", ".\Source\Windows\System32\")
End If
Next
Set tblWiseSourcePath = Nothing
msgbox "Process Copleted", vbOkonly, "Convert WiseSource Path Properties Relative"
End Sub
Posted by:
MPA2012
16 years ago
Robert,
I have that sub routine already, but thank you.
I need to figure out how to Run my AD function in Macro Editor. Can you help me with that. I hear you are pretty savvy. We have some mutual packaging friends, Rick Daniels and Randy Conrad.
P.S. Randy and I working together on this project.
Thanks,
I have that sub routine already, but thank you.
I need to figure out how to Run my AD function in Macro Editor. Can you help me with that. I hear you are pretty savvy. We have some mutual packaging friends, Rick Daniels and Randy Conrad.
P.S. Randy and I working together on this project.
Thanks,
Posted by:
jmcfadyen
16 years ago
just thinking a laterally a little here but wouldn't it be easier and cleaner to use a lookup table in your macro.
ie
select case strUserName
case "userA"
strPhone = xxxx
strEmail = xxxx
strNam = xxxx
case "userB"
strPhone = xxxx
strEmail = xxxx
strNam = xxxx
end select
if you insist on heading down the AD lookup path you are better served using the name.translate function which will convert a userid id into an Adspath with the ADoDB SQL query.
ie
select case strUserName
case "userA"
strPhone = xxxx
strEmail = xxxx
strNam = xxxx
case "userB"
strPhone = xxxx
strEmail = xxxx
strNam = xxxx
end select
if you insist on heading down the AD lookup path you are better served using the name.translate function which will convert a userid id into an Adspath with the ADoDB SQL query.
Posted by:
Robo Scripter
16 years ago
Greetings Mike.
Tell the guys hello.
AngelD was correct in that the only thing wrong with the Sub is the nested function.
Do this:
1. Open the Macro editor to edit the "AddSummaryinfo" macro.
2. Cut the "GetPackagerName" function from the Sub.
3. On the macro editor secondary toolbar select the "Full Mode View" button.
4. Change the far right pull down to "(Declarations)" section.
5. Paste the function above the " 'End of (Declarations) " text.
6. Save and run the macro.
It seems to work fine for me
Without making any other changes it populates the Author field as well as populating the Comments field with the required data.
[8D] Nice I think I will hold on to it if you don't mind. [;)]
Tell the guys hello.
AngelD was correct in that the only thing wrong with the Sub is the nested function.
Do this:
1. Open the Macro editor to edit the "AddSummaryinfo" macro.
2. Cut the "GetPackagerName" function from the Sub.
3. On the macro editor secondary toolbar select the "Full Mode View" button.
4. Change the far right pull down to "(Declarations)" section.
5. Paste the function above the " 'End of (Declarations) " text.
6. Save and run the macro.
It seems to work fine for me
Without making any other changes it populates the Author field as well as populating the Comments field with the required data.
[8D] Nice I think I will hold on to it if you don't mind. [;)]
Posted by:
MPA2012
16 years ago
Posted by:
MPA2012
16 years ago
Here is another issue:
In my vbscript I was passing the Wise project variables to set some fields, like Summary table/Title to [ProjectName].
Do you know if it is as simple as adding the brackets and variable or do you have to declare a call or stay with my vbscript and populate the property table with these values?
Example:
Create a tool in WPS Tool to run WScript.exe
Create a Task (Company Branding) that uses the WScript.exe tool.
Create the following Options to run my vbscript and pass the switches to the (vbs) script with the following options.
My vbs file checks these switches and sets variables accordenly. (/PKFN="Adobe_AcrobatPro_8.0_B01" SETS strPkgFileName = "Adobe_AcrobatPro_8.0_B01")
In my vbscript I was passing the Wise project variables to set some fields, like Summary table/Title to [ProjectName].
Do you know if it is as simple as adding the brackets and variable or do you have to declare a call or stay with my vbscript and populate the property table with these values?
Example:
Create a tool in WPS Tool to run WScript.exe
Create a Task (Company Branding) that uses the WScript.exe tool.
Create the following Options to run my vbscript and pass the switches to the (vbs) script with the following options.
Task Name: Company Branding
Tool: WScript.exe
Option: MST Branding
Name: MST Branding
"[Sharepoint]\VBScripts\Branding\Add_Branding_2.0.vbs" /PJDR="[ProjectDir]" /PDV="[ProductVendor]" /PKFN="[FileName]" /PJN="[ProjectName]" /MSTB
My vbs file checks these switches and sets variables accordenly. (/PKFN="Adobe_AcrobatPro_8.0_B01" SETS strPkgFileName = "Adobe_AcrobatPro_8.0_B01")
Posted by:
AngelD
16 years ago
I would do like this:
Added a task
Type: Other EXE
EXE: C:\WINDOWS\system32\wscript.exe
Option: "[Sharepoint]\VBScripts\Branding\Add_Branding_2.0.vbs" /PJDR:"[ProjectDir]" /PDV:"[ProductVendor]" /PKFN:"[FileName]" /PJN:"[ProjectName]"
From the vbscript I would have something like this to fetch the arguments for usage when opening/modifying the project file:
Added a task
Type: Other EXE
EXE: C:\WINDOWS\system32\wscript.exe
Option: "[Sharepoint]\VBScripts\Branding\Add_Branding_2.0.vbs" /PJDR:"[ProjectDir]" /PDV:"[ProductVendor]" /PKFN:"[FileName]" /PJN:"[ProjectName]"
From the vbscript I would have something like this to fetch the arguments for usage when opening/modifying the project file:
Option Explicit
Dim WSIFile, WFWI, WTable
WSIFile = Wscript.Arguments.Named("PJDR") & "\" & Wscript.Arguments.Named("PKFN") & ".wsi"
Set WFWI = CreateObject("WfWi.Document")
WFWI.Open(WSIFile)
Set WTable = WFWI.WTables("Summary")
WTable.WRows.Row("Title").WColumns("Value").Data = "Installation Database"
WTable.WRows.Row("Subject").WColumns("Value").Data = Wscript.Arguments.Named("PJN")
WTable.WRows.Row("Author").WColumns("Value").Data = "<Name from Active Directory>"
WTable.WRows.Row("Key Words").WColumns("Value").Data = "Installer,MSI,Database"
WTable.WRows.Row("Comments").WColumns("Value").Data = "This installer database contains the logic and data required to install " & WFWI.GetProperty("ProductName") & " " & WFWI.GetProperty("ProductVersion") & "."
WFWI.Save(WSIFile)
Posted by:
MPA2012
16 years ago
AngleID,
I have this already in my vbscript. I am trying to move it from the vbscript to a Wise Macro to run it from the macro instead. I am looking for, how to retrieve the the WPS variables ([PackageName], [FileName], [ProjectDir] etc....) from with in the wise macro.
Just thought there might be an easier way.
Any help on this would be greatly appreciated.
P.S. I am currently having the vbs branding script add these WPS variables as properties so when I open the wsi/mst project, the macro will run using the properties.
I have this already in my vbscript. I am trying to move it from the vbscript to a Wise Macro to run it from the macro instead. I am looking for, how to retrieve the the WPS variables ([PackageName], [FileName], [ProjectDir] etc....) from with in the wise macro.
Just thought there might be an easier way.
Any help on this would be greatly appreciated.
P.S. I am currently having the vbs branding script add these WPS variables as properties so when I open the wsi/mst project, the macro will run using the properties.
Posted by:
MPA2012
16 years ago
Posted by:
AngelD
16 years ago
Posted by:
AngelD
16 years ago
If it's of any help I found this piece of information laying around at my disk:
Q.
How to get the "Package Path" or actual opened wsi including full path in a Wise Installer Editor macro (visible on Project Definition / Product Detail / Package Path and also declared via [ProjectDir] in Project Setup Dialog)?
A.
Have a look at the save event, you will see a property called "Pathname". Throw that into the declarations then, chop it up using string manipulation as this is a full file path.
Q.
How to get the "Package Path" or actual opened wsi including full path in a Wise Installer Editor macro (visible on Project Definition / Product Detail / Package Path and also declared via [ProjectDir] in Project Setup Dialog)?
A.
Have a look at the save event, you will see a property called "Pathname". Throw that into the declarations then, chop it up using string manipulation as this is a full file path.
Posted by:
Robo Scripter
16 years ago
Mike,
Sorry I didn’t get back to you on this, I got more than a little busy.
[:(] Unfortunately WPS does not directly expose and of the project data items internally to the interior of the WSI. Therefore there is no easy way to access these values via the Wise Macro. [:(]
[:@]((NOTE: To any Altiris folks reading this... This is a BAD thing. Fix it please!))[:@]
I have in the past attempted to access the data utilizing WMI calls directly back to the Work Bench database but the project was cut short for cost concerns.
We currently have in our project work flow a vbscript action that utilizes the same method of branding. The difference being that here we create a component that writes an INI file as well as a set of defined registry entries.
As far as what can and can not be done with the Wise Macro. I am currently running a macro that has around 70 separate functions that can touch virtually every part of the development process in WSI’s, MSI’s, MST’s as well as merge module development and patch creation.
Couple this with a library of over 3000 vbscript and there is very little I have not found a solution to.
Regards,
Sorry I didn’t get back to you on this, I got more than a little busy.
[:(] Unfortunately WPS does not directly expose and of the project data items internally to the interior of the WSI. Therefore there is no easy way to access these values via the Wise Macro. [:(]
[:@]((NOTE: To any Altiris folks reading this... This is a BAD thing. Fix it please!))[:@]
I have in the past attempted to access the data utilizing WMI calls directly back to the Work Bench database but the project was cut short for cost concerns.
We currently have in our project work flow a vbscript action that utilizes the same method of branding. The difference being that here we create a component that writes an INI file as well as a set of defined registry entries.
As far as what can and can not be done with the Wise Macro. I am currently running a macro that has around 70 separate functions that can touch virtually every part of the development process in WSI’s, MSI’s, MST’s as well as merge module development and patch creation.
Couple this with a library of over 3000 vbscript and there is very little I have not found a solution to.
Regards,
Posted by:
AngelD
16 years ago
If you have define the Application field (PackageName) under "Product Details" (found under the Installation Expert view) you could from a macro get the value from the WiseMediaOptions table.
Set tblWiseMediaOptions = WTables("WiseMediaOptions")
sPackageName = tblWiseMediaOptions.WRows.Row("SMApplication").WColumns("Value").Data
Posted by:
AngelD
16 years ago
Have in mind that this is my first Macro so be gentle [;)]
Edit the Save macro for "On Windows Installer Editor Event" (WFWIEvents_Save)
This code should be similar for what you're after:
Edit the Save macro for "On Windows Installer Editor Event" (WFWIEvents_Save)
This code should be similar for what you're after:
sProjectDir = Mid(strPathname, 1, InStrRev(strPathname, "\")-1)
sProductVendor = GetProperty("Manufacturer")
sFileName = Mid(strPathname, InStrRev(strPathname, "\")+1)
sFileName = Mid(sFileName, 1, InStrRev(sFileName, ".")-1)
Set tblWiseMediaOptions = WTables("WiseMediaOptions")
sSMApplication = tblWiseMediaOptions.WRows.Row("SMApplication").WColumns("Value").Data
sSMPackage = tblWiseMediaOptions.WRows.Row("SMPackage").WColumns("Value").Data
sProjectName = sSMApplication & " " & sSMPackage
MsgBox(sProjectDir & vbNewline & sProductVendor & vbNewline & sFileName & vbNewline & sProjectName)
Posted by:
AngelD
16 years ago
Posted by:
jmcfadyen
16 years ago
Therefore there is no easy way to access these values via the Wise Macro.
umm sorry I have been away for a bit.
are you guys just looking for the project directory ?
if so
(pathname)
its in the save event, this will return the full path to the current WSI / MSI folder.
its been there since the year dot but its poorly documented.
Posted by:
AngelD
16 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.