Line 16 wont run properly (VBS) [closed] - vbscript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
I'm trying to make a program BUT whenever i run this .VBS file it says line 16 has an error, iv tried most things like putting it into a different directory, but it didn't work... rewording. renaming the file. AND just making it put the file into the designated place.
I'm expecting it to Copy the program to the C:\Windows\ directory, but its not realy copying it. iv also tried using "MoveFile" but it still didn't work.
THE CODE:
DIM FSO, MyFile
Set oShell = CreateObject( "WScript.Shell" )
''' runs file
CreateObject("Wscript.Shell").Run """SSS.bat""", 1, True
''' Alert Box
z=MsgBox("Finished.", 0+64, "Windows Alert!!!")
WScript.Sleep(1)
CreateObject("Wscript.Shell").Run """111.bat""", 1, True
CreateObject("Wscript.Shell").Run """file.bat""", 1, True
'''copy file to Windows
FSO.CopyFile "program.txt","C:\Windows\"
FSO.MoveFolder "C:\Windows\program.txt","C:\Windows\System32\program.exe"
CreateObject("Wscript.Shell").Run """C:\Windows\System32\program.exe""", 1, True

The error is likely happening because you are trying to use the FSO.CopyFile method before you've created the FSO object. To fix the error, you should add the following line of code before using FSO.CopyFile:
Set FSO = CreateObject("Scripting.FileSystemObject")

Related

How to set correct syntax if (fso.FileExists("")) after checking with fso.GetAbsolutePathName(".") [duplicate]

This question already has an answer here:
How to Verify if file exist with VB script
(1 answer)
Closed 1 year ago.
I'm struggling with correct syntax for setting the path in:
if (fso.FileExists("myfile.txt")) then ....
I use this:
set fso = WScript.CreateObject("Scripting.FileSystemObject")
Mypath = fso.GetAbsolutePathName(".")
if (fso.FileExists("myfile.txt")) then...
as i understand fso.GetAbsolutePathName(".") knows the path from where my script was launched
and when tested i can see the correct path with:
call MsgBox(Mypath)
for example the MsgBox is showing c:\users\user\desktop
that's where the script was launched and where i create my files.
I cannot use directly a path because it needs to be dynamic, files will be created and replaced
if exists at the same path the script was launched.
I hope it was clear enough, and that someone can answer this!
I'v read a lot of examples but none are covering this particular need.
thanks
Dim FSO 'As FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
If (FSO.FileExists("C:\Foobar.txt") Then
{statements}
End If
Set FSO = Nothing

Delete File in VBscript [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a list of about 50 files throughout different folders and I back them up very regularly by adding that day's date to the files. Not all the files are back up at the same time. Here's an example:
C:\Intel\Logs\AcerDT.pdf.2020-05-05
C:\Intel\Logs\IntelChipset.log.2020-05-05
C:\Intel\Logs\IntelGFX.log
C:\Intel\Logs\IntelSSDTDK.log.2020-05-05
C:\Intel\Logs\IntelSSDToolbox.log
I wrote a VBScript to delete all the files with that date. It works great if all the files had the extension, ".2020-05-05". The problem is if the file in the list does not exist, as in, it does not have ".2020.-05-05", it throws me an error message and exit. I don't want this. I want the script to check the list, if the file exists, then delete it, if the file does NOT exist then check the next one. Is this possible to do?
Here's my code:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
arrList = Array(_
"C:\Intel\Logs\AcerDT.pdf", _
"C:\Intel\Logs\IntelChipset.log", _
"C:\Intel\Logs\IntelGFX.log", _
"C:\Intel\Logs\IntelSSDTDK.log", _
"C:\Intel\Logs\IntelSSDToolbox.log" _
)
Function CleanUp(arrList, value)
Dim sFile, myFile
For each sFile in arrList
myFile = sFile & "." & value
If objFSO.FileExists(sFile) Then
objFSO.DeleteFile(myFile)
Else
Wscript.Echo "NO File: " & sFile
End if
Next
End Function
CleanUp arrList, "2020-05-09"
Thanks
Thank you Kul-Tigin
When I replaced sFile with myFile as you had indicated, it resolved the issue. I can't believe I didn't see it.
Solution:
If objFSO.FileExists(myFile) Then
objFSO.DeleteFile(myFile)
Else
...

How to change directory details (e.g. Author, Date...) using vba [duplicate]

This question already has answers here:
How can I change extended file properties using vba
(3 answers)
Closed 6 years ago.
I'm looking for some solution how to change folder property - "Author".
I've found "Shell" solution how to get this info:
Dim sFile As Variant
Dim oShell: Set oShell = CreateObject("Shell.Application")
Dim oDir: Set oDir = oShell.Namespace("c:\foo")
For Each sFile In oDir.Items
Debug.Print oDir.GetDetailsOf(sFile, 9)
Next
but I need to change this value.
Have you got any experience with it?
You may use ChDir:
https://msdn.microsoft.com/en-us/library/office/gg264410.aspx
For more information see help from vba editor

VBS: Permission denied when deleting a file or a folder

This is my code, which first checks for a folder which contains the installer, if found, runs the uninstall and deletes the uninstall.exe if it still exists. Lastly, it deletes the folder itself.
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshshell = wscript.CreateObject("WScript.Shell")
If objFSO.FolderExists("C:\Installer_3_00_00") Then
Set objFolder = objFSO.GetFolder("C:\Installer_3_00_00")
if objFSO.FileExists("C:\Installer_3_00_00\uninstall.exe") Then
Wshshell.run "C:\Installer_3_00_00\uninstall.exe -q"
End if
if objFSO.FileExists("C:\Installer_3_00_00\uninstall.exe") Then
Set objFile=objFSO.GetFile("C:\Installer_3_00_00\uninstall.exe")
objFile.Delete True
End if
objFolder.Delete True
Else
End If
Set objFSO = Nothing
The problem is: It says Permission denied trying to delete a file or folder. I cross checked by deleting manually and it worked. I have searched for similar problems in this forum but none of which helped me to solve this particular issue.
Any suggestions will be appreciated.
Thanks
P.s I tried formatting my code here, but still I was not able to format it correctly.
Your problem is most likely caused by the (un)installer still running when you try to delete it, because this call:
Wshshell.run "C:\Installer_3_00_00\uninstall.exe -q"
returns immediately without waiting for the program to finish. Change that line into this:
Wshshell.Run "C:\Installer_3_00_00\uninstall.exe -q", 0, True

VB script to zip a file and give the zip file the name of the file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Need help with VB script to zip a file in a folder and give the zip file created the name of the original name of the file. Like if there is a trn file named abc.trn then want to create a zip file named abc.zip. Please help if anyone have any idea
Yes and no. According to this answer on SO it is not possible using VBscript alone.
There are VBA methods to zip and unzip using the windows built in
compression as well, which should give some insight as to how the
system operates. You may be able to build these methods into a
scripting language of your choice.
However, you can use an "implementation-dependent behavior of the Windows shell" (again, quoted from the same source)
Dim fso, winShell, MyTarget, MySource, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set winShell = createObject("shell.application")
MyTarget = Wscript.Arguments.Item(0)
MySource = Wscript.Arguments.Item(1)
Wscript.Echo "Adding " & MySource & " to " & MyTarget
'create a new clean zip archive
Set file = fso.CreateTextFile(MyTarget, True)
file.write("PK" & chr(5) & chr(6) & string(18,chr(0)))
file.close
winShell.NameSpace(MyTarget).CopyHere winShell.NameSpace(MySource).Items
do until winShell.namespace(MyTarget).items.count = winShell.namespace(MySource).items.count
wscript.sleep 1000
loop
Set winShell = Nothing
Set fso = Nothing

Resources