VB Script - Windows 2008 Server

Trying to modify below VB Script to check to make sure script is running off hours.  No issues are coming up when manually running script but it's not producing a log file, can you tell me where I'm going wrong?   Thanks.

Option Explicit
On Error Resume Next

' Establish global variables.
Dim g_intMain, g_intLocale
Dim g_objFS, g_objShell, g_objCSV, g_objRegister
Dim g_strLogFolder, g_strLogFile, g_strServerName, g_strCurrentPath, g_strHosts
Dim g_strCSVTemp, g_strWinDir, g_strCSV, g_strUtils, g_strServerIPAddress, g_strEnvType
Dim g_strBPS, dNow

' Constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const MinWindow = 7
'Const SuccessCode = 555
'Const PendingCode = 777
'Const RegisterThreshold = 0.75
'Const LocaleUSA = 1033
dNow = Now()

' Set global variables.
Set g_objFS = CreateObject("Scripting.FileSystemObject")
Set g_objShell = CreateObject("WScript.Shell")
Set g_objRegister = CreateObject("Scripting.Dictionary")
Set g_intLocale = SetLocale(LocaleUSA)

g_strServerName = UCase(g_objShell.ExpandEnvironmentStrings("%COMPUTERNAME%"))
g_strServerIPAddress = GetIPAddress(g_strServerName)
g_strCurrentPath = g_objFS.GetAbsolutePathName(".")
g_strHosts = GetOutput("type %systemroot%\system32\drivers\etc\hosts")

' Establish location for log file.
g_strLogFolder = "C:\TJXLogs"
If Not g_objFS.FolderExists(g_strLogFolder) Then
End If
If Not WScript.Arguments.Named.Exists("Target") And Not WScript.Arguments.Named.Exists("Controller") Then
    g_strLogFile = g_strLogFolder & Chr(92) & "2EncryptLoggingLevelChange_" & DateSuffix() & ".log"
    If g_objFS.FileExists(g_strLogFile) Then
        Call g_objFS.DeleteFile(g_strLogFile, True)
    End If
'    g_strCSV = g_strLogFolder & Chr(92) & "PWRotationDeliveryResults.csv"
    g_strLogFile = g_strLogFolder & Chr(92) & "2EncryptLoggingLevelChange_" & DateSuffix() & "_Target.log"

End If

' Declare function variables.
Dim arrEnvType, blnEnvType

 ' Determine software environment.
    blnEnvType = False
    arrEnvType = Array("DEV", "QA", "PROD")
    If WScript.Arguments.Named.Exists("EnvType") Then
        For Each g_strEnvType In arrEnvType
            If UCase(WScript.Arguments.Named("EnvType")) = g_strEnvType Then
                Call WriteToLog("Software environment marked as" & Chr(32) & EnvType(g_strEnvType) & ".")
                blnEnvType = True
                Exit For
            End If
    End If
	' Software environment must be detected to proceed.
    If Not blnEnvType Then
        Call WriteToLog("Error: Software environment type not recognized or specified as an argument.")
        Call WriteToLog("Aborting installation script.")
        Main = 6
'        Exit Function
    End If

' Windows 2008 requires reboot, so the script is allowed to run before 8 AM OR after 11 PM OR manually at any time of the day
If EnvType(g_strEnvType) = "Production" Then
  If  g_objFS.FileExists("C:\Windows\System32\ServerManagerCmd.exe") Then
	Call WriteToLog("Windows 2008 require reboot to complete the 2Encrypt Logging Level Change")
	If DatePart("h",Now()) > 8 Then

	  If DatePart("h",Now()) < 23 Then
		Call WriteToLog("The script is not allowed to run during business hours ie 8 AM to 11 PM, checking if it is a manual install")
			If WScript.Arguments.Named.Exists("Now") Then
				Call WriteToLog("Running the script manually to overcome the time restriction")
				Call WriteToLog("Manual install switch is missing, exiting the script")
				Main = 2
'				Exit Function
			End If
	  End If
		Call WriteToLog("The script is running on off-business hours")
	End If
  End If
End If

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, the code contains a whole bunch of calls to a WriteToLog procedure, but that procedure does not exist in the code.

Have you forgotten to include that procedure, or do you need one written?



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David Johnson, CD, MVPOwnerCommented:
more missing functions:

poor testing
If  g_objFS.FileExists("C:\Windows\System32\ServerManagerCmd.exe") Then
      Call WriteToLog("Windows 2008 require reboot to complete the 2Encrypt Logging Level Change")

use some code from this get-os-info.vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo "Boot Device: " & objOperatingSystem.BootDevice
    Wscript.Echo "Build Number: " & objOperatingSystem.BuildNumber
    Wscript.Echo "Build Type: " & objOperatingSystem.BuildType
    Wscript.Echo "Caption: " & objOperatingSystem.Caption
    Wscript.Echo "Code Set: " & objOperatingSystem.CodeSet
    Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode
    Wscript.Echo "Debug: " & objOperatingSystem.Debug
    Wscript.Echo "Encryption Level: " & objOperatingSystem.EncryptionLevel
    dtmConvertedDate.Value = objOperatingSystem.InstallDate
    dtmInstallDate = dtmConvertedDate.GetVarDate
    Wscript.Echo "Install Date: " & dtmInstallDate
    Wscript.Echo "Licensed Users: " & _
    Wscript.Echo "Organization: " & objOperatingSystem.Organization
    Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage
    Wscript.Echo "OS Product Suite: " & objOperatingSystem.OSProductSuite
    Wscript.Echo "OS Type: " & objOperatingSystem.OSType
    Wscript.Echo "Primary: " & objOperatingSystem.Primary
    Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser
    Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber
    Wscript.Echo "Version: " & objOperatingSystem.Version
wscript.echo GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").AddressWidth

Open in new window

David Johnson, CD, MVPOwnerCommented:
are you trying to change the hosts file? or read the hosts file ?
SDJ_1Author Commented:
I've requested that this question be deleted for the following reason:

issue has been resolved
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.