VBScript Invalid Character 800A0408 error - vbscript

After much searching, I have not been able to find a solution to the error. This script is used to find corrupt cache files in the c:\Windows\Installer directory
this is the offending line of code:
Log "Debug: Found " & dicSUpdatesAll.Count – iCnt & " unique patch(es) in folder " & Folder
the full script can be found here gist

Related

Code Error 800A0409 - Unterminated String Constant (Japanese Windows)

This one is kind of strange to me. Prior to posting I did research this error code and according to many articles out there it seems relatively a straight forward issue. The issue is generally related to either missing double quotes in a string or where a string spans across multiple lines.
However, in my case neither of the above seem to be the cause of the issue. The strange thing is my code works fine in English windows operating system but I encounter this error only in the Japanese version of windows.
The error is pointing to the following line of code:
WScript.Echo "PFXファイル " & pfxFileName & " は存在しません。"
Any ideas why this would only happen in the Japanese version of Windows?
Here is the block of surrounding code in case it gives any further clues:
' check if pfx file exists
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
pfxFileExists = 0
Do
If fso.FileExists(pfxFilePath & pfxFileName) Then
' it exists, continue
pfxFileExists = 1
Else
' The PFX file does not exist.
WScript.Echo "PFXファイル " & pfxFileName & " は存在しません。"
End If
Loop Until pfxFileExists = 1

Windows Service That Deletes Contents of C:\Windows\Temp

I have windows service written in vb.net that deletes the contents of a folder (meaning all files, subfolders, and files) in that folder every few minutes.
I need to change the service so that it now deletes the contents of the C:\Windows\Temp folder.
When I edit the path in the service, then recompile, and re-install, the service does not delete the contents of C:\Windows\Temp
I even added code to handle any open/locked files so that the deletion process would just continue, but still nothing.
Sub ClearWinTempDirectory(folder As String)
'Loop over the subdirectories and remove them with their contents
For Each d In Directory.GetDirectories(folder)
Directory.Delete(d, True)
Next
' Finish removing also the files in the root folder
For Each f In Directory.GetFiles(folder)
Try
File.Delete(f)
Catch e As System.IO.IOException
Console.WriteLine(e.Message)
End Try
Next
COBWtl.WriteEntry("All files and folders in the " & folder & " directory that
are not currently locked by applications or processes Have been deleted",
EventLogEntryType.Information, eventID:=9995)
End Sub
I am hoping someone can help me identify why this service does not work when pointed to C:\Windows\Temp but it works without incident when deleting files and folders in C:\MyTestFolder.
My service runs as LocalSystem and SYSTEM has full control on C:\Windows\Temp
I also changed it to run as an administrator account, but that doesn't work either.
I can put the same code into a non-service exe and double click it, and it works and deletes the contents of C:\Windows\Temp -- so I am at a complete loss and hope someone can point me in the right direction on how to figure out what is wrong.
I provided process monitor results, which appear to show the service is accessing C:\windows\temp which is confusing because I put some test files out there that are not open or held up in a process, and those are not being deleted.
Native Process Monitor PML Results File
Process Monitor Extended Results XML File
I was able to fix my own problem. Here is what I found:
The service was successfully accessing C:\Windows\Temp but it was failing due to two exceptions:
1) Permissions Exception where it was denied access to a subfolder or file as a result of permissions
2) IO Problem because the file was open or in use.
In my code, I was only checking for System.IO.Exceptions so when it encountered an Access Failure exception it would break.
Once I discovered this, I modified the exception handling on the catch so that it would check for all exceptions.
Hence the code changed from what it was as listed above to this.
Sub ClearWinTempDirectory(folder As String)
'Loop over the subdirectories and remove them with their contents
For Each d In Directory.GetDirectories(folder)
Try
Directory.Delete(d, True)
Catch e As System.Exception
COBWtl.WriteEntry("The directory " & d & " is
currently locked or is inaccessable and will not be deleted.",
EventLogEntryType.Information, eventID:=9997)
End Try
Next
' Finish the files in the root folder
For Each f In Directory.GetFiles(folder)
Try
File.Delete(f)
Catch e As System.Exception
COBWtl.WriteEntry("The file " & f & " in directory " & folder
& " is currently locked or is inaccessable and will not be
deleted.", EventLogEntryType.Information, eventID:=9997)
End Try
Next
COBWtl.WriteEntry("All files and folders in the " & folder & "
directory that are not currently locked by applications or processes
Have been deleted", EventLogEntryType.Information, eventID:=9995)
End Sub
Problem solved.

Read path from file and check if file exists in a specified path

I am trying to read a PATH from a text file and check whether the file exists in the PATH specified in the "input.txt" file. Though the file is present in the specified location. The loop continues to run.Please help
Below is my VBScript
Set oReadObj = CreateObject("Scripting.FileSystemObject")
set oRead = oReadObj.OpenTextFile("C:\input.txt", 1)
loc = oRead.ReadAll()
Do Until oReadObj.FileExists(loc)
wscript.sleep 5000
Loop
msgbox "file found"
you don't need a loop to check if the file exists (if you have the full path of it), here is the code you need.
Set oReadObj = CreateObject("Scripting.FileSystemObject")
set oRead = oReadObj.OpenTextFile("C:\input.txt", 1)
loc = oRead.ReadAll()
If oReadObj.FileExists(loc) Then msgbox "file found" else msgbox "file not found"
.ReadAll() may include a EOL from the file, which surely isn't part of the path; use .ReadLine(), as you just want to get one path.
On second thought:
There may be other junk (spaces, BOM, ...) in your file. Did you try something like
WScript.Echo ">" & loc & "<"
to check for those or typos?
Reboot:
Based your comments:
If I specify the "path(location of installer)" instead of variable
"loc", I am getting expected result
This is the content of my " input.txt" file
"C:\Users\Administrator\Downloads\Storage_Manager_Server-windows-x86_64-6.0.0.ex‌​e"
we can
rule out permission problems (usual suspects if "Administrator" pops up)
conclude that loc - i.e. the file's content - is to blame
If we are sure that EOL's, blanks, typos are not the cause of .FileExists' failure, then the most likely hypothesis is: The file contains the " (quoted path), which is good for the shell, but fatal for FileSystemObject methods.

vbscript reads File object properties, but won't delete the file

Here is my (very simple) code:
if fs.FileExists(strPath) then
set thisFile=fs.GetFile(strPath)
wscript.echo thisFile.Name & " (" & thisFile.Size & ") will be deleted"
thisFile.Delete
end if
The path is correct, because I can read the file name and file size in the output. However, this is the output I'm getting:
D:\Inetpub>cscript PDFDelete.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
131_1443_cds101711.pdf (28660) will be deleted
D:\Inetpub\PDFDelete.vbs(38, 3) Microsoft VBScript runtime error: File not found
As you can see, I get the proper output on the file properties, so I know I have a valid reference to the file object, but trying to execute the Delete() method on that exact same file object produces a "File not found" error?!
It makes no sense to me. How can the file be "not found" if I just accessed its name and size properties?
EDIT I should have mentioned, I initially was using the code "fs.DeleteFile(strPath)" when I first got the "File Not Found" error. I changed it to the more direct "File.Delete()" method, but the error persists.
You can try:
if fs.FileExists(strPath) then
set thisFile=fs.GetFile(strPath)
wscript.echo thisFile.Name & " (" & thisFile.Size & ") will be deleted"
fs.DeleteFile strPath
end if
http://www.devguru.com/technologies/vbscript/14055
I found the issue.
There was a stray line of code further down in the script that was referencing thisFile.Size, after trying to delete that file. The error was happening on that line, not on the thisFile.Delete line.
Moral of the story: make use of the On Error Resume Next/On Error Goto 0 error trapping from the start, and things get a lot clearer.

VB script_CReating Folder inside folder

For i = 1 To 40 Step 1
ChildFolderPath = ChildFolderPath & "\" & "LargeFolder" & i
If fso.FolderExists(ChildFolderPath) Then
MsgBox ("Folder Exists")
else
fso.CreateFolder (ChildFolderPath)
End If
Next
But after creating 21 folders, I am getting error 53, "File path not found". Why?
You're hitting the Windows limitation on maximum path length, which is 260 characters.
The linked article also mentions a workaround to use extended-length paths up to (approximately) 32767 characters long – add \\?\ before the drive name. For example:
ChildFolderPath = "\\?\C:\MyFolder"
As also noted in that article, even though you can create extended-length paths programmatically, the Windows shell (e.g. Explorer) may be unable to handle them properly. For example, you may get the "The source file name(s) are larger than is supported by the file system" error when trying to delete a long path folder from Explorer or the command prompt.

Resources