none
VB Script must placed under system32 folder? RRS feed

  • Question

  • As to monitor our server, we wrote a batch which runs a vb script which passes the trigger from Performance Monitor. When the alert is triggered, an sms will be send to our staff for notification.

    Here is our batch file content:
    ==================================================
    %windir%\system32\wscript.exe "SendEmail.vbs" %1
    ==================================================

    Here is our vb script:
    ==================================================
      'Body of email message
       Dim msgBody
       msgBody=WScript.Arguments.Item(0)

       'Call our function with recipient, message and subject
       MySendMail "12345678@bulksms.net",msgBody,"ser190"

       Sub MySendMail(recipient,msg,subject)
        sch = "http://schemas.microsoft.com/cdo/configuration/"
     
        Set cdoConfig = CreateObject("CDO.Configuration")
     
        With cdoConfig.Fields
            .Item(sch & "sendusing") = 2 ' cdoSendUsingPort
            .Item(sch & "smtpserver") = "localhost"
            .Item(sch & "smtpserverport") = "25"
       .Item(sch & "smtpauthenticate") = 1 'cdoBasic
       .Item(sch & "sendusername") = "user"
       .Item(sch & "sendpassword") = "pwd"
            .update
        End With
     
        Set cdoMessage = CreateObject("CDO.Message")
     
        With cdoMessage
            Set .Configuration = cdoConfig
            .From = "server@company.com"
            .To = recipient
            .Subject = subject
            .TextBody = msg
            .Send
        End With
     
        Set cdoMessage = Nothing
        Set cdoConfig = Nothing

       End Sub
    ================================================== 

    We set the alert as running the batch file and the alert passed, to the vb script and finally send a sms to our staff. But I found a weired thing is, when I place two files under any of the directory (For example: c:\a\), the performance monitor can detect and trigger the event, but cannot send the sms out; if we place the vb script file under the folder 'C:\Windows\System32', the alert can be triggered and the sms can be sent. We have vertified that it should not be the problem of the premission of the user/script issue. Could anyone help us?

    OS: Windows Server 2003 Standard Edition with Service Pack 1

    Thursday, March 26, 2009 6:18 AM

All replies

  • Hi Frank,

    this is probably because C:\Windows\System32 is in the %PATH% environment variable, so Windows will always be able to find your VBS if you place it there. If you modify your batch file (pointing to the complete VSB path), you would be abled to execute your VBS without placing it in the System32 folder:

    %windir%\system32\wscript.exe "C:\a\SendEmail.vbs" %1

    Or you could modify your batch like this (which I would advice; that way, you can store your scripts in any folder, as long as the VBS and Batch are in the same folder):
    -- START BATCH SCRIPT
    SET CurrentPath=%~dp0
    %windir%\system32\wscript.exe "%CurrentPath%SendEmail.vbs" %1
    -- END BATCH SCRIPT

    kind regards,
    Floris van der Ploeg
    Tuesday, April 21, 2009 8:15 PM