Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So basically I have this VBScript that opens up an Excel 2010 instance, run a macro in it and close the spreadsheet. I am calling it using Scheduled Task to automate it. It ran beautifully when I was on Windows XP, but recently my company upgraded to Windows 7 and when I tried to schedule it using the new Task Scheduler in Windows 7, the task was stuck at running status but nothing was ever run if I choose Run whether user is logged in or not, with or without run with highest privileges checked. However if I use Run only when user is logged on, everything runs fine.

Here are a few things I've tried to test/verify the issue:

  1. The same script could be scheduled in Windows XP with the scheduled task, without the need for user to log on. The script itself, of course, would work when I double-clicked it.

  2. Another script that does not use Excel instance could be scheduled without any issue.

  3. I have created a .bat file to call the VBS script and use Windows task scheduler to schedule the bat file with no luck, the bat file is one line of code:

    C:\Windows\System32\CScript.exe //Nologo //B "C:\myscript.vbs"

    When I ran it, it showed the task was completed but nothing was ever launched nor run.

    Other things I have tried include using CMD as the program./script and /c start "" "C:\myscript.vbs" as the argument, or using C:\Windows\System32\CScript.exe as the program/script and //Nologo //B "C:\myscript.vbs" as the argument. All with no luck.

  4. Excel was not even launched in this case as I can see there is no additional Excel process in task manager.

  5. There seems to be an option to schedule the task in compatibility mode with Windows XP but when I tried to right click and select Properties, under General tab, the only thing I can see in Configure for: is Windows 7 and server 2008 R2, second option is Windows Vista and server 2008.

  6. My account has admin privileges on the PC.

Therefore, is there any way I can schedule this script somehow to run without the need of me to log on? I am open to any options. The PC is on Windows 7 Enterprise 64 bit with Excel 2010 installed.

Thanks in advance for your help!

share|improve this question
1  
When you run the script you need to elevate the script with elevated privilages to the administrator level. –  Ramhound May 23 '13 at 15:56
    
@Ramhound thanks for your message, I have already tried to run it with the Highest Privileges with no luck. –  zhuanyi May 23 '13 at 16:03
    
@huanyi - Please update your question on the process you used to do that exactly. Most people who ask these types of questions "It works on Windows XP but not Windows 7" forget that a great deal changed with Windows Vista and UAC which also effects Windows 7 which means that even the default Administrator user profile can have problems unless things are configured a certain way or a process is started the correct way. –  Ramhound May 23 '13 at 17:13
    
@Ramhound I am not sure I know what you mean, basically when I was using Windows XP, I was just scheduling a vb script to run at, say, 8am every morning, whether I am logged in or not is not important. UAC is not enabled on this PC running Windows 7 so it should not matter, and I have admin privileges as well. –  zhuanyi May 23 '13 at 18:43
    
Just because UAC is disabled doesn't change the fact you need to elevate the process if its required. –  Ramhound May 23 '13 at 19:34
show 1 more comment

1 Answer

up vote 1 down vote accepted

Fixing Group Policy problems by using log files

Enable Logging for Group Policy Object Editor Client Side Extensions

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon]
GPTextDebugLevel REG_DWORD 0x30002

0/ see logs:

 %windir%\debug\usermode\gptext.log

1/ 32-bit run vbscript:

%windir%\syswow64\cscript.exe "C:\myscript.vbs"

2/ Programs may be unable to access some network locations after you turn on User Account Control in Windows Vista or in Windows 7

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"EnableLinkedConnections" REG_DWORD 1

3/ Disable UAC

command line:

vbs-32.cmd ExcelSheetName.vbs ExcelSrc.xls

vbs-32.cmd:

SET WSH32=%windir%\SysWOW64\cscript.exe
%WSH32% %*

SheetName.vbs:

'Microsoft ActiveX Data Object 2.8 Library
'Microsoft ADO Ext. 2.8 for DDL And Security

Const ArrSize = 100
Dim ArrSheetName()
ReDim ArrSheetName(ArrSize)
IndexArr = 0

IF WScript.Arguments.Count = 0 Then
        WScript.Echo "Script Usage:"
        WScript.Echo "%windir%\SysWOW64\cscript.exe ExcelSheetName.vbs [Excel file full path]"
        WScript.Echo "%windir%\SysWOW64\cscript.exe ExcelSheetName.vbs D:\Office\ExcelSrc.xls"
       Wscript.Quit(10)
End If

Dim ExcelFileName
ExcelFileName=WScript.Arguments(0)

Dim ADOCatalog, ADOTable, ADODBConnection

Set ADOCatalog      = Createobject("ADOX.Catalog")
Set ADOTable        = Createobject("ADOX.Table")
Set ADODBConnection = CreateObject("ADODB.Connection")

Dim strConnString, strSheetName

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelFileName & ";Extended Properties=Excel 8.0;"

ADODBConnection.Open strConnString
Set ADOCatalog.ActiveConnection = ADODBConnection

For Each ADOTable In ADOCatalog.Tables
strSheetName = ADOTable.Name
strSheetName = Replace(strSheetName, "'", "")
strSheetName = Left(strSheetName, InStr(1, strSheetName,"$", 1)-1)
'Wscript.Echo strSheetName
ArrSheetName(IndexArr)=strSheetName
IndexArr=IndexArr+1

Next
ReDim Preserve ArrSheetName(IndexArr-1)

ADODBConnection.Close

Set ADOCatalog      = Nothing
Set ADOTable        = Nothing
Set ADODBConnection = Nothing

For Each ArrValue in ArrSheetName
    Wscript.Echo ArrValue
Next
share|improve this answer
    
Thanks for the reply, basically the files are local so I don't think the second option matters. However, for the first point, I guess for cscript, it does not matter for the 64 versus 32 bits right? (as long as my OS is 64 bit)? UAC is confirmed to be disabled and there is no graphical/pop-ups in the code. –  zhuanyi May 23 '13 at 18:46
    
@zhuanyi - Your question makes no sense. –  Ramhound May 23 '13 at 19:33
    
@Ramhound In the Option 1, STTR said I should run in 32 bit, but my argument is if my Windows is 64 bit, it does not matter if I run cscript in 32 or 64 bit right? Make sense now? –  zhuanyi May 23 '13 at 23:35
    
@zhuanyi Some Office COM objects not in the 64-bit implementation and database provider. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelFileName & ";Extended Properties=Excel 8.0;" ADOX.Catalog, ADOX.Table ... see code sample. –  STTR May 24 '13 at 3:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.