locked
Windows 2008 R2 64 bit vbs script is not run in Task Scheduler RRS feed

  • Question

  • Good day! 
    There is a script that at a certain point opens excel, says there is something, saves and closes. 
    Does not work in 2008 scheduler mode to perform regardless of the user's registration (ie, the script should run when the PC no one registered), if you run your hands or in the Run mode only for the registered user oki-all 
    Here is a sample text of the script:

    checkosx86x64args()
    
    Dim conn
    Set conn = CreateObject("ADODB.Connection")
    conn.ConnectionString = "Provider=MSDAORA.1;Password=пароль;User ID=логин;Data Source=база;Persist Security Info=True"
    conn.Open
    
    
    Set Recordset = CreateObject("ADODB.Recordset")
    Recordset.CursorLocation = 3
    Recordset.Open "текст запроса", conn, 2, 3, 1
    
    If Recordset.RecordCount = 0 Then 
    Recordset.Close: Call Pochta
    else
    Incas = Recordset.GetRows 
    Recordset.Close
    End if
    
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkBook = objExcel.Workbooks.Open("*.xlsx")
    
    DateNow = Left(Now(),10)
    DateTimeNow1 = CDate(DateNow + " " + "14:00:00")
    DateTimeNow2 = CDate(DateNow + " " + "21:00:00")
    'DateTimeNow3 = CDate(DateNow + " " + "23:30:00")
    'objExcel.Range("A1:F1").Merge - объединение ячеек
    objExcel.Range("A1:F1") =  Empty  ' очистка объединенных ячеек
    
    If Now < DateTimeNow1 Then 
    objExcel.Range("A1:F1").Value = "Текст " + DateNow + " с 05:00:00 до 06:45:00"
    ElseIf Now < DateTimeNow2 Then 
    objExcel.Range("A1:F1").Value = "Текст  " + DateNow + " с 14:00:00 до 16:30:00"
    Else objExcel.Range("A1:F1").Value = "Текст  " + DateNow + " с 21:00:00 до 23:30:00"
    End If
    
    For j = 3 To 100 Step 1
        objExcel.Cells(j, 1).Clear
        objExcel.Cells(j, 2).Clear
        objExcel.Cells(j, 3).Clear
        objExcel.Cells(j, 4).Clear
        objExcel.Cells(j, 5).Clear
        objExcel.Cells(j, 6).Clear
    Next
    
    intRow = 3
    i = 0
        
        For f = 0 To UBound(Incas, 2)
        AZS = Incas(0, f)
        nTo = Incas(1, f)
        Term = Incas(2, f)
        DataIn = Incas(3, f)
        Addres = Incas(4, f)
        Phone = Incas(5, f)
            objExcel.Cells(intRow,1).Value = AZS
            objExcel.Cells(intRow,2).Value = nTo
            objExcel.Cells(intRow,3).Value = Term
            objExcel.Cells(intRow,4).Value = DataIn
            objExcel.Cells(intRow,5).Value = Addres
            objExcel.Cells(intRow,6).Value = Phone
            intRow = intRow + 1
        Next
    
    'For k = 0 To 6
    '    objExcel.Columns(k + 1).AutoFit
    'Next
    
    
    objExcel.DisplayAlerts = False
    objExcel.ActiveWorkbook.SaveAs("*.xlsx")
    objExcel.DisplayAlerts = True
    objexcel.Quit
    conn.Close
    
    Wscript.Sleep(180)
    Call OtpravkaPochti
    
    Recordset = ""
    conn.Close
    '------------------------Процедура отправки почты если есть запись в таблице-----------------------------------------
    
    Sub OtpravkaPochti()
        Const EmailFrom = "почта"    
    
    Const EmailPassword = "пароль"  
    
    Const strSmtpServer = "сервер"  
    
    Const EmailTo = "адресаты"   
    ' Кому будет отправляться e-mail
    Const AttFile = "*.xlsx"        'Указываем путь к файлу, который необходимо вложить в сообщение
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = EmailFrom
    objEmail.To = EmailTo
    objEmail.Subject = "текст"
    objEmail.Textbody = "текст"
    objEmail.AddAttachment(AttFile) 
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = EmailFrom
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = EmailPassword
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmtpServer
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/languagecode") = 1049
    
    objEmail.BodyPart.CharSet = "windows-1251"
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext") = true
    objEmail.Configuration.Fields.Update
    objEmail.Send
    WScript.Quit
    
    End Sub
    
    '------------------------Процедура отправки почты если нет записей в таблице-----------------------------------------
    
    Sub Pochta()
         
    
    End Sub
    
    sub checkosx86x64args()
    ' если скрипт запущен из %windir%\system32\ под win x64 - перезапуск из %windir%\syswow64\
    dim cmdln, arg
    with createobject("WScript.Shell")
    if replace(lcase(wscript.path), lcase(.expandenvironmentstrings("%windir%\")), "") = "system32" then
    cmdln = replace(lcase(wscript.fullname), "system32", "syswow64")
    if createobject("scripting.filesystemobject").fileexists(cmdln) then
    cmdln = cmdln & " """ & wscript.scriptfullname & """"
    for each arg in wscript.arguments
    cmdln = cmdln & " """ & arg & """"
    next
    .run cmdln
    wscript.quit
    end if
    end if
    end with
    end sub

    Please help me with a problem.

    Please help me with a problem.
    Thursday, October 2, 2014 9:15 AM

Answers

  • Hi Liveofan,

    COM calls into an Excel.application ofbject fails on Windows 2008 R2. It's because it's trying to access a bound directory - C:\Windows\SYSWOW64\config\systemprofile\desktop\

    If you simply create the folder C:\Windows\SYSWOW64\config\systemprofile\desktop\ - It should Work, i had the exact same problem once.

    If it does not fix it, create the directory on both the system folders:

    C:\Windows\SYSWOW64\config\systemprofile\desktop\

    C:\Windows\System32\config\systemprofile\desktop\


    All the best, Jesper Hassing - MCTS SCCM 2012 - MCSA 2012 Server - MCP

    • Proposed as answer by Jesper Hassing Tuesday, October 7, 2014 6:44 AM
    • Marked as answer by Liveofan Tuesday, October 7, 2014 7:11 AM
    Tuesday, October 7, 2014 6:44 AM

All replies

  • 1. Does this script run in interactive mode?

    2. Have you tried to run in command task mode? It allows for for possibilities.

    3. Are parameters correct (correct operating system, priviledged mode, user account,...)

    4. What messages are in logs (history)

    5. Include test printouts in your script to check where the problem is.

    HTH

    Milos

    • Marked as answer by Liveofan Friday, October 3, 2014 8:26 AM
    • Unmarked as answer by Liveofan Friday, October 3, 2014 8:39 AM
    Thursday, October 2, 2014 12:41 PM
  • Download ProcessMon and open on the computer where you scheduled the task.

    http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

    Enable filter (Ctrl+L) and type the name of your vbs file in the Path and make sure to select contains in the Relation drop down.

    Adjust the schedule to run in the next few min and let us know what you see in Process Monitor?

    Can you post a screen shot of your scheduled task configuration window?


    • Edited by net_tech Thursday, October 2, 2014 3:17 PM
    Thursday, October 2, 2014 3:16 PM
  • 1. Yes, 

    If the user is logged. Script of scheduled tasks to run fine. 
    When not logged in user, the job is not performed on schedule and is in the process of hanging the Excel process

    2. Strart script: csript.exe C:\VBS\*.vbs

    3. Yes, user account - Administrator

    4. Errors, there is no

    5. The script itself is working on Windovs 2003 carried out assigned tasks without problems.

    Friday, October 3, 2014 8:34 AM
  • Friday, October 3, 2014 8:36 AM
  • Please go to the Action tab click Edit on your task and post Edit Action screen

    You can also try fill in "Start in" directory and if the task still fails switch the Run as to the SYSTEM account


    • Edited by net_tech Friday, October 3, 2014 11:02 AM
    Friday, October 3, 2014 10:52 AM
  • Please go to the Action tab click Edit on your task and post Edit Action screen

    You can also try fill in "Start in" directory and if the task still fails switch the Run as to the SYSTEM account


    How to start Run from SYSTEM account?

    Monday, October 6, 2014 2:28 AM
  • Please fill in "Start in" directory  with "C:\VB" ("Рабочая папка") in your case.
    • Edited by net_tech Monday, October 6, 2014 2:50 AM
    Monday, October 6, 2014 2:50 AM
  • http://superuser.com/questions/347751/how-can-i-run-a-scheduled-task-as-system

    under the system account does not work.

    Under my account when I logged in, works

    Monday, October 6, 2014 4:54 AM
  • try this.

    create a batch file and place it in your C:\VBS folder.

    inside your batch file type

    C:\Windows\System32\cscript.exe C:\VBS\OtchentInkassTpk.vbs

    disable your task and create a new task where you use the BAT file without any arguments and don't forget to fill in "Start in" directory. Give it a shot. If the task does not run change your batch file to

    c:\Windows\SysWOW64\cscript.exe C:\VBS\OtchentInkassTpk.vbs and try again.

    Come back with results.

    Monday, October 6, 2014 12:57 PM
  • The last reply in this thread might be helpful:

    http://social.technet.microsoft.com/Forums/en-US/31f329ce-0862-435e-94a5-9f53578f9466/powershell-script-running-excel-wont-run-on-windows-server-2008-r2?forum=winserverpowershell

    Basically, the local system account is not configured for Excel.


    Richard Mueller - MVP Directory Services

    Monday, October 6, 2014 1:54 PM
  • try this.

    create a batch file and place it in your C:\VBS folder.

    inside your batch file type

    C:\Windows\System32\cscript.exe C:\VBS\OtchentInkassTpk.vbs

    disable your task and create a new task where you use the BAT file without any arguments and don't forget to fill in "Start in" directory. Give it a shot. If the task does not run change your batch file to

    c:\Windows\SysWOW64\cscript.exe C:\VBS\OtchentInkassTpk.vbs and try again.

    Come back with results.

    The script is not satisfied
    Tuesday, October 7, 2014 6:28 AM
  • The last reply in this thread might be helpful:

    http://social.technet.microsoft.com/Forums/en-US/31f329ce-0862-435e-94a5-9f53578f9466/powershell-script-running-excel-wont-run-on-windows-server-2008-r2?forum=winserverpowershell

    Basically, the local system account is not configured for Excel.


    Richard Mueller - MVP Directory Services

    did not help (
    Tuesday, October 7, 2014 6:29 AM
  • Hi Liveofan,

    COM calls into an Excel.application ofbject fails on Windows 2008 R2. It's because it's trying to access a bound directory - C:\Windows\SYSWOW64\config\systemprofile\desktop\

    If you simply create the folder C:\Windows\SYSWOW64\config\systemprofile\desktop\ - It should Work, i had the exact same problem once.

    If it does not fix it, create the directory on both the system folders:

    C:\Windows\SYSWOW64\config\systemprofile\desktop\

    C:\Windows\System32\config\systemprofile\desktop\


    All the best, Jesper Hassing - MCTS SCCM 2012 - MCSA 2012 Server - MCP

    • Proposed as answer by Jesper Hassing Tuesday, October 7, 2014 6:44 AM
    • Marked as answer by Liveofan Tuesday, October 7, 2014 7:11 AM
    Tuesday, October 7, 2014 6:44 AM
  • Hi Liveofan,

    COM calls into an Excel.application ofbject fails on Windows 2008 R2. It's because it's trying to access a bound directory - C:\Windows\SYSWOW64\config\systemprofile\desktop\

    If you simply create the folder C:\Windows\SYSWOW64\config\systemprofile\desktop\ - It should Work, i had the exact same problem once.

    If it does not fix it, create the directory on both the system folders:

    C:\Windows\SYSWOW64\config\systemprofile\desktop\

    C:\Windows\System32\config\systemprofile\desktop\


    All the best, Jesper Hassing - MCTS SCCM 2012 - MCSA 2012 Server - MCP

    Thank you very much. 
    That solved the problem
    Tuesday, October 7, 2014 7:12 AM
  • Thank you very much Jesper for sharing this. My program also calls Excel.application in the script and it was never working after we moved the script to Win 2008 R2 server. After creating these 2 folders, it started working.

    C:\Windows\SYSWOW64\config\systemprofile\desktop\

    C:\Windows\System32\config\systemprofile\desktop\





    Monday, April 6, 2015 4:03 PM