1

I have a very simple VBA script that I am running on Windows Server 2012. It creates an Excel Object, writes to two cells, saves the sheet as a CSV, and closes the Workbook and the Application, and then quits the Excel Object.

This works on Server 2003 without any issues.

When I run the script on Server 2012 R2, the Excel Object Process continues running and has to be terminated manually through task manager.

As I understand, the Excel application is running in Session-0, preventing the object from being closed by the script running in the user session. Additionally, if I alter the script to create the file and save/close the object then re-open the Excel file, it is unable to write to the file as again, it's in Session-0.

When the script runs, it creates an error in the error log of:

Service Control Manager Event 2073: The Interactive Services Detection 
service terminated with the following error: Incorrect function.

The script is as follows:

set fso = CreateObject("Scripting.FileSystemObject")
currDir = fso.GetParentFolderName(Wscript.ScriptFullName)

outputFile = currDir & "\ExcelTest.csv"

set objExcel = CreateObject("Excel.Application")
set ExcelWorkbook= objExcel.workbooks.add()
objExcel.application.visible = false
objExcel.application.displayalerts =false
set objExcelWorksheet = objExcel.worksheets(1)

objExcelWorksheet.Cells(1, 1).Value = "Foo"
objExcelWorksheet.Cells(1, 2).Value = "Bar"


ExcelWorkbook.saveas outputFile,23

ExcelWorkbook.close  false

objExcel.application.quit

objExcel.quit

set objExcel = nothing  

I am looking for either a way to force the Excel object to open in the User Session, or somehow be able to control/access that Excel object. The above code is a simplified snippet of a larger script which opens and closes multiple CSV files, and as such I do need the ability to access those Excel objects.

Caveats: I have no access or ability to change the registry, nor install any third-party applications. Security is tight as we are a HealthCare-related shop.

Community
  • 1
  • 1
RJohnson
  • 166
  • 2
  • 10
  • Have you tried to see if you can do a runas in that session 0? Something like `runas /noprofile /user:DOMAIN\WHOEVER c:\Windows\Syswow64\cscript.exe c:\path\to\your\vbs\script.vbs` – Sean W. Apr 12 '17 at 21:00
  • I just tried, and it doesn't seem to like the formatting. I'm running from the drive and folder where the script lives, with a command of `runas /noprofile /user:DOMAIN\USERNAME c:\windows\syswow64\cscript.exe test.vbs` and it just provides the help page. I appreciate the help, though. – RJohnson Apr 12 '17 at 21:28
  • No problem putting double quotes around "c:\path\to\your\vbs\script.vbs" may help too. Good luck. – Sean W. Apr 12 '17 at 22:00

0 Answers0