File wont move to folder vbs - vbscript

So im writing a script that drops a file folder then moves that file to the folder it dropped it self. Well the folder drops fine but the file wont move. Can some see whats wrong with my code? Or give me a better way to move the file. I also get no error message about trying to move the file.
Dim folder,fso,filsys,C
Set fso = CreateObject("Scripting.filesystemObject")
Set folder = fso.GetSpecialFolder(1)
Set wshshell = CreateObject("wscript.shell")
Set filesys = CreateObject("scripting.filesystemobject")
Set objfso = CreateObject("Scripting.filesystemObject")
Set c = fso.GetFile(Wscript.scriptFullname)
On Error Resume NEXT
Set objFolder = objFSO.CreateFolder("C:\55egr932ntn7mk23n124kv1053bmoss5")
If Err.Number<>0 Then
End If
WScript.Sleep 3000
C.Move ("C:\552ntn7mk23n124kv1053bmoss5\File.exe") (folder&"\File.exe")
And I have a program I use that turns the VBS into and EXE so you see the "file.exe" which really is the .VBS itself

I'm not familiar with this syntax, but the line below looks like it's expecting the folder variable to be a string.
C.Move ("C:\552ntn7mk23n124kv1053bmoss5\File.exe") (folder&"\File.exe")
Earlier in code it looks as though you're setting folder as an object.
Set folder = fso.GetSpecialFolder(1)
You might not get the error you mentioned in your comment if you convert folder to a string.
~~
Another thing to try is the following code:
Set fso = CreateObject("Scripting.filesystemObject")
Set folder = fso.GetSpecialFolder(1)
Alert (folder&"\File.exe")
(I'm not sure if it's "Alert" or "Msgbox" or something else.) That test will show you whether the file path makes sense. If you get an error on line 3 of that test, try converting folder to a string before your Alert (or Msgbox).

Related

Multi line vbs auto typer from .txt file [duplicate]

This question already has answers here:
Single Line Input VBS Autotyper
(2 answers)
Closed 2 years ago.
So i have been working on a troll terminal and now i want to type out the entire bee movie script or whatever i put in a text file.
What i need help with is taking the text(with enters and spaces) and fully typing it out.
Another way to say it is i want to take a text file and copy it threw typing it out.
I couldnt find any decent code to do this wich is why i'm asking here.
Also if possible make it type anything that you put in the text file.
(I have no clue why it doesnt let me post this)
Idea: I might know another way around but i dont know how to get it done.
Maby there is a way to infinetly generate variables for each line and type them out like that.
Other idea: I might be able to make a tool to let me quickly hard code it.
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\yourfirstfile", 1)
content = file.ReadAll
Const fsoForAppend = 8
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\yoursecondfile", fsoForAppend)
'Display the contents of the text file
objTextStream.WriteLine content
'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
Set wshShell = CreateObject("Wscript.Shell")
wshShell.run "C:\yoursecondfile"
Tell me if it works
Yes i m self anwsering.
This script works but it double taps enter i will update it if i figure out how to stop that from happening.
Set wsh=WScript.CreateObject("WScript.Shell")
sub custom_text_typer_confirm
Set objFileToRead =WScript.CreateObject("Scripting.FileSystemObject").OpenTextFile("Custom_Text_Typer.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
custom_typer_wait = inputbox("How long should the program wait untill it will start typing?", "Eclips-Terminal Custom Text Typer")
custom_typer_wait1=custom_typer_wait * 1000
Wscript.sleep custom_typer_wait1
wsh.sendkeys (strFileText & "{enter}")
Wscript.sleep 1000
call home
end sub

Using VBScript to examine properties of files within a zip file

I'm trying to use VBScript to examine the contents of several hundred .zip files. Essentially what I want to do is run through each .zip and find all of the files wihtin that zip file. For each one of these files within the zip, I want to record some information about it to an Oracle database. That information being: file name and file modified date.
So far, my solution has been extracting each zips folder structure to a temp folder then running through the temp folder with an fso object. However, this has been proven to be very slow.
Is there a way to accoplish this without unziping the zip files?
Ouch man. I have never heard of vbscript zip object. But it has been a long time since I have done vbscript. Is there anyway you can avoid it?
I did some googling for you. I did find this: http://www.example-code.com/vbscript/zip_List.asp Chilkat has done a lot of stuff I thought not possible. This gives me the impression - that what you are trying to do is not going to be painless.
If given the problem you have I would find a different solution than vbscript. But if you pull-it-off I would vote for you to be mayor of vb land
You can do it in place with Shell Objects. But it will be just as slow, maybe. If just name and date Explorer may get it direct from the zip directory (at the end of the file so the whole file still needs to be read).
This copies items in a folder to another folder. A zip file is a folder so it will copy in and copy out.
To Zip
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"
To Unzip (note SrcFolder and DestFolder are reversed)
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set DestFldr=objShell.NameSpace(Ag(1))
Set SrcFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"
To Create a blank zip. (I should have used an ADODB binary stream rather than an FSO text stream, but it shouldn't matter)
Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip

VBS WScript.Run fails after passing Exists test

In a couple of place in my code I check if the file exists (it does) then I try to Run the file as above, or get the DateLastModified, and get errors about file not found or invalid path. How can the script NOT see a file after confirming it exists?
I'm working up a .vbs script that tries to run an Access .mdb file. The WScript.Run command seems to choke on the filename, but putting a MsgBox() before that call to display the path allows Run to work properly. I don't want to display a popup.
Error is:
The directory name is invalid.
How is this possible and how can I get around it?
Here is code:
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
SET ws = WScript.CreateObject("WScript.Shell")
path = Chr(34) & LocalPath & AccessFileName & Chr(34)
if (fso.FileExists(LocalPath & AccessFileName)) THEN
'MsgBox(path) 'Uncommenting this line removes the error
ws.Run path 'This line errors
End If
Try to open your file with shell .InvokeVerb method:
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
If CreateObject("Scripting.FileSystemObject").FileExists(LocalPath & AccessFileName) Then
CreateObject("Shell.Application").Namespace(LocalPath).ParseName(AccessFileName).InvokeVerb
End If
UPD: Both ActiveX WScript.Shell and Shell.Application uses native windows shell to perform a file execution.The first one launches new process via WSH core located in wscript.exe, cscript.exe, wshom.ocx, jscript.dll, vbscript.dll, ets, .Run and .Exec methods of WsShell object provides wide control on the launched process, and second one located in Shell32.dll, uses .InvokeVerb method of IShellDispatch object, called without name, runs default verb equals to the windows explorer "open" command.In case of any issues connected to WSH, explorer might still works without any proplems. If it does, that is just a work-around, I can't say what's wrong definetely without close look.
Hello the following code worked for me.
Basically this code gets a folder object and loops through all files in a folder and checks if its the one that you named. This it runs the application.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = Wscript.CreateObject("Wscript.Shell")
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
Set myFolder = fso.GetFolder(LocalPath)
For each myFile in myFolder.Files
If myFile.Name = AccessFileName Then
'Wscript.Echo myFile.Name
ws.Run myFolder.Path & "\" & myFile.Name
End If
Next
You can give this a shot. You probably do not need the quotes around the path, but I included it as a comment if you want to give it a shot. You just put quotes twice if you need to include a quote character in a string:
Set fso = CreateObject("Scripting.FileSystemObject")
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
Set ws = WScript.CreateObject("WScript.Shell")
' path = """" & LocalPath & AccessFileName & """" <-- probably unnecessary
path = LocalPath & AccessFileName
If (fso.FileExists(path)) Then
Set file = fso.GetFile(path)
'MsgBox(path) 'Uncommenting this line removes the error
ws.Run file.Path 'This line errors
End If
This does not make any sense. Having a MsgBox line is altering the behavior of the program!!!
I feel it is probably some weird invisible character somewhere which is getting activated when you comment the line.
Try retyping the If block without the MsgBox in between.

cant get local htm file to open with VB-script

Hi Im tryijng to open a local htm file ussing vb script. I have the following code which will work for standard online webpages however my target htm is found localy, and in that case senario i cant get it to work
WORKING:
strURL = "http://www.somesite.com"
Set objShell = CreateObject("Wscript.Shell")
objShell.Run(strURL)
NOT WORKING:
strURL = "file://J:\Project Phoenix\Tekenafspraak Tafelhandboek\COMPELATION WITHOUT IMAGES (MASTER)\Tekenafspraak Tafelhandboek.htm"
Set objShell = CreateObject("Wscript.Shell")
objShell.Run(strURL)
You need to put quotes around your full path name if there are spaces in it. In this case, it means adding two extra double-quotes at the beginning and end of your string.
And you shouldn't need the "file://" in the path. The Shell object will just open the htm file in your default browser automatically:
strURL = """J:\Project Phoenix\Tekenafspraak Tafelhandboek\COMPELATION WITHOUT IMAGES (MASTER)\Tekenafspraak Tafelhandboek.htm"""
Set objShell = CreateObject("Wscript.Shell")
objShell.Run(strURL)
Quote your spaces. This is spaces 101. What will happen in your script will depend on the configuration of the computer it is run on.

Copy info from txt and paste in another vbscript

I'm trying to copy a line of text from a .txt -> paste into another file and save. The code I have keeps giving me errors at the paste section. I am completely new at this and learning as I go. My main goal is to paste the info after Host= in another file. But I need to get this down first.
Here is my code so far
///OPEN FILE and READ
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\vnc\vnc.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
' ///PASTE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileToWrite = objFSO.OpenTextFile("c:\vnc\testfile.vnc", 2)
objFileToWrite.Write strFileText
objFileToWrite.Close
This works for me:
'//OPEN FILE and READ
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\vnc.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
' ///PASTE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileToWrite = objFSO.OpenTextFile("c:\vnc.vnc", 2)
objFileToWrite.Write strFileText
objFileToWrite.Close
The only difference I made was remove the subfolder, and put in the root of C: The script worked.
I manually created both the source file and target file. If both files exist, and are not locked (as if you had it open / locked in another application), then the permissions of that VNC folder must be the issue.
If still your file permission denied you to write then you have to do change the security of that file using right click of mouse, and update advanced setting.

Resources