I have written a simple VBScript code which:
opens an Excel workbook
makes the Excel workbook visible
update the contents of Cell(1,1) of Sheet1 with the current system time
saves the Excel workbook
The code is as follows:
Option Explicit
Dim objExcel, objBook, objSheet, strPath
strPath = "C:\Users\a614923\Work Repository\Local\Test Complete\Working\05012019\bonn-6.11.9_Regression\FIL_REGRESSION\Stores\Files\ExternalDriver\Test.xlsx"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objBook = objExcel.Workbooks.Open(strPath)
Set objSheet = objBook.Sheets("Sheet1")
objSheet.Cells(1,1) = "Time: " & time
objBook.Save
'objBook.Close
'objExcel.Quit
When I run this VBScript file(directly by double-clicking, not via Jenkins), all the 4 steps mentioned above run fine.
When I run the same file via Jenkins, the following happens:
Excel workbook is opened
the contents of Cell(1,1) of Sheet1 are updated with the current system time
Excel workbook is saved
The issue is that the Excel workbook does not become visible. I have been stuck on this step for hours now. Today is the first time I am using Jenkins. Is there any Jenkins configuration that I am missing? Has anyone ever faced this issue?
I am running Windows batch command on Jenkins to achieve the same:
C:\Windows\SysWOW64\cscript.exe "C:\Users\a614923\Work Repository\Local\Test Complete\Working\05012019\bonn-6.11.9_Regression\FIL_REGRESSION\Stores\Files\ExternalDriver\TEST.vbs"
This is how my build console looks like after running the build:
Started by user Gurmanjot Singh
Building in workspace C:\Program Files (x86)\Jenkins\workspace\SuiteRunner
[SuiteRunner] $ cmd /c call C:\WINDOWS\TEMP\jenkins2976471610072523635.bat
C:\Program Files (x86)\Jenkins\workspace\SuiteRunner>C:\Windows\SysWOW64\cscript.exe "C:\Users\a614923\Work Repository\Local\Test Complete\Working\05012019\bonn-6.11.9_Regression\FIL_REGRESSION\Stores\Files\ExternalDriver\TEST.vbs"
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Jenkins\workspace\SuiteRunner>exit 0
Finished: SUCCESS
Any help/suggestion would be appreciated.
I took help from this answer
To solve the issue, I performed these steps:
Downloaded the generic war package from https://jenkins.io/download/
Ran the jenkins from command line using the command java -jar jenkins.war
Complete the Installation(configure proxy, if any; download plugins, credentials etc)
Entered the batch command
After clicking on Build now, I was able to see the excel getting launched.
Related
Set oShell = Server.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /C copy ""C:\inetpub\test\test.txt"" ""C:\inetpub\test\test2.txt"" ", 0, true
Hello, I try to run any command from an asp file on my Windows 2003 server but none of them work, my test page loads endlessly when it is executed.
I have already tried to put the pool application in local system but nothing changes.
Have you seen this before ?
Im trying to execute an Excel Macro via VBScript that run every 2 minutes via Windows Scheduler. For this macro work, I have installed an AddIn for Excel and for this AddIn work a program need to be open.
Currently, Im running this on a Windows Server 2019 on Amazon EC2, while Im logged via RDP connection everything runs fine, but while Im disconnect script executes every 2 minutes, the program is opened but the excel always fails and show this error:
Faulting application name: EXCEL.EXE, version: 16.0.13426.20404, time stamp: 0x5fdea4e7
Faulting module name: KERNELBASE.dll, version: 10.0.17763.1613, time stamp: 0xa4105fac
Exception code: 0xe0434352
Fault offset: 0x001225f2
Faulting process id: 0xe3c
Faulting application start time: 0x01d6e5f4ca9ab8c6
Faulting application path: C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: afc9ea7a-f38d-425b-addb-7781ad2b4e64
Faulting package full name:
Faulting package-relative application ID:
I was thinking the AddIn was causing the error, but i tried some things like uninstall AddIn after run Macro and before quit Excel, but the error still persist.
Set WshShell = WScript.CreateObject("WScript.Shell")
exeName = "C:\Program Files (x86)\BroadcastAgro\bcsys32.exe"
WshShell.Exec(exeName)
WScript.Sleep 5000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 15000
On Error Resume Next
'Input Excel File's Full Path
ExcelFilePath = "C:\Users\Administrator\Desktop\Pasta2.xlsm"
'Input Module/Macro name within the Excel File
MacroPath = "Planilha1.CommandButton1_Click"
'Create an instance of Excel
Set ExcelApp = CreateObject("Excel.Application")
'Do you want this Excel instance to be visible?
ExcelApp.Visible = False
'Prevent any App Launch Alerts (ie Update External Links)
ExcelApp.DisplayAlerts = False
'Open Excel File
Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)
ExcelApp.RegisterXLL "C:\Program Files (x86)\BroadcastAgro\Broadcast.AddIn64.xll"
ExcelApp.AddIns("Broadcast+").Installed = False
ExcelApp.AddIns("Broadcast+").Installed = True
ExcelApp.Cells(3, 2).Calculate
WScript.Sleep 30000
'Execute Macro Code
ExcelApp.Run MacroPath
'Reset Display Alerts Before Closing
ExcelApp.DisplayAlerts = False
ExcelApp.AddIns("Broadcast+").Installed = False
'Close Excel File
wb.Close False
'End instance of Excel
ExcelApp.Quit
ExcelApp.Quit
I really tried lot of things but still only work while Im in an active RDP connection
I am trying to execute an Excel VBA macro with a VBScript so that I can run it with cscript in batch. When I run it in Excel it works fine, but when I call the VBScript I get a permission error saying that create object is the cause.
I have tried rewriting the VBScript to no avail and it only works in Excel.
But the one that seems to be the most promising is below:
Option Explicit
On Error Resume Next
Sub ExcelMacro()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\MyWorkbook.xls", 0, True)
xlApp.Run "MyMacro"
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
The problem is that when I run it in the batch file, it shows that Windows starts to run it but then I get an error saying
Microsoft VBS runtime error: Permission denied Create Object.
How can I fix this?
After adding path "e.g. C:\Program Files\Java\jdk-11.0.5\bin" as PATH in System environment setting and doing restart of system has solved my issue.
I would like to write a function to create a windows .lnk file from my lua script. I found a function in the LuaFileSystem library . Is there a way to do this without the library? (The reason: I am writing the script for multiple users, would be nice if we don't have to install the library on every machine.)
I appreciate the help!
To make a shortcut (an .lnk file)
-- your .lnk file
local your_shortcut_name = "your_shortcut.lnk"
-- target (file or folder) with full path
local your_target_filespec = [[C:\Windows\notepad.exe]]
local ps = io.popen("powershell -command -", "w")
ps:write("$ws = New-Object -ComObject WScript.Shell;$s = $ws.CreateShortcut('"..your_shortcut_name.."');$s.TargetPath = '"..your_target_filespec.."';$s.Save()")
ps:close()
To make a symlink simply use os.execute"mklink ..."
Use luacom is faster than powershell
local luacom=require'luacom'
local shortcut_file_path='test_create_shortcut.lnk'
local target_file_path=arg[0]
local shellObject=luacom.CreateObject("WScript.Shell")
local shortcut=shellObject:CreateShortcut(shortcut_file_path)
shortcut.TargetPath=target_file_path
shortcut:Save()
assert(io.open(shortcut_file_path)):close()--shortcut file exist now
os.remove(shortcut_file_path)
And use FileSystemObject object (another COM), or Windows shell link file format spec for Kaitai Struct (parse binary file struct to get info on various file format) to retrieve shortcut info. Which 'lfs' can't do now.
see: Create a desktop shortcut with Windows Script Host - Windows Client | Microsoft Docs
LuaCOM User Manual (Version 1.3)
I have to run .vbs through classic asp. From past quite a few days, I am working on this, but still can't find a solution.
My code is as follows:
Set oWshShell = Server.CreateObject("WScript.Shell")
'sCmd = "%systemroot%\sysnative\cmd.exe"
'oWshShell.run "c:\windows\system32\cmd.exe", 1, TRUE
'oWshShell.run("%comspec% /c "C:\inetpub\wwwroot\sharedagents\print.vbs",1,TRUE)
'owshshell.run sCmd
Set oWshShell=Nothing
I tried all the methods that are commented out, but while executing the page, Browser/IIS hangs indefinitely. I have tried all sorts of variation to put in oWshShell, but still I am being able to put it through. I have checked permissions, Registry and all sorts other tweaks that can be possible.
Is it due 32-bit/64-bit issue or something else?
If you are running it on Windows 7 64-bit, your following code must be changed:
from:
'oWshShell.run "c:\windows\system32\cmd.exe", 1, TRUE
to:
'oWshShell.run "c:\windows\SysWOW64\cmd.exe", 1, TRUE
Also, verify if the cmd is running under administrator rules
Windows 7 x64: Execute a 64bit exe/script from a 32bit command prompt? may help you.