hopefully this will be an easy one? I've got a VBS file which I am trying to schedule every week to do a XML refresh. It simply calls an ASPX page. But I cannot get the thing to work! Even when I try to double click the VBS file I just get an error message. The actual code can be found all over the place - it seems to be standard code for this purpose.
The code is (fetch.vbs)
Call LogEntry()
Sub LogEntry()
'Force the script to finish on an error.
On Error Resume Next
'Declare variables
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XMLHTTP")
'Put together the URL link appending the Variables.
URL = "http://mywebsite/fetchXML.aspx"
'Open the HTTP request and pass the URL to the objRequest object
objRequest.open "POST", URL , false
'Send the HTML Request
objRequest.Send
'Set the object to nothing
Set objRequest = Nothing
End Sub
The error message I get from windows (when I double click the VBS file is)
Script: fetch.vbs
Line: 1
Char: 1
Error: Invalid Character
Code: 800A0408
Source: Microsoft VBScript Compilation Error
Any ideas?!
Problem was solved by saving as ANSI format (not UTF-8 as default)
ref: VBScript Invalid Character 800A0408 compilation error
it looks like it may be the encoding. especially for line 1 char 1.
Related
I am working on making a simple vbs that will open and close an excel file and save as it closes. This is to update the values inside the excel file after they are modified by a separate python script, and I need to do it this way for many dumb reasons outside my control.
I don't have a lot of experience with VBS but what I researched about this, I don't see the error in my code. However, I get an error whenever I try to run the code below. There error is:
Line: 7
Char: 39
Error: Expected statement
Code: 800A0400
Source: Microsoft VBScript compilation error
Any help would be appreciated, thanks!
dim fso
set fso = CreateObject("Scripting.FileSystemObject")
if(fso.FileExists("C:\Users\Public\Documents\Templates\testfile.xlsx")) then
set xlapp = createobject("Excel.Application")
xlapp.Workbooks.Open "C:\Users\Public\Documents\Templates\testfile.xlsx"
xlapp.ActiveWorkbook.SaveAs Filename:="C:\Users\Public\Documents\Templates\testfile_test.xlsx", FileFormat:=51, ConflictResolution:=2
xlapp.ActiveWorkbook.Close SaveChanges:=True
end if
If you are using standalone VBS, the following lines won't work because VBS isn't VBA. VBA supports Named Argument Syntax in function calls whereas its not supported by VBS
xlapp.ActiveWorkbook.SaveAs Filename:="C:\Users\Public\Documents\Templates\testfile_test.xlsx", FileFormat:=51, ConflictResolution:=2
xlapp.ActiveWorkbook.Close SaveChanges:=True
You have to provide the arguments to the function. So Function ArgName:=ArgValue becomes Function ArgValue
xlapp.ActiveWorkbook.SaveAs "C:\Users\Public\Documents\Templates\testfile_test.xlsx",51,,,,,,2
xlapp.ActiveWorkbook.Close True
I am trying to run a VBScript but CFExecute throws an error
<cfexecute name = "C:\Windows\System32\CScript.exe"
arguments = "//NoLogo D:\Excel.vbs D:\test.xls"
variable = "data"
timeout = "100">
</cfexecute>
<cfdump var="#data#">
Error:
Error: 424 Source: Microsoft VBScript runtime error Description: Object required
But when I run the VBScript with CMD it works fine
C:\Windows\System32 > cscript //nologo D:\Excel.vbs D:\test.xls
I have full admin access, so why am I getting this error?
It was due to bug in the Windows 2008 server.
For office automation (accessing via script and non-window based operation) we have to add a "Desktop" folder inside
C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\system32
I added it and found success.
Create a vbscirpt file (.vbs). The code content would have the task you want to achieve.
The below example contains the vbscript file, that refreshes the excel and the cfm which executes the vbscript.
Sample vbscript file code:-
Set fso = CreateObject("Scripting.FileSystemObject")
Set xl = CreateObject("Excel.Application")
xl.Visible = True
For Each f In fso.GetFolder("C:\inetpub\WebSites\Upload\").Files
If LCase(fso.GetExtensionName(f.Name)) = "xlsx" Then
Set wb = xl.Workbooks.Open(f.Path)
wb.RefreshAll
wb.Save
wb.Close
End If
Next
xl.Quit
Sample cfm file code:-
<cfexecute name = "C:\Windows\System32\cscript.exe" arguments = "C:\inetpub\WebSites\CSAT\test.vbs">
</cfexecute>
I have windows hosting and it uses plesk. I want to make http request in every 30 mintues. I have written a vbs script to do this. Below you can see the code. But I am wondering what to write in "Path to executable file" field.
Also I set "Arguments" field as /httpdocs/scripts/web_visit_script.vbs
Here is vbs file code:
Call Send_HTTP_Request()
Sub Send_HTTP_Request()
'Force the script to finish on an error.
On Error Resume Next
'Declare variables
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XMLHTTP")
'Put together the URL link appending the Variables.
URL = "http://www.google.com"
'Open the HTTP request and pass the URL to the objRequest object
objRequest.open "POST", URL , false
'Send the HTML Request
objRequest.Send
'Set the object to nothing
Set objRequest = Nothing
End Sub
Technically c:\windows\syswow64\cscript.exe should be enough as the path to the executable. If that is not enough then I recommend making a .bat file in that scripts folder with the following code: c:\windows\syswow64\cscript.exe web_visit_script.vbs and then simply call that .bat file in the path to executable with no arguments.
Thanks,
Sean W.
I'm trying to print to the browser screen the Absolute Path of the current directory using Classic ASP. (equivalent to PHP's echo command).
I'm getting this error on the last line of the code below:
"Microsoft VBScript runtime error '800a01a8'
Object required: 'Document'
/Research/ro.asp, line 17"
I've tried a couple different methods to print to the screen (Like WScript.StdOut.Write) and they return the same error as well.
I suspect that my error has something to do with the fact that it is an object, and objects require a different method of printing to the screen.
Any thoughts on this from anyone?
samplefile.asp=
<%
Dim szCurrentRoot: szCurrentRoot= ""
'Create the File System Ojbect
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Get the Absolute Path of the current directory
szCurrentRoot = objFSO.GetParentFolderName(Server.MapPath(Request.ServerVariables("URL")))
'Print to the screen. The following line is line 17 which causes the error
Document.Write(szCurrentRoot)
%>
After some more research, I found the answer to my question:
Response.Write(szCurrentRoot)
This way of writing to the browser screen was successful.
<%
Dim szCurrentRoot: szCurrentRoot= ""
'Create the File System Ojbect
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Get the Absolute Path of the current directory
szCurrentRoot = objFSO.GetParentFolderName(Server.MapPath(Request.ServerVariables("URL")))
'Print to the screen.
Response.Write szCurrentRoot
%>
Response.Write is the way to send text data back to the client. Use <% %> is a shortcut to this method.
You can't print to the screen from ASP, you can only write a response back to the browser, using Response.Write Server.EncodeHTML(szCurrentRoot) or the shorthand <%=Server.EncodeHTML(szCurrentRoot) %> if you are not inside a code block.
Yea Document is not implicitly defined if you are running this from the command line
eg.
cscript whatever.vbs
If you were to run this script inside of IE in a you would have access to "document"
Try doing this
Set ie = CreateObject(“InternetExplorer.Application”)
ie.document.write(szCurrentRoot)
I am getting error in scheduled task :"http://localhost:4625/DataUpdater.aspx.Error Message:Object reference not set to an instance of an object."
Scheduledtask vbs script :
Call LogEntry()
Sub LogEntry()
On Error Resume Next
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XMLHTTP")
URL = "http://localhost:4625/DataUpdater.aspx"
objRequest.open "POST", URL , false
objRequest.Send
Set objRequest = Nothing
End Sub
If the error is coming back from Cassini/IIS then you should post the code in the .aspx / .aspx.cs file, and the line the error is occurring on.
Have you tried to use a batch file to do this?
For example here are some sample run lines:
cscript.exe c:\scripts\call_logs.vbs
Or:
script.exe c:\scripts\call_logs.vbs
Here is one that I use to archive off IIS Logs:
C:\WINDOWS\system32\wscript.exe D:\scripts\list.vbs