I've come across instances, seemingly random, where WMI scripts fail inside 
Windows Installer. I've always assumed it's got something to do with 
credentials and impersonation. When you're running a custom action you may 
already be impersonated on an msiexec process via RPC. Then when you get into 
WMI it's another out-of-process call and I believe WMI tries to do more 
impersonation, and you can't transfer impersonated credentials.

Phil Wilson

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Siegfried 
Heintze (Aditi)
Sent: Friday, May 30, 2008 12:08 PM
To: wix-users@lists.sourceforge.net
Subject: [WiX-users] WMI/ADSI VBS scripts fail in installer only: They work 
fine from cscript on the command line!

I have the script below stored in a file called IISScripts.vbs.

I have this in my wxs file:

    <Binary Id="IISScripts" src="IISScripts.vbs"/>
    <CustomAction Id="SetIISLog" BinaryKey="IISScripts" 
VBScriptCall="SetIISLog" Return="check" />

      <InstallExecuteSequence>
        <InstallExecute Sequence='6500'>NOT Installed</InstallExecute>
        <Custom Action="SetIISLog" After="InstallFiles" >
                </Custom>
      </InstallExecuteSequence>

I get these error messages:

((ERROR)) Line 133 
GetObject("winmgmts:{authenticationLevel-pktPrivacy}\\.\root\microsoftiisv2)
((ERROR)) line 135 Set colItems ... (see source code below)

Hmmm... I was getting an error indicating that objWMIService was undefined. I 
cannot figure out what changed to cause these different error messages.

Well, anyway: here is the kicker: this script works fine when I call it from 
CMD.EXE with the cscript.exe command. Why do these calls only fail when I call 
them from the installer?

Thanks,
Siegfried


    16       Option Explicit
    17
    18       Const FAILED = 3
    19       Const SUCCEEDED = 0
    20       Dim notInWMI
    21       notInWMI = False
    22
    23       
'------------------------------------------------------------------------------
    24       ' Logs information to calling MSI
    25       
'------------------------------------------------------------------------------
    26       Sub LogInfo(msg)
    27           If notInWMI Then
    28               WScript.Echo msg
    29           Else
    30               Dim rec
    31               Set rec = Session.Installer.CreateRecord(1)
    32               rec.StringData(0) = "((INFO)) " & msg
    33               Session.Message &H04000000, rec
    34           End If
    35       End Sub
    36
    51       Function ChkError(msg)
    52           if Err and Err.number <> 0 then
    53               LogError msg & " {" & Err.number & ": " & Err.Description 
& "}"
    54               ChkError = FAILED
    55               Exit Function
    56           end if
    57           ChkError = SUCCEEDED
    58       End Function
    59
    60
   116      
'------------------------------------------------------------------------------
   117      ' Sets the the IIS log file
   118      
'------------------------------------------------------------------------------
   119      Function SetIISLog()
   120          On Error Resume Next
   121          dim objWMIService
   122          dim colItems
   123          dim strComputer
   124          LogInfo "line 124 Beginning SetIISLog"
   125          SetIISLog = FAILED
   126          'Instance = Session.Properties("SITEURL")
   127          Instance = "Default Web Site"
   128          ' Verify we can connect to IIS on specified Server
   129          LogInfo "Line 129  "
   130          strComputer = "."
   131          LogInfo "Line 131"
   132          Set objWMIService = 
GetObject("winmgmts:{authenticationLevel=pktPrivacy}\\" & strComputer & 
"\root\microsoftiisv2")
   133          ChkError("Line 133 
GetObject(""winmgmts:{authenticationLevel=pktPrivacy}\\" & strComputer & 
"\root\microsoftiisv2"")")
   134          Set colItems = objWMIService.ExecQuery ("Select * from 
IIsWebServiceSetting")
   135          ChkError("line 135  Set colItems = objWMIService.ExecQuery 
(""Select * from IIsWebServiceSetting"")")
   136          For Each objItem in colItems
   137              LogInfo "Line 137 Log File Directory: " & 
objItem.LogFileDirectory
   138              'LogInfo "Line 138 Log File Local Time Rollover: " & 
objItem.LogFileLocaltimeRollover
   139              'LogInfo "Line 139 Log File Period: " & 
objItem.LogFilePeriod
   140              'LogInfo "Line 140 Log File Truncate Size: " & 
objItem.LogFileTruncateSize
   141              if objItem.LogFileDirectory = 
"C:\WINDOWS\system32\LogFiles" then
   142                objItem.LogFileDirectory = "c:\Documents and 
Settings\a-siehei\My Documents\dev\bugs\2803"
   143              else
   144                objItem.LogFileDirectory = "C:\WINDOWS\system32\LogFiles"
   145              end if
   146              objItem.Put_
   147              LogInfo "Line 147 Log File Directory: " & 
objItem.LogFileDirectory
   148          Next
   149
   150          SetIISLog = SUCCEEDED
   151          LogInfo "Line 151 Ending SetIISLog retval=" & SetIISLog
   152      End Function
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to