Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help solve my code

Posted on 2014-07-14
4
Medium Priority
?
495 Views
Last Modified: 2014-07-21
I am lost in this script, I am getting end of statement needed error
'===============================================================
'=== Health Partners Scripting / Packaging VBScript Template
'=== Author: Bobby Lee
'=== 
'=== Revision History:
'=== 09/04/2012:  v1.0 - Initial Release
'===
'===============================================================

Const OverwriteExisting = True
Const HKEY_LOCAL_MACHINE = &H80000002
'Const HKEY_CLASSES_ROOT   = &H80000000
'Const HKEY_CURRENT_USER   = &H80000001
'Const HKEY_USERS          = &H80000003

Dim objIEDebugWindow
Dim objFSO, objFolder, WshShell, objTextFile, objFile, oReg
Dim Scanner_File, Scanner_File2, strComputer	
Dim appName, appVer, logfile, Bit32_64, ReturnCode, ReturnCode_Err
Dim strDirectory, Log_File, strText, strKeyPath, strValueName, strValue
Dim strPath, strScriptFolder, strCommand, strScriptPath, strScriptFullName
Dim strEnv, strMode, strLD 

'=========================
'=== Script Parameters ===
'=========================
Set colNamedArguments = WScript.Arguments.Named

If colNamedArguments.Exists("Env") Then
	strEnv = UCase(colNamedArguments.Item("Env"))
Else
	strEnv = "Prod"
End If 

If colNamedArguments.Exists("Mode") Then
	strMode = UCase(colNamedArguments.Item("Mode"))
Else
	strMode = "INSTALL"
End If

If colNamedArguments.Exists("LD") Then
	strLD = UCase(colNamedArguments.Item("LD"))
Else
	strLD = "9" 
End If

'===============================
'=== Application Information ===
'===============================
appName = "CCPulse"
appVer = "v8.0100.16"

strComputer = "." 'Use . for current machine

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set colNamedArguments = WScript.Arguments.Named  
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'============================
'=== Get Script Directory ===
'============================ 
strPath = WScript.ScriptFullName
Set objFile = objFSO.GetFile(strPath)
strScriptFolder = objFSO.GetParentFolderName(objFile) & "\"
'WScript.Echo strScriptFolder

'==========================
'=== Log File Directory ===
'==========================
strDirectory = "c:\logs\appinst"
Log_File = strDirectory & "\" & appName & " " & appVer & "_Inst"& ".log"
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
Else
   Set objFolder = objFSO.CreateFolder(strDirectory)
   'WScript.Echo "Created Directory: " & strDirectory
End If

If objFSO.FileExists(Log_File) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
Else
   Set objFile = objFSO.CreateTextFile(Log_File)
	'Wscript.Echo "Created Logfile: " & Log_File
End If 

Set objFile = Nothing
Set objFolder = Nothing
'=== End Log File Declaration ===
'===============================================
'=== OpenTextFile Method needs a Const value ===
'=== ForAppending = 8                        ===
'=== ForReading = 1                          ===
'=== ForWriting = 2                          ===
'===============================================
Const ForAppending = 8

'==============================
'=== Initialize Error Codes ===
'==============================
ReturnCode = 0 
ReturnCode_Err = 0

'===================================
'=== Begin - Initialize Log File ===
'===================================
Set objTextFile = objFSO.OpenTextFile(Log_File, ForAppending, True)
objTextFile.WriteLine("=====================================================")
objTextFile.WriteLine(Now & ": Begin Execution")
objTextFile.WriteLine(Now & ": LogFile = " & Log_File)
'=== End Initialize Log File ===

'=== Determine 32-bit or 64-bit OS
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "PROCESSOR_ARCHITECTURE"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,Bit32_64

'Debug "This is a great way to display intermediate results in a separate window."

'============================
'=== Begin Common Section ===
'============================
objTextFile.WriteLine(Now & ": === Processing Common Section")

'=== Remove Registry Keys
'strKeyPath = "SOFTWARE\Microsoft\Active Setup\Installed Components\>{0000000000-0000-0000-0000-HP0000CCE1130}"
'strValueName = "Version"
'strValue = ReadRegStr (HKEY_LOCAL_MACHINE, strKeyPath, strValueName, 32)
'If not IsBlank(strValue) Then
'	objTextFile.WriteLine(Now & ": Removing ActiveSetup Component from Registry for v11.30")
'	oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
'End If 
	
'=== Enumerate Registry Key
'strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
'oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
'For Each objSubkey In arrSubkeys
'	'code here
'Next
	

'=== CCPulse v8.0.100.16?
'strValue = ""
'strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4C321511-E6CA-4D0E-AC48-72AB7E7297A8}"
'strValueName = "DisplayVersion"
'strValue = ReadRegStr (HKEY_LOCAL_MACHINE, strKeyPath, strValueName, 32)
'WScript.Echo "CCPulse v8.0.100.16 in 32-bit registry " & strValue
'If IsBlank(strValue) Then
	'WScript.Echo "Uninstalling CCPulse+ v8.0.100.16 in 32-Bit Registry: " & strValue
	
	objTextFile.WriteLine(Now & ": Installing CCPulse+ v8.0.100.16")
	strCommand = chr(34) & strScriptFolder & "Source\setup.exe" -s -f1 & chr(34) & strScriptFolder & "Source\setup.iss"" -f2""c:\logs\appinst\CCPulse_v8.0_Inst.log""",0,True)
	ReturnCode = WshShell.Run(strCommand,0,True)
	'ReturnCode = WshShell.Run("""\\hplandesk95\packages\CCPulse\v8\Source\setup.exe"" -s -f1""\\hplandesk95\packages\CCPulse\v8\Source\setup.iss"" -f2""c:\logs\appinst\CCPulse_v8.0_Inst.log""",0,True)
	objTextFile.WriteLine(Now & ": Return Code = " & ReturnCode)
	objTextFile.WriteLine(" ")
	'oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
	InstallError (ReturnCode)
'End If  



If UCase(Bit32_64) = "X86" Then
'============================
'=== Begin 32-bit Section ===
'============================
	'objTextFile.WriteLine(Now & ": === Processing 32-bit Section")

' #region Disabled code
' 	'=== CCE v12.20 Installed?
' 	strValue = ""
' 	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{6377D733-85CF-4961-91CE-B84A4F866917}"
' 	'=== HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{6377D733-85CF-4961-91CE-B84A4F866917}
' 	strValueName = "DisplayVersion"
' 	strValue = ReadRegStr (HKEY_LOCAL_MACHINE, strKeyPath, strValueName, 32)
' 	'oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
' 	'WScript.Echo "CCE v12.20 in 32-bit registry " & strValue
' 	If IsEmpty(strValue) Or IsNull(strValue) Then
' 		'WScript.Echo "Executing CCE v12.20 in 32-Bit Registry: " & strValue
' 		objTextFile.WriteLine(Now & ": Installing CCE v12.20")
' 		ReturnCode = WshShell.Run("""\\hplandesk95\packages\CCE\v12.20\Disk1\setup.exe"" -s -f1""\\hplandesk9\packages\CCE\v12.20\Disk1\setup.iss"" -f2""c:\logs\appinst\CCE_1220_ISS.log",0,True)
' 		objTextFile.WriteLine(Now & ": Return Code = " & ReturnCode)
' 		objTextFile.WriteLine(" ")
' 		'InstallError (ReturnCode)
' 	Else 
' 		objTextFile.WriteLine(" ")
' 		objTextFile.WriteLine(Now & ": Detected CCE " & strValue & " Installed")
' 		objTextFile.WriteLine(" ")	
' 	End If
' 	Set strValue = Nothing
' #endregion
	
'=============
'=== Debug ===
'=============
'	ReturnCode = 10
'	objTextFile.WriteLine(Now & ": Debug")
'	objTextFile.WriteLine(Now & ": Return Code = " & ReturnCode)
'	objTextFile.WriteLine(" ")
'	InstallError(ReturnCode)
	
		
'=== End 32-bit Section ===
Else 
'============================
'=== Begin 64-bit Section ===
'============================
	'objTextFile.WriteLine(Now & ": === Processing 64-bit Common Section")

	'Set strValue = Nothing
		
'=== End 64-bit Section ===
End If 

'=====================================================
'=== Begin Post-Installation Configuration Section ===
'================------===============================
objTextFile.WriteLine(Now & ": === Processing Post-Installation Configuration Section")
objTextFile.WriteLine("")

If objFSO.FolderExists("C:\GCTI\CCPulse+") Then
	objFSO.CopyFile chr(34) & strScriptFolder & "Updates\*.stg" , "C:\GCTI\CCPulse+\" , OverwriteExisting
	'objFSO.CopyFile "\\hplandesk95\packages\CCPulse\v8\Updates\*.stg" , "C:\GCTI\CCPulse+\" , OverwriteExisting
	objTextFile.WriteLine(Now & ": Installing HP Custom Files: Return Code = " & ReturnCode) 
End If

'=== Force LANDesk Inventory Scan
LDInventory()	
	
objTextFile.WriteLine("===============================================")
objTextFile.Close
'=== End Post-Installation Configuration Section ===


'=== Cleanup ===
Set objFSO = Nothing
Set objFolder = Nothing
Set WshShell = Nothing
Set objTextFile = Nothing
Set objFile = Nothing
Set oReg = Nothing
Set appName = Nothing
Set appVer = Nothing
Set logfile = Nothing
Set Bit32_64 = Nothing
Set ReturnCode = Nothing
Set strDirectory = Nothing
Set Log_File = Nothing
Set strText = Nothing
Set strKeyPath = Nothing
Set strValueName = Nothing
Set strValue = Nothing

WScript.Quit

' Reads a REG_SZ value from the local computer's registry using WMI.
' Parameters:
'   RootKey - The registry hive (see http://msdn.microsoft.com/en-us/library/aa390788(VS.85).aspx for a list of possible values).
'   Key - The key that contains the desired value.
'   Value - The value that you want to get.
'   RegType - The registry bitness: 32 or 64.

Function ReadRegStr (RootKey, Key, Value, RegType)
    Dim oCtx, oLocator, oReg, oInParams, oOutParams

    Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
    oCtx.Add "__ProviderArchitecture", RegType

    Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")

    Set oInParams = oReg.Methods_("GetStringValue").InParameters
    oInParams.hDefKey = RootKey
    oInParams.sSubKeyName = Key
    oInParams.sValueName = Value

    Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)

    ReadRegStr = oOutParams.sValue
End Function

Sub InstallError (ReturnCode)
	'=== Retain ReturnCode if error and exit script if required component
	If ReturnCode <> 0 Then
		objTextFile.WriteLine(Now & ": *** Installation Error Encountered ***")
		objTextFile.WriteLine(Now & ": Return Code = " & ReturnCode)
		objTextFile.Close

		Set objFSO = Nothing
		Set objFolder = Nothing
		Set WshShell = Nothing
		Set objTextFile = Nothing
		Set objFile = Nothing
		Set oReg = Nothing
		Set appName = Nothing
		Set appVer = Nothing
		Set logfile = Nothing
		Set Bit32_64 = Nothing
		Set strDirectory = Nothing
		Set Log_File = Nothing
		Set strText = Nothing
		Set strKeyPath = Nothing
		Set strValueName = Nothing
		Set strValue = Nothing

		WScript.Quit(ReturnCode)
	End If 	
End Sub

Sub LDInventory()
	Scanner_File = "C:\Program Files (x86)\LANDesk\LDClient\LDISCN32.EXE"
	Scanner_File2 = "C:\Program Files\LANDesk\LDClient\LDISCN32.EXE"
	'ReturnCode = 0 

	If objFSO.FileExists (Scanner_File) Then 
		ReturnCode = WshShell.Run("""C:\Program Files (x86)\LANDesk\LDClient\LDISCN32.EXE"" /NTT=HPLANDESK9:5007 /S=HPLANDESK9  /I=HTTP://HPLANDESK9/ldlogon/ldappl3.ldz /NoUI /Sync /F",0,True)
	ElseIf objFSO.FileExists (Scanner_File2) Then
		ReturnCode = WshShell.Run("""C:\Program Files\LANDesk\LDClient\LDISCN32.EXE"" /NTT=HPLANDESK9:5007 /S=HPLANDESK9  /I=HTTP://HPLANDESK9/ldlogon/ldappl3.ldz /NoUI /Sync /F",0,True)	
	End If 
	
	objTextFile.WriteLine(Now & ": Return Code = " & ReturnCode & " : Updating LANDesk Inventory")
End Sub  

Sub Debug( myText )
	' Uncomment the next line to turn off debugging
	Exit Sub

  If Not IsObject( objIEDebugWindow ) Then
    Set objIEDebugWindow = CreateObject( "InternetExplorer.Application" )
    objIEDebugWindow.Navigate "about:blank"
    objIEDebugWindow.Visible = True
    objIEDebugWindow.ToolBar = False
    objIEDebugWindow.Width   = 200
    objIEDebugWindow.Height  = 300
    objIEDebugWindow.Left    = 10
    objIEDebugWindow.Top     = 10
    Do While objIEDebugWindow.Busy
      WScript.Sleep 100
    Loop
    objIEDebugWindow.Document.Title = "IE Debug Window"
    objIEDebugWindow.Document.Body.InnerHTML = _
                 "<b>" & Now & "</b></br>"
  End If

  objIEDebugWindow.Document.Body.InnerHTML = _
                   objIEDebugWindow.Document.Body.InnerHTML _
                   & myText & "<br>" & vbCrLf
End Sub

Function IsBlank(Value)
	'returns True if Empty or NULL or Zero
	If IsEmpty(Value) or IsNull(Value) Then
		IsBlank = True
		Exit Function
	ElseIf VarType(Value) = vbString Then
		If Value = "" Then
 			IsBlank = True
 			Exit Function
		End If
	ElseIf IsObject(Value) Then
		If Value Is Nothing Then
			IsBlank = True
			Exit Function
		End If
	ElseIf IsNumeric(Value) Then
		If Value = 0 Then
			'wscript.echo " Zero value found"
			IsBlank = True
  			Exit Function
		End If
	Else
		IsBlank = False
	End If
End Function

Open in new window

0
Comment
Question by:xzay1967
  • 2
4 Comments
 
LVL 28

Assisted Solution

by:MacroShadow
MacroShadow earned 1200 total points
ID: 40195727
Change line 152 to:
strCommand = Chr(34) & strScriptFolder & "Source\setup.exe -s -f1" & Chr(34) & strScriptFolder & "Source\setup.iss -f2 c:\logs\appinst\CCPulse_v8.0_Inst.log"

Open in new window

0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 800 total points
ID: 40195936
I find getting double quotes inside a string variable can be a little tricky, and I actually take (what I consider) a slightly more obvious and clearer approach.  Rather than working with CHR(34) or "" inside strings, I add the small function below to my code, and then use it to wrap a string with double quotes when I need it.

That allows line 152 to be tidied up a bit as:

strCommand = Quote(strScriptFolder & "Source\setup.exe") & " -s -f1 " & Quote(strScriptFolder & "Source\setup.iss") & " -f2 " & Quote("c:\logs\appinst\CCPulse_v8.0_Inst.log"), 0, True)

Open in new window

Here's the small function used:

' Small routine to add double quotes around a string
Function Quote(strText)
   Quote = Chr(34) & strText & Chr(34)
End Function

Open in new window

~bp
0
 

Author Comment

by:xzay1967
ID: 40196025
Bill you always make time to provide simple concise solutions, thanks for that. @Macroshadow, I also appreciate your contribution, and I will give it a try when I get back to the office tomorrow.
0
 

Author Comment

by:xzay1967
ID: 40209962
Both solutions worked thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question