Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

WMI script to launch an MSI


3 replies to this topic

RAZORFISH228

RAZORFISH228
  • Members
  • 1 posts

Posted 06 April 2004 - 17:15

I have been searching all around and even tried to hire a coder for this but cannot figure it out. I am looking for a script to copy a small MSI that enables file and printer sharing for microsoft networks when executed on a windows 2000 machine. Does anyone have a script or know where I can find one that does this.

Here is one I found but doesn't work on Windows 2000. I am wondering why or what needs to be on Windows 2000 for this to work. I am an administrator and have access to the workstations. Can someone comment or assist?

'********************************************************************
'*
'* Script: wmi_install.vbs
'*
'* Author: Darwin Sanoy
'* Desktop Engineer's Junk Drawer
'* http://wwww.desktopengineer.com/
'*
'* Purpose: Install a Windows Installer Application
'* local or remote computer Using WMI
'*
'* Date: 3/10/2000
'*
'********************************************************************


Dim objWshNet
Set objWshNet = CreateObject("Wscript.Network")
strServer = objWshNet.ComputerName

package_location = InputBox("Enter the location of the package to be installed.", "Package Name", "C:\TEMP\SCRIPTS\SHARE.msi")
remote_machine_name = InputBox("Enter the name of the machine on which the product " + _
Chr(13) + "is to be installed. Press enter for this machine.", "Machine Name", strServer)

If remote_machine_name <> strServer Then
admin_user = InputBox("Enter the user name. " + Chr(13) + _
"(User must have Administrative privileges.)")
admin_user_password = InputBox("Enter the users password. ")
End If

Set Locator = CreateObject("WbemScripting.SWbemLocator")

If remote_machine_name = strServer or remote_machine_name = "" Then
Set Service = Locator.ConnectServer(, "root\cimv2")
Else
Set Service = Locator.ConnectServer(remote_machine_name, "root\cimv2", _
admin_user, admin_user_password)
End If


Set Product = Service.Get("Win32_Product")

Set InstallSink = WScript.CreateObject("WbemScripting.SWbemSink", _
"INSTALLSINK_")

Service.Security_.ImpersonationLevel=3

Set Path = Product.Path_
Set Method = Product.Methods_.Item("Install")
Set InParams = Method.InParameters
Set MyIns = InParams.SpawnInstance_

MyIns.PackageLocation = package_location
MyIns.AllUsers = "TRUE"
MyIns.Options = ""

Service.ExecMethodAsync InstallSink, Path, "Install", MyIns, wbemFlagSendStatus

WScript.Echo "Waiting for progress."

Sub INSTALLSINK_OnCompleted(hResult, pErrorObject, pAsyncContext)
WScript.Echo ("Installation Complete")
End Sub

Sub INSTALLSINK_OnProgress(iUpperBound, iCurrent, strMessage, objWbemAsyncContext)
if iUpperBound > 0 then
iComplete = (iCurrent * 100)/iUpperBound
ProgBar.Value = iComplete
WScript.Echo (CStr(objObject.ReturnValue + "% Complete"))
end if
End Sub

Sub INSTALLSINK_OnObjectReady(objObject, objAsyncContext)
if Not objObject.ReturnValue = 0 Then
WScript.Echo ("Installation failed with following error: " + _
CStr(objObject.ReturnValue))
Else
WScript.Echo ("Installation Succeeded")
End If
End Sub



luke_s

luke_s
  • Full Members
  • 532 posts

Posted 07 April 2004 - 08:18

So are you actually looking for code to setup the file and print sharing, or for the msi copy, or for both?

Zweitze

Zweitze
  • Full Members
  • 522 posts

Posted 07 April 2004 - 08:32

I can see why this code doesn't configure file & printer sharing: The attached code actually installs a package on a remote system!

To learn how to do administrative tasks by script, try the Technet Script center:
http://www.microsoft...er/default.mspx


RobinD

RobinD
  • Members
  • 1 posts

Posted 08 April 2004 - 10:21

The script is doomed from the start because of the DCOM 2 hops and you're out rule. Hard coded into DCOM is the inability to connect to a remote server (Hop 1)and have a process (WMI) then connect (Hop 2) to another server (for the source of the msi package). This is a deliberate security limitation. The only way it will works as currently written is if the msi package is available locally on the target server.

You can get over it in a number of ways
  • Re-configure the user's account, the target server's acccount for 'Trusted for Delegation' and re-write the script to use kerberos. Too complicated here and in anycase this is just generally inadvisable
  • Hack the LanMan reg settings on the server with the share conatining the msi package to allow Null sessions - not advisable as anybody can now access the server
  • Place the msi package on a website which allows anonymous access and enter the url as the package source 'http://server/mypackage.msi'. Disadvantage - anybody can can connect and run the installation.