Hi,
I got a script to install some software, which produces a log file.
But now I have a requirement where the log file has to be something like:
"Client_computername_Install_DATE-TIME.log"
"Client_computer_Install_20120411_1633.log".
The date has to be yyyymmdd and time hhmm.
I have done this before...but unfortunately at the time, I didn't make a note of how to achieve this.
I don't how and where to put the additional commands.
This is my original script which needs to be adapted so I get the logs with the new naming sttyle.
"...
'************
' Description: Install the SCCM client on systems that don't have it or are running an older
' version
' It must not install on Thin Clients or Citrix blades
'
' Requirements: ccmsetup.exe in the current folder
' Parameter(s): None
' Returns: None
'*************
Option Explicit
' Constants
Const CLIENTVERSION = "4.0.6487.2000"
Const SCCMSITECODE = "IT"
Const LOGFILE = "C:\SCCMClientInstallLog.txt"
Const INSTALL_COMMAND = "ccmsetup.exe /service /mp:itgroup.net SMSSITECODE=IT FSP=PWI133 SMSSLP=serverpwi132.itgroup.net"
Const ForAppending = 8
Const EVENT_SUCCESS = 0
Const EVENT_INFO = 4
Const EVENT_ERROR = 1
' Globals
Dim intDebug
intDebug = 0
'*************
if intDebug = 1 then
WriteToLog "--Start of Script"
end if
' Start Execution
main
' End Execution
'*************
sub main
Dim ofsFS
Dim intRetVal
Dim objWshShell
set ofsFS = createobject("Scripting.FileSystemObject")
set objWshShell = createobject("Wscript.Shell")
if ofsFS.FileExists("c:\debug") then
intDebug = 1
if ofsFS.FileExists(LOGFILE) then
ofsFS.DeleteFile LOGFILE, True
end if
WriteToLog("Debugging is enabled")
end if
' Install the SCCM client
if CheckForSCCMClient <> 0 then
InstallSCCMClient
else
if intDebug = 1 then
WriteToLog "SCCM client already installed..."
end if
objWshShell.LogEvent EVENT_INFO, "SCCM client is already installed and the correct version."
end if
if intDebug = 1 then
WriteToLog "--End of Script"
end if
end sub
'*************
' Description: Checks for the existance of the correct version of the SCCM client.
'
' Requirements: None
' Parameter(s): None
' Returns: 0 if successful, nonzero for an issue
'*************
sub InstallSCCMClient
Dim WshShell
Dim objProcEnv
Dim objExecProcess
Set WshShell = WScript.CreateObject("WScript.Shell")
' This is how we disable the Open File Security Warning dialog for running .exe's from UNC paths...
set objProcEnv = WshShell.Environment("PROCESS")
objProcEnv("SEE_MASK_NOZONECHECKS") = 1
if intDebug = 1 then
WriteToLog "SEE_MASK_NOZONECHECKS is " & objProcEnv("SEE_MASK_NOZONECHECKS")
end if
if intDebug = 1 then
WritetoLog "Exectuting '" & INSTALL_COMMAND & "'"
end if
set objExecProcess = WshShell.Exec(INSTALL_COMMAND)
' Wait for the process to exit...
Do While objExecProcess.Status = 0
WScript.sleep 500
Loop
' Re-enable the Open File Security Warning dialog...
objProcEnv.Remove("SEE_MASK_NOZONECHECKS")
if intDebug = 1 then
WriteToLog "SEE_MASK_NOZONECHECKS is " & objProcEnv("SEE_MASK_NOZONECHECKS")
end if
if intDebug = 1 then
WriteToLog INSTALL_COMMAND & " exited with exitcode " & objExecProcess.ExitCode
end if
if objExecProcess.ExitCode = 0 then
WshShell.LogEvent EVENT_SUCCESS, "The SCCM client CCMSETUP.EXE program completed with exit code " & objExecProcess.ExitCode
else
WshShell.LogEvent EVENT_ERROR, "The SCCM client CCMSETUP.EXE program failed with exit code " & objExecProcess.ExitCode
end if
end sub
'*************
' Description: Checks for the existance of the correct version of the SCCM client.
'
' Requirements: None
' Parameter(s): None
' Returns: 0 if successful, nonzero for an issue
'*************
Function CheckForSCCMClient
' Check if the SMS Agent Host service exists
Dim objWMIService
Dim objSCCMService
Dim intRetVal
Dim objService
intRetVal = 0
CheckForSCCMClient = 0
set objWMIService = GetObject("winmgmts://./root/cimv2")
set objSCCMService = objWMIService.ExecQuery("Select PathName,StartMode from Win32_Service where Caption = 'SMS Agent Host'")
if objSCCMService.Count = 0 then
intRetVal = 1
if intDebug = 1 then
WriteToLog "No SMS/SCCM Service found..."
end if
else ' if it exists, check the version
if intDebug = 1 then
WriteToLog "SMS/SCCM Service found...Now the version check."
end if
end if
Dim ofsFs
Dim strFileVersion
set ofsFS = CreateObject("Scripting.FileSystemObject")
For Each objService in objSCCMService
strFileVersion = ofsFS.GetFileVersion(objService.PathName)
if intDebug = 1 then
WriteToLog "SMS/SCCM client version is " & strFileVersion
end if
if strFileVersion <> CLIENTVERSION then
if intDebug = 1 then
WriteToLog "SMS/SCCM client is not the correct version"
end if
intRetVal = 2
end if
if intDebug = 1 then
WriteToLog "CheckForSCCMClient intRetVal is " & intRetVal
end if
next
CheckForSCCMClient = intRetVal
End Function
'*************
' Description: Write a line to the debug log file
'
' Requirements: LOGFILE contains the path and filename to write to
' Parameter(s): strMessageToWrite is the text to write to the file
' Returns: Nothing!
'*************
sub WriteToLog(strMessageToWrite)
Dim ofsFS
Dim otsLogFile
set ofsFS = createobject("Scripting.FileSystemObject")
set otsLogFile = ofsFS.OpenTextfile(LOGFILE, ForAppending, True)
otsLogFile.WriteLine strMessageToWrite
otsLogFile.Close
end sub
..."
Thanks for any help!!!
I got a script to install some software, which produces a log file.
But now I have a requirement where the log file has to be something like:
"Client_computername_Install_DATE-TIME.log"
"Client_computer_Install_20120411_1633.log".
The date has to be yyyymmdd and time hhmm.
I have done this before...but unfortunately at the time, I didn't make a note of how to achieve this.
I don't how and where to put the additional commands.
This is my original script which needs to be adapted so I get the logs with the new naming sttyle.
"...
'************
' Description: Install the SCCM client on systems that don't have it or are running an older
' version
' It must not install on Thin Clients or Citrix blades
'
' Requirements: ccmsetup.exe in the current folder
' Parameter(s): None
' Returns: None
'*************
Option Explicit
' Constants
Const CLIENTVERSION = "4.0.6487.2000"
Const SCCMSITECODE = "IT"
Const LOGFILE = "C:\SCCMClientInstallLog.txt"
Const INSTALL_COMMAND = "ccmsetup.exe /service /mp:itgroup.net SMSSITECODE=IT FSP=PWI133 SMSSLP=serverpwi132.itgroup.net"
Const ForAppending = 8
Const EVENT_SUCCESS = 0
Const EVENT_INFO = 4
Const EVENT_ERROR = 1
' Globals
Dim intDebug
intDebug = 0
'*************
if intDebug = 1 then
WriteToLog "--Start of Script"
end if
' Start Execution
main
' End Execution
'*************
sub main
Dim ofsFS
Dim intRetVal
Dim objWshShell
set ofsFS = createobject("Scripting.FileSystemObject")
set objWshShell = createobject("Wscript.Shell")
if ofsFS.FileExists("c:\debug") then
intDebug = 1
if ofsFS.FileExists(LOGFILE) then
ofsFS.DeleteFile LOGFILE, True
end if
WriteToLog("Debugging is enabled")
end if
' Install the SCCM client
if CheckForSCCMClient <> 0 then
InstallSCCMClient
else
if intDebug = 1 then
WriteToLog "SCCM client already installed..."
end if
objWshShell.LogEvent EVENT_INFO, "SCCM client is already installed and the correct version."
end if
if intDebug = 1 then
WriteToLog "--End of Script"
end if
end sub
'*************
' Description: Checks for the existance of the correct version of the SCCM client.
'
' Requirements: None
' Parameter(s): None
' Returns: 0 if successful, nonzero for an issue
'*************
sub InstallSCCMClient
Dim WshShell
Dim objProcEnv
Dim objExecProcess
Set WshShell = WScript.CreateObject("WScript.Shell")
' This is how we disable the Open File Security Warning dialog for running .exe's from UNC paths...
set objProcEnv = WshShell.Environment("PROCESS")
objProcEnv("SEE_MASK_NOZONECHECKS") = 1
if intDebug = 1 then
WriteToLog "SEE_MASK_NOZONECHECKS is " & objProcEnv("SEE_MASK_NOZONECHECKS")
end if
if intDebug = 1 then
WritetoLog "Exectuting '" & INSTALL_COMMAND & "'"
end if
set objExecProcess = WshShell.Exec(INSTALL_COMMAND)
' Wait for the process to exit...
Do While objExecProcess.Status = 0
WScript.sleep 500
Loop
' Re-enable the Open File Security Warning dialog...
objProcEnv.Remove("SEE_MASK_NOZONECHECKS")
if intDebug = 1 then
WriteToLog "SEE_MASK_NOZONECHECKS is " & objProcEnv("SEE_MASK_NOZONECHECKS")
end if
if intDebug = 1 then
WriteToLog INSTALL_COMMAND & " exited with exitcode " & objExecProcess.ExitCode
end if
if objExecProcess.ExitCode = 0 then
WshShell.LogEvent EVENT_SUCCESS, "The SCCM client CCMSETUP.EXE program completed with exit code " & objExecProcess.ExitCode
else
WshShell.LogEvent EVENT_ERROR, "The SCCM client CCMSETUP.EXE program failed with exit code " & objExecProcess.ExitCode
end if
end sub
'*************
' Description: Checks for the existance of the correct version of the SCCM client.
'
' Requirements: None
' Parameter(s): None
' Returns: 0 if successful, nonzero for an issue
'*************
Function CheckForSCCMClient
' Check if the SMS Agent Host service exists
Dim objWMIService
Dim objSCCMService
Dim intRetVal
Dim objService
intRetVal = 0
CheckForSCCMClient = 0
set objWMIService = GetObject("winmgmts://./root/cimv2")
set objSCCMService = objWMIService.ExecQuery("Select PathName,StartMode from Win32_Service where Caption = 'SMS Agent Host'")
if objSCCMService.Count = 0 then
intRetVal = 1
if intDebug = 1 then
WriteToLog "No SMS/SCCM Service found..."
end if
else ' if it exists, check the version
if intDebug = 1 then
WriteToLog "SMS/SCCM Service found...Now the version check."
end if
end if
Dim ofsFs
Dim strFileVersion
set ofsFS = CreateObject("Scripting.FileSystemObject")
For Each objService in objSCCMService
strFileVersion = ofsFS.GetFileVersion(objService.PathName)
if intDebug = 1 then
WriteToLog "SMS/SCCM client version is " & strFileVersion
end if
if strFileVersion <> CLIENTVERSION then
if intDebug = 1 then
WriteToLog "SMS/SCCM client is not the correct version"
end if
intRetVal = 2
end if
if intDebug = 1 then
WriteToLog "CheckForSCCMClient intRetVal is " & intRetVal
end if
next
CheckForSCCMClient = intRetVal
End Function
'*************
' Description: Write a line to the debug log file
'
' Requirements: LOGFILE contains the path and filename to write to
' Parameter(s): strMessageToWrite is the text to write to the file
' Returns: Nothing!
'*************
sub WriteToLog(strMessageToWrite)
Dim ofsFS
Dim otsLogFile
set ofsFS = createobject("Scripting.FileSystemObject")
set otsLogFile = ofsFS.OpenTextfile(LOGFILE, ForAppending, True)
otsLogFile.WriteLine strMessageToWrite
otsLogFile.Close
end sub
..."
Thanks for any help!!!