Please help,
my vbscript: saveGSheet.vbs (to download sheet) works fine when manually run. I woud like to automat this, but an automatic task will NOT download the file.
How to run this in Task Scheduler? On Windows Server 2008.
Task Scheduler - settings:
Action: Run program: saveGSheet.bat with code:
c:\Windows\SysWOW64\cscript saveGSheet.vbs
Run task as LOCAL SERVICE
Run task when NOT LOGGED IN
Tried already:
Run with highest privileges does not help
creating "Desktop" folders does not help
"Log on as a batch job" does not help
Possible reasons:
Not logged in means objects doesnt work properly - possibly needs to be run in interactive mode like MS Excel? I do not understand what in my script needs to be run interactive (logged in)?
"MSXML2.XMLHTTP.3.0"
"ADODB.Stream"
Vbscript:
' Set your settings
strFileURL = "https://docs.google.com/spreadsheets/d/1B5jBWGHT1dGKCwE9KLTlFsyymNCc1s4AH1LcFQOcwqQ/export?format=xlsx"
strHDLocation = "C:\file.xlsx"
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
'Response 200 is OK, now download sheet
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Note: I should not use any third party apps, so I dont use wget for example.
EDIT: Made log file as suggested, result:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\AppBackUpTools\ALM\NotifikaceVSE\SLA_Escalation\download_excel\saveGSheet.vbs(27, 3) ADODB.Stream: Write to file failed.
modify your saveGSheet.bat as below:
c:\Windows\SysWOW64\cscript saveGSheet.vbs > %temp%\saveGSheet.log 2>&1
after the task is executed, examine the content of the log file at %temp%\saveGSheet.log that should give you some clue to debug further
You have no rights to write there. Change the folder ie to the folder where you have vbscript.
Related
I'm trying to get classic asp / vbscript to run a less compiler (https://github.com/duncansmart/less.js-windows). Running the exact command from a real cmd prompt on the server works fine. So it's going to be one of those permissiony type things. My server is Win2003 x86 / IIS6.
<%
' foo.asp
outpath = "c:\inetpub\wwwroot\site\less"
cmd = "c:\less.js-windows-v1.6.2\lessc.cmd"
Set Shell = server.createobject("WScript.Shell")
nodeCommand = cmd & " " & outPath & "\app.less " & outPath & "\app.css"
errCode = Shell.Run(nodeCommand, 0, True)
' errcode = 1
%>
foo.asp is running somewhere on the web server, anonymously.
cmd.exe has had iusr_server added so that it has read and execute permission.
c:\less.js-windows-v1.6.2 has had iusr_server added with read/execute as well.
I've granted everyone permission to modify files in side c:\inetpub\wwwroot\site\less to make sure it's not a permission thing.
I have tried modifying my command to include CMD /C ahead of the command file name.
Use the following process:
Stop the server
Change relative paths to full paths for all files
Reconfigure the IUSR to be you
Restart the server
I have a very simple WMI test-script that I am running locally on a server to diagnose a problem I'm having getting WMI some data.
Essentially, all WMI queries I run on this machine (locally) fail with an error code 0x80041017.
Option Explicit
Dim WmiQuery
WmiQuery = "SELECT * FROM Win32_Processor"
Dim objSWbemLocator
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Dim objWMIService
Set objWMIService = objSWbemLocator.ConnectServer("localhost", "root\cimv2")
Dim results
Set results = objWMIService.ExecQuery (WmiQuery)
Dim row
For Each row in results
Next
I'm not even trying to view any properties yet, but it fails on line 16, which is the For Each row in results line.
Here's the output of running it in a console:
c:\test>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
c:\test\test.vbs(16, 1) (null): 0x80041017
Running that query through wbemtest gives the description "Invalid query", even though the same query runs on other servers. Is something not registered in WMI or something?
I think it may be to do with how you're getting your WMI object.
How about this:
Option Explicit
Dim wmi,col,itm
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set col = wmi.ExecQuery("Select * from Win32_Processor")
For Each itm in col
WScript.Echo itm.Name
Next
Set wmi = Nothing
Set col = Nothing
WScript.Quit
Seems to work for me... Don't think you need all the WBemLocator guff...
We moved from Windows Server 2003 ro Windows Server 2008 and our FileSystemObject script no longer works. Whenever we try to download a file 10-12 Mb it results in a short download, ie: sometimes only getting 15, 19 or 22 Mb of a 26 Mb file.
The server is set to allow downloads of 40+ Mb no problem and this has been confirmed by direct http downloads to the file in root level... tests of direct downloads on 32 Mb are successful 100% of the time. However we need to provide downloads of files that are stored below root, hence we need to use the FSO script.
We have used the script with success for a few years on Windows Server 2003 but lately we cannot get a full download from Windows Server 2008.
strChunkSize = 1024000*1
strDocFile = "someDocument.doc"
FPath = "C:\data\" & strDocFile
Response.Buffer = True
Response.Clear
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fl = fso.GetFile(FPath)
intFilelength = fl.size
adoStream.LoadFromFile(FPath)
Response.AddHeader "Content-Disposition", "attachment; filename=" & fl.name
Response.AddHeader "Content-Length", intFilelength
Response.AddHeader "Accept-Ranges", "bytes"
Response.ContentType = "application/octet-stream"
For i = 0 To adoStream.Size
i = i + strChunkSize
Response.BinaryWrite(adoStream.Read(strChunkSize))
Response.Flush
Next
adoStream.Close
Set adoStream = Nothing
I have checked out this topic intensively elsewhere and every example of a FSO download script fails, even when using chunks for any file larger than 4 Mb.
The problem in this case was script timeout which by default is only 90 seconds so large files were getting discontinued. To resolve the problem I added some script to set a time out proportional to the download and allowing for slow coaches...
if strDocFileSize <> "" then
strScriptTimeout = (strDocFileSize/1024000)*40
else
strScriptTimeout = 30000
end if
Server.ScriptTimeout = strScriptTimeout
I'm testing the responsiveness of a web application, and want to isolate any slow areas (database access, javascript, etc) and want to be sure that IIS Express isn't slowing things down by all its console output.
Is there a way of running IIS Express without that output, or even without the console being visible at all?
I've tried the /trace:error option, but it still outputs lines for every request.
the following should do the trick:
Create a VBScript: IIS-Express-silent.vbs
Dim App,Site
Site = "[YOUR SITE NAME]"
If Len(Site) < 1 Then
Site = WScript.Arguments(0)
End If
App = """%PROGRAMFILES%\IIS Express\iisexpress""" & _
" /site:" & Site
If Len(Site) > 0 Then
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run App, 0
Set WshShell = Nothing
End If
If you are running IIS Express only as localhost and you don't (intend to) use SSL then you are ready. Just add [YOUR SITE NAME] from applicationhost.config located in your user profile:
<sites>
<site name="[YOUR SITE NAME]" id="1" serverAutoStart="true">
...
</sites>
If you need elevated privileges you must create a second file in the same directory (VBScripts can't be run this way directly): Run-as-Administrator.bat
#echo off
pushd %~dp0
cscript IIS-Express-silent.vbs [YOUR SITE NAME]
Please leave Site in your VBScript blank then and add the name in your batch file instead.
Right mouse button - "Run as Administrator" - and you're done :-)
Scripters,
I am new to the VB-scripting world!
I would like to get the following done by scripting so that I can install Flash.
The steps are:-
1. Open Internet Options.
2. Click on “Connections” tab.
3. Click on “LAN Settings” button.
4. Deselect the “Automatically Detect Settings” checkbox.
5. Check the “Use a proxy server for your LAN (These settings will not apply to dial-up or VPN connections).” checkbox.
6. Enter the address “172.16.3.150” in the “Address” text field and “80” in the “Port” text field.
7. Check the “Bypass proxy server for local addresses” check box.
8. Click “OK”, and “OK” again.
9. Open “Internet Explorer” and navigate to “http://aihdownload.adobe.com/bin/install_flashplayer11x64ax_gtbd_aih.exe”
and open the file.
So is it possible to get this all to work in a script? I would like to use this in GPO to run on all client desktops.
I appreciate any help provided! Thank you very much!
You don't need IE and its gui to make an http request behind a proxy server. You can download a file using WinHttpRequest object (with proxy information, see SetProxy).
e.g.
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim oHttp
Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
With oHttp
'Make request
.SetTimeouts 5000,5000,5000,30000
.SetProxy HTTPREQUEST_PROXYSETTING_PROXY, "172.16.3.150:80"
.Open "GET", "http://aihdownload.adobe.com/bin/install_flashplayer11x64ax_gtbd_aih.exe", False
.Send
If oHttp.Status = 200 Then
'Save Response
With CreateObject("ADODB.Stream")
.Open
.Type = adTypeBinary
.Write oHttp.ResponseBody
.SaveToFile "C:\setup.exe", adSaveCreateOverWrite
.Close
End With
'Run Executable
CreateObject("WScript.Shell").Run "C:\setup.exe"
WScript.Echo "Completed!"
Else
WScript.Echo "Download Failed"
End If
End With
Set oHttp = Nothing