From: Robert on 24 Mar 2010 22:17 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
From: Richard Mueller [MVP] on 24 Mar 2010 23:07 "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 It's hard for us to tell which is line 40. When I paste the code into a file I believe it is the "End Function" statement in "Function Name", but I could be wrong. In any case Function Name is never called, so variable strComputerName will never have a value. And, I wouldn't be surprised if "Name" is a reserved name. If so, that could be the problem. I don't believe "On Error Resume Next" is necessary. I would remove it. Finally, if the object of Function Name is to retrieve the name of the local computer, why not use: Set objNetwork = CreateObject("Wscript.Network") strComputerName = objNetwork.ComputerName -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net --
From: Al Dunbar on 25 Mar 2010 00:27 "Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in message news:#rOlIh8yKHA.4964(a)TK2MSFTNGP04.phx.gbl... > > "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 > > It's hard for us to tell which is line 40. When I paste the code into a > file I believe it is the "End Function" statement in "Function Name", but > I could be wrong. In any case Function Name is never called, so variable > strComputerName will never have a value. And, I wouldn't be surprised if > "Name" is a reserved name. If so, that could be the problem. I don't > believe "On Error Resume Next" is necessary. I would remove it. Finally, > if the object of Function Name is to retrieve the name of the local > computer, why not use: > > Set objNetwork = CreateObject("Wscript.Network") > strComputerName = objNetwork.ComputerName Also, it is difficult to lookup the error code when only seven of its eight digits are given. /Al
From: Brian Kelly on 25 Mar 2010 07:05 Robert wrote: > 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 Your missing a 'next' after the 'For Each subkey in arrSubKeys' loop. -- Brian Kelly Home Page http://kellybk.com Species Race http://speciesrace.com
From: LikeToCode on 25 Mar 2010 07:27
In the Function 'Name' your 'For Each' loop is missing the 'Next' so the error your getting is because of incorrect syntax. |