From: Pegasus [MVP] on


"Robert" wrote in message news:2010324221711robert.stepp(a)cvn74.navy.mil...
> I am constantly getting "Error 8004000" Line 40 Char1 expected statement
> with my script and can't figure out why.
>
> 'Logging
> Option Explicit
> 'Declarations
> Const LOGFILE = "c:\SysAd Tools\Logs\UA.log"
> Const ForReading = 1
> Const ForWriting = 2
> Const ForAppending = 8 'Open and write to the end of log
> Dim ComputerName
> Dim oFSO
> Dim strComputer
> Dim strComputerName
> Const HKEY_LOCAL_MACHINE = &H80000002
> Dim WshShell
> Dim oReg
> Dim strKeyPath
> Dim subkey
> Dim arrSubKeys
> strComputer = "."
>
> Set oFSO = CreateObject("Scripting.FIleSystemObject")
>
> 'Initialization
> InitLogFile()
>
> 'Descriptions
> WriteEventLog 1,"Error in Uninstall"
> WriteLogFile 0,"Completed Uninstall"
>
> Function InitLogFile()
> oFSO.CreateTextFile LOGFILE,True
> End Function
>
> Function Name
> Set WshShell = CreateObject("wscript.Shell")
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> strComputer & "\root\default:StdRegProv")
> strKeyPath =
> "SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName"
> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
> For Each subkey in arrSubKeys
> strComputerName = WshShell.RegRead ("HKLM\" & strKeyPath & "\" & subkey &
> "\ComputerName")
> End Function
>
> Function WriteLogFile(iResult, sLogInfo)
> Dim sLog,fFile
>
> If iResult =0 Then
> sLog = strComputerName & Time & "-Info-" & WriteLogFile
> Elseif iResult <> 0 Then
> sLog = strComputerName & Time & "-Error-" & WriteEventLog
> End If
>
> Set fFile = oFSO.OpenTextFIle(LOGFILE,ForAppending,True)
> fFile.WriteLine sLog
> fFile.Close
> End Function
>
> Function WriteEventLog(iResult, sLogInfo)
> Dim oshell, Retval, sLog
> Set oshell = createobject("wscript.shell")
> sLog = "***" & ucase(wscript.scriptname) & "***" & vbcrlf &_
> vbcrlf &_
> Chr(9) & "RESULT:" & sLogInfo & vbcrlf &_
> vbcrlf &_
> Chr (9) & "ScriptLocation:" & wscript.scriptfullname & vbcrlf
> Retval = oshell.LogEvent(iResult, sLog)
> End Function
>
> On Error Resume Next
>
> strKeyPath = "SOFTWARE\Microsoft\WIndows\CurrentVersion\Uninstall"
> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>
> For Each subkey in arrSubKeys
> strDisplayName = WshShell.RegRead ("HKLM\" & strKeyPath & "\" & subkey &
> "\DisplayName")
> If strDisplayName = "Yahoo! Toolbar" Then
> WshShell.Run "msiexec.exe /X" & subkey & " /qn /norestart", 7, True
> End If
> If strDiplayName = "Netflix Movie Viewer" Then
> WshShell.Run "msiexec.exe /X" & subkey & " /qn /norestart", 7, True
> End If
> If strDisplayName = "Drug Lord 2" Then
> WshShell.Run "msiexec.exe /X" & subkey & " /qn /norestart", 7, True
> End If
> If strDisplayName = "Atari Arcade Hits" Then
> WshShell.Run "msiexec.exe /X" & subkey & " /qn /norestart", 7, True
> End If
> Next
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> BizTalk: Conditional looping incorporating the Greater Than functoid.
> http://www.eggheadcafe.com/tutorials/aspnet/e4334816-d106-40f2-812d-043c18df964c/biztalk-conditional-loop.aspx

Others have pointed out the cause of your error. This type of error is easy
to avoid if you indent your code consistently in order to make the
underlying structure visible. Instead of coding like so:

Function Name
Set WshShell = CreateObject("wscript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey in arrSubKeys
strComputerName = WshShell.RegRead ("HKLM\" & strKeyPath & "\" & subkey &
"\ComputerName")
End Function

you could code like so:

Function Name
Set WshShell = CreateObject("wscript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
strKeyPath =
"SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey in arrSubKeys
strComputerName = WshShell.RegRead ("HKLM\" & strKeyPath & "\" &
subkey & "\ComputerName")
next
End Function