Hi,
I am using this...
cscript.exe /nologo "\\indiasophos\Ps\Msi.vbs"
title:"Microsoft Office OneNote 2003 Setup" path:"\\indiasophos\Ps\ONO
TE11.MSI" group:".net"
Script starts here...
'
http://www.vbshf.com/vbshf/forum '
'Author:
'Rob Dunn
'
'Email Address:
'uphold2001@hotmail.com
'
'Script Name:
'installmsiapp.vbs
'
'Script Version:
'1.0
'
'Description:
'This script will help you install a particular application based upon user
' membership in a particular domain group. Installmsiapp will check the
' computer's installed (MSI) applications, see if it can find the requested
' software title, then install the app if it is missing, and if the logged
' in user is a member of the requested domain group (no nested groups currently)
'
'Note that this is for MSI-packaged applications ONLY.
'
'The script will take three inputs as command-line parameters:
'
'title: the application title of the MSI (i.e. "Microsoft .NET Framework 1.1")
'path: the path of the installation MSI (i.e. "\\fileserver\share\netfx.
msi)
'group: the name of the domain group (i.e. "Install - .NET")
'
'Note: the group must be a domain group of the currently logged in user domain.
' Also, the name must match EXACTLY (case-insensitive). If the user is not
' a member of the specified group, the script will exit without checking to see
' if the application is installed or not. This allows for faster processing.
'
'If the requested application is not installed, a popup dialog will
' appear, telling the user that the application needs to be installed and
' to please wait (this will disappear after 10 seconds (default)).
'
'When the msi installs, it will use the /passive msiexec.exe command-line
' switch, which only shows a progress bar, but no other intervention is
' necessary.
'
'This script is particularly useful for deploying applications via the logon
' script, but you don't want to go the route of deploying via GPO (or if
' perhaps the GPO isn't working properly with a third-party MSI).
'
'An example of this being called from a batch file login script:
'
'cscript.exe /nologo "\\indiasophos\Ps\Msi.vbs"
title:"Microsoft Office OneNote 2003 Setup" path:"\\indiasophos\Ps\ONO
TE11.MSI" group:".net"
'
'So, in this case, you would create a user group on the domain level called
' 'Install - .Net 1.1', add users to it, then assign the batch file containing
' the above code to those users...or, you can deploy a GPO with this as a
' logon script, then only give 'Install - .Net 1.1' permissions to apply it
' through the security filtering tab...then assign the GPO to the domain.
'Declare a couple of constants for our WMI connection string (courtesy of
' the Microsoft Scriptomatic 2.0 tool).
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
On Error goto 0
'Declare objects
Set objArgs = WScript.Arguments
'Declare variables
dim bInstalled
'Set to 'false' since we are assuming NOT installed, we will check later...
bInstalled = false
'Show variables as they are being passed, status, etc. -
' 0 = No debug, perform installation
' 1 = Debug, show variables, no installation (don't run MSI at end of script)
iDebug = 0
'Get command-line arguments
If objargs.count < 1 Then
'If no command line parameters are passed, exit the script.
wscript.quit
Else
'Go through all the command-line options and find out what was passed.
For I = 0 to objArgs.Count - 1
'Find the title of the application we are looking for.
If InStr(1,LCase(objargs(I)),
"title:") Then
arrTitle = split(objargs(I),"title:")
strTitle = arrTitle(1)
if idebug = 1 then wscript.echo "Title: " & strTitle
ElseIf InStr(1,LCase(objargs(I)),
"path:") Then
'Find the path of the application down to the .msi extension for the title
' we were shown above.
arrPath = split(lcase(objargs(I)),"p
ath:")
strPath = arrPath(1)
if idebug = 1 then wscript.echo "Path: " & strPath
ElseIf InStr(1,LCase(objargs(I)),
"group:") Then
'What domain group does this user (who is running the script) need to belong
' to in order for the .msi to run?
arrGroup = split(objargs(I),"group:")
strGroup = arrGroup(1)
if idebug = 1 then wscript.echo "Group: " & strGroup
Else
End If
Next
End If
'Find out if the currently logged on user is a member of the group we specified
' in strGroup above. If the user is not a member, then quit the script.
If isMember(strGroup) = false then wscript.quit
'Show text - - if run with cscript.exe, this will show up in the console window
' for the logon script. If not, it will show up in a pop-up window.
wscript.echo "Verifying install status for " & strTitle
If idebug = 1 then wscript.echo "Is a member of " & strGroup & ": " & IsMember(strGroup)
'Find out if the application we specified is installed - - - i.e. call the
' function that checks the status.
Call CheckInstalledStatus
Function CheckInstalledStatus
'When strComputer = ".", then that means tell the script to check the computer
' which is running the script.
strComputer = "."
'Create connection via WMI to computer.
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
'Perform a WQL (Windows Query Language) query through the WMI connection
' above, and output the results to a collection called 'colItems'.
Set colItems = objWMIService.ExecQuery("S
ELECT Caption FROM Win32_Product where caption='" & strTitle & "'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
'Move through each item in the collection.
For Each objItem In colItems
'If one of the captions has the text that we specified for the title (i.e.
' strTitle, then we know the application is installed.
If instr(objItem.Caption,strT
itle) then
WScript.Echo objItem.Caption & " is installed. Continuing script..."
wscript.echo " "
'Set this variable to 'true' so we can reference it later.
bInstalled = true
End If
Next
'If the application is not installed, then install the application...
If bInstalled = false then
Set WshShell = WScript.CreateObject("WScr
ipt.Shell"
)
'Give the user a warning telling them what is going on. This will
' disappear after 10 seconds.
WshShell.Popup "Now installing '" & strTitle & "', please stand by, this may take a few minutes..." & vbcrlf & vbcrlf & "This message will disappear in 10 seconds", 10, "Software installation in progress", 64
'Set the command line we are going to run, using the path we specified
' in strPath above. Use the /passive switch so that the user will only
' see the progress bar during installation.
sCmd = "msiexec.exe /i " & chr(34) & strPath & chr(34) & " /passive"
if idebug = 1 then wscript.echo "Command: " & sCmd
if idebug <> 1 then wshshell.run sCmd,1,true
Else
'If the application is installed, then show a quick blurb in the console
' window.
if idebug = 1 then wscript.echo strTitle & " is already installed on this computer."
End If
End Function
'*************************
**********
**********
**********
**********
**********
***
'Function IsMember(groupName)
'
'Input: Title of group name you wish to query against. This will check the
' domain and logged on user ID to find out whether or not it is a member of the
' specified group in 'strGroup' - the title must match the group name exactly.
'*************************
**********
**********
**********
**********
**********
***
Private Function IsMember(groupName)
'Instantiate the network object
Set netObj = CreateObject("WScript.Netw
ork")
'Set variable sDomain to the logged on user's domain.
sDomain = netObj.UserDomain
'Set variable sUser to the logged on user's ID.
sUser = netObj.UserName
'Set is member to false, as if there any problems we want to err on the side
' of caution (don't install if we don't know he/she is a member)
flgIsMember = false
'Attach to the user object in the domain using the WinNT provider.
Set userObj = GetObject("WinNT://" & sDomain & "/" & sUser & ",user")
'Move through each group that this user is a member of.
For Each grp In userObj.Groups
'If the name of one of the user's groups match the one we specified then
' the user is a member...i.e. flgIsMember = true.
If grp.Name = groupName Then
flgIsMember = true
'Don't keep searching, so exit the 'for' loop.
Exit For
End If
Next
'IsMember will equal 'true'/'false', depending on what the code above found.
IsMember = flgIsMember
'Set declared objects to nothing to free up memory.
Set userObj = nothing
Set netObj = nothing
End Function
'*************************
**********
**********
**********
**********
**********
****