SBS2003 Logon Script Error

Discussion in 'Scripting' started by Justin Herbert, Nov 18, 2011.

  1. Hi all - I have a logon script that maps drives and sets up Outlook
    signatures for our users that has been working perfectly for several
    years for many users on many different PCs accross many different
    OS's. All of a sudden I'm getting an error on just one users WinXP PC.
    (The script runs fine on all other XP machines).

    Windows Script Host
    Script: \\RCNET\NETLOGON\XPLogSig.vbs
    Line: 23
    Char: 1
    Error: ActiveX component can't create object:
    'Scripting.FileSystemObject'
    Code: 800A01AD
    Source: Microsoft VBScript runtime error

    it's the "Set fso = CreateObject("Scripting.FileSystemObject")" line
    that seems to be causing the error.

    Anyone got any ideas?

    Rem Automatic Log & Signature Copy Routine - JPH -23/02/09
    Const SigMasterLocation = "\\rcnet\common\Signatures"
    Const SigFileName = "RC-"
    Const SigFileName2 = "NOTUSED-"
    Const SigFileName3 = "KMR-"
    Const SigProfileLocation = "\Application Data\Microsoft\Signatures"
    Const LocalLogFileName = "C:\OnLog.Log"
    Const NetworkLogFileName = "\\rcnet\Logs$\NetOnLog.Log"

    Set WshShell = WScript.CreateObject("WScript.Shell")
    rc = WriteLogonInfo() 'Returns true if logon succeeds.
    if rc = "Ok" then
    WshShell.LogEvent 0, "Logon & Signature Script Completed Successfully"
    else
    WshShell.LogEvent 1, "Logon & Signature Script failed - " + vbcrlf +
    rc
    end if

    Function WriteLogonInfo()
    WriteLogonInfo = "Ok"
    Dim WshNetwork
    Set WshNetwork = CreateObject("WScript.Network")
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    LogInfo = WriteLogEntry(LocalLogFileName)
    If LogInfo <> "Ok" Then
    WriteLogonInfo = "Local Log Failure" + vbcrlf + LogInfo
    End If

    LogInfo = WriteLogEntry(NetworkLogFileName)
    If LogInfo <> "Ok" Then
    WriteLogonInfo = "Network Log Failure" + vbcrlf + LogInfo
    End If

    Rem ** Check If there's a user outlook signature directory **
    Set WshShell = WScript.CreateObject("WScript.Shell")
    strStartMenu = WshShell.SpecialFolders("StartMenu")
    strProfileDir = Left(strStartMenu,(Len(strStartMenu)-11))
    strSigDir = strProfileDir + SigProfileLocation

    If Not folderExists(strSigDir) Then
    Set f = fso.CreateFolder(strSigDir)
    End If

    Rem ** If User Signature is found, Then Copy it, Else Log **
    If fileExists(SigMasterLocation + "\" + SigFileName +
    WshNetwork.UserName + ".htm") Then
    fso.CopyFile SigMasterLocation + "\" + SigFileName +
    WshNetwork.UserName + ".htm", strSigDir + "\" , True
    Else
    WriteLogonInfo = "Signature File Not Found" + vbcrlf + "Request
    Generation Of New Signature"
    End If
    Rem ** If User Signature2 is found, Then Copy it, Else Log **
    If fileExists(SigMasterLocation + "\" + SigFileName2 +
    WshNetwork.UserName + ".htm") Then
    fso.CopyFile SigMasterLocation + "\" + SigFileName2 +
    WshNetwork.UserName + ".htm", strSigDir + "\" , True
    Else
    WriteLogonInfo = "Signature2 File Not Found" + vbcrlf + "Request
    Generation Of New Signature"
    End If
    Rem ** Purposely flawed Signature3 code to output test data string **
    If fileExists(SigMasterLocation + "\" + SigFileName3 + ".htm") Then
    fso.CopyFile SigMasterLocation + "\" + SigFileName3 + ".htm",
    strSigDir + "\" , True
    Else
    WriteLogonInfo = "Signature3 File Not Found" + vbcrlf + "Request
    Generation Of New Signature"
    WriteLogonInfo = "XPLogSig Tried to access: " + strSigDir + vbcrlf +
    LogInfo
    End If
    End Function

    Function fileExists(sFilePath)
    Dim fso, bReturn
    Set fso = CreateObject("Scripting.FileSystemObject")
    bReturn = fso.FileExists(sFilePath)
    fileExists = bReturn
    End Function

    Function folderExists(sFolderPath)
    Dim fso, bReturn
    Set fso = CreateObject("Scripting.FileSystemObject")
    bReturn = fso.FolderExists(sFolderPath)
    folderExists = bReturn
    End Function

    Function WriteLogEntry(LogFileName)
    On Error Resume Next
    WriteLogEntry = "Ok"

    Dim WshNetwork
    Set WshNetwork = CreateObject("WScript.Network")
    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso_OpenTextFile(LogFileName, ForAppending, True)

    If Err<>0 Then
    WriteLogEntry = Err.Description
    Err.clear
    End If

    f.Write "<LOGON>" + vbcrlf
    f.Write "<DATE>"+ CStr(Now) + "</DATE>" + vbcrlf
    f.Write "<COMPUTERNAME>" + WshNetwork.ComputerName + "</COMPUTERNAME>"
    + vbcrlf
    f.Write "<DOMAIN>" + WshNetwork.UserDomain + "</DOMAIN>" + vbcrlf
    f.Write "<USERNAME>" + WshNetwork.UserName + "</USERNAME>" + vbcrlf
    f.write "strStartMenu=" + WshShell.SpecialFolders("StartMenu") +
    vbcrlf
    f.write "strProfileDir=" + Left(strStartMenu,(Len(strStartMenu)-11)) +
    vbcrlf
    f.write "strSigDir=" + strProfileDir + SigProfileLocation + vbcrlf
    f.Write "</LOGON>" + vbcrlf
    f.Write vbcrlf
    f.Close
    On Error GoTo 0
    End Function
     
    Justin Herbert, Nov 18, 2011
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.