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
Related
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.
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
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
I have the eventual goal of determining that a particular database on a particular server with particular credentials is running, but I would settle, at this point, for the ability to check and see if a server is actually up on the network. Does anyone have a way of doing this? I seem to be drawing a blank.
Michael
try this
Dim target
Dim result
target= "172.19.130.96"
Set shell = WScript.CreateObject("WScript.Shell")
Set shellexec = shell.Exec("ping " & target)
result = LCase(shellexec.StdOut.ReadAll)
If InStr(result , "reply from") Then
WScript.Echo "Server alive"
Else
WScript.Echo "Not Alive"
End If
There maybe better ways especialy given you end goal but this should work and at least point you in the correct direction.
Here's an alternative solution that uses the Win32_PingStatus WMI class (note: this class is only available on Windows XP and later):
strServer = "stackoverflow.com"
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strServer & "'")
If oPing.StatusCode = 0 Then
WScript.Echo "Server is available."
Else
WScript.Echo "Server is not available."
End If
More ping script samples here: Why Doesn't My Ping Script Run on Windows 2000 Computers?
If you update the ping command so it only sends one echo request the script executes faster, if you've got an unreliable network this might not be best but for local LAN it's useful.
Dim target
Dim result
target= "172.19.130.96"
Set shell = WScript.CreateObject("WScript.Shell")
Set shellexec = shell.Exec("ping -n 1 " & target)
result = LCase(shellexec.StdOut.ReadAll)
If InStr(result , "reply from") Then
WScript.Echo "Server alive"
Else
WScript.Echo "Not Alive"
End If
For checking whether your database server is up, you can use tools like nmap. Then you can call it in your vbscript using exec() as per normal.
We are working on automating the deployment of some IIS applications. I've used cscript.exe inside a windows batch file to create the web app and such. There are however a few settings currently done by hand that I need to automate. Namely, if you look at the properties of an app, under Directory Structure -> Authentication and access control -> Edit, I need to uncheck Enable anonymous access and check Integrated Windows authentication.
Is there an easy way to do this from a windows batch file?
EDIT: I should clarify this is IIS 6.0, so appcmd is not available.
hope this helpes:
http://forums.iis.net/t/1159665.aspx
I answered a very similar question a wee while back. The example uses the asdutil.vbs tool which you can call from your batch file:
Setting NTAuthenticationProviders at an Application level in IIS 6 (Stack Overflow)
Updated:
Because you've already got a CScript script to create the website, you can just set the AuthFlags in the script:
'' Some values just as an example
iisNumber = 668
ipAddress = "172.16.3.200"
hostName = "myserver.com"
wwwfolder = "c:\mysites\www"
Dim serverBindings(1)
serverBindings(0) = ipAddress & ":80:www." & hostName
serverBindings(1) = ipAddress & ":80:" & hostName
'' Create server
Set w3svc = GetObject("IIS://localhost/w3svc")
Set newWebServer = w3svc.Create("IIsWebServer", iisNumber)
newWebServer.ServerBindings = serverBindings
newWebServer.ServerComment = "Server is: " & hostName
newWebServer.SetInfo
'' Create /root app
Set rootApp = newWebServer.Create("IIsWebVirtualDir", "ROOT")
rootApp.Path = wwwFolder
rootApp.AccessRead = true
rootApp.AccessScript = true
rootApp.AppCreate(True)
rootApp.AuthFlags = 4 '' <== Set AuthFlags here
rootApp.SetInfo
See Configure Windows Authentication (IIS 7):
appcmd set config /section:windowsAuthentication /enabled:true | false
For IIS 6 probably WMI is the alternative:
Creating Sites and Virtual Directories, and Setting Properties Using WMI
IIsWebServiceSetting (WMI)
AuthFlags
Dim sSitePath = "1" 'Set the site ID here
Set oSite = GetObject("IIS://localhost/" & sSitePath & "/root")
Select Case oSite.AuthFlags
Case 1
Wscript.Echo "Anonymous"
Case 2
Wscript.Echo "Basic"
Case 4
Wscript.Echo "NTLM"
Case 6
Wscript.Echo "MD5"
Case 64
Wscript.Echo "Passport"
End Select