VB Script error 800a004c - when trying to access network drive - vbscript

Im really new to VB script and have run into a problem. I keep getting
Error: Path not found
Code: 800A004C
when running the script;
Set objMachineList = objFSO.OpenTextFile(txtMachineList, ForReading)
If I change it to a local folder I no longer get the error but it needs to access the network drive for the script to work properly. Now time for the background story. There is a host computer that has the program (called TOMART, which are technical docs that are PDF with a GUI interface) installed to the network drive, with multiple computers accessing the drive (either online or always available offline) for sync purposes, which works fine. But the updates for the said program need to be installed into each of the networked computers hard drive for it to integrate and apply the updates for use with the program. The problem is, the updates need to be transferred to each computers hard drive for the program to recognise it and without the script working properly the updates arent getting transfered to each computers hard drive, so when accessing the updated PDFs in the program, the program just throws up error codes. I have attached the entire script in the hope someone here can help me out.
Sorry for the long winded description and apologies in advance if I haven't been clear with anything.
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objNet = CreateObject("WScript.Network")
Const ForReading = 1
Const ForWriting = 2
ServerName = "\\Mynetworkdrivename\Files"
ETool = objNet.computerName
updateServer = "\\" & ServerName & "\TOMART\Update\"
txtMachineList = "\\" & ServerName & "\TOMART\Machines.txt"
txtLogFile = "\\" & ServerName & "\TOMART\Logs\" & ETool & ".txt"
localTOMARTUpdate = "C:\TOMART\update\"
Set objMachineList = objFSO.OpenTextFile(txtMachineList, ForReading)
Do While objMachineList.AtEndOfStream = False
strLine = objMachineList.ReadLine
If ETool = strLine THEN
Set updServerList = objFSO.GetFolder(updateServer)
Set colSubFlds = updServerList.SubFolders
For Each fl in colSubFlds
subFldr = fl.name
If Not objFSO.folderExists _
(localTOMARTUpdate & subFldr) THEN
objFSO.copyFolder updateServer & subFldr, localTOMARTUpdate
End If
Next
Set textFile = objFSO.createTextFile(txtLogFile)
End If
Loop

Related

VBScript to run a file from desktop (any user)

I've created a VBScript to run a macro from excel without opening the file.
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\MyUser\Desktop\RM.xlsm'!Module4.Email"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
I want to use this VBScript & XLSM file on different computers, so how can i change this script to work without editing the path every time?
(Maybe a code to run from current folder or a code to run from any user desktop)
If the file will always be on the desktop of every user then you can use environment variables to determine the location.
Set wshShell = CreateObject( "WScript.Shell" )
userName = wshShell.ExpandEnvironmentStrings( "%UserName%" )
path = "'C:\Users\" + userName + "\Desktop\RM.xlsm'!Module4.Email"
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run path
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
(Untested code)
If the file is not on each user's desktop then you'll need to store it in a common location on the network and have each user access it from there, e.g. in .
\\YourFileSever\SharedFiles\RM.xlsm
In practical terms the latter is preferable as it means the workbook is in only one place and when it comes to releasing a new version you only have to update one copy

Creating folder in network share fails with "bad path" error

I have a network share already setup. I am trying to create a VBScript that will create a folder in the share called computername, which is the PC's name. The script will run locally on the PC, access the share and create the folder in the share.
My error is "bad path". I'm guessing I can't just state the network share path?
My script is below:
Dim objShell
Set oWS = WScript.CreateObject("WScript.Shell")
Set objShell = Wscript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
computername = oWS.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
If NOT (objFSO.FolderExists("\\ServerPath\Share$" + computername)) Then
objFSO.CreateFolder("\\ServerPath\Share$" + computername)
End If
You're lacking a backslash between the name of the share and the name of the folder you want to create. Also, I'd recommend using a variable for the path, so you don't have to construct it multiple times.
Change this:
If NOT (objFSO.FolderExists("\\ServerPath\Share$" + computername)) Then
objFSO.CreateFolder("\\ServerPath\Share$" + computername)
End If
into this:
path = "\\ServerPath\Share$\" & computername
If NOT objFSO.FolderExists(path) Then
objFSO.CreateFolder(path)
End If

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.

Can I list apps that don't have registry entries?

I've been working on a way to quickly and easily list all of the software installed on my machine. Once complete, I'd like to send it out to my group so that I can have everyone run it. Since the purpose of this exercise is generate a list of all of the applications that we absolutely require access to to our IT administrators, I don't want to miss anything important.
Up to this point, I've used code very similar to this - it looks in the registry at SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ and Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ and gives me all of the software that has been installed. However, a bunch of important programs are conspicuously absent (e.g. R, RStudio, SQL Developer), and I assume it's because they do not use Windows Installers.
This brings me to my question - is there a way I can list all of the programs that can be run on my machine (that have not impacted the registry)? Essentially, I think I want all of the non-system *.exe files, but that is probably oversimplifying things.
Anyone have any ideas? My code is VBS now, but I can muddle my way through most things.
If you want to find them all then you need to search every single file on your machine and check whether or not it has an executable extension. I'm reasonably confident that you are not going to want to do this.
I read your answer and laughed, since I was also "reasonably confident" that I did not want to go through all of the files on my (or anyone else's) machine. Once the laughing stopped, I realized that that's essentially what I had to do...
I've come up with something that works, and it now takes minutes to run (it took seconds to only check the registry), but it does work. I'm putting it here in case it can assist someone else, or maybe someone can find a way to make it more efficient. You need to supply some paths to folders where you want to look for exe files, and a file that you want to output to.
Thanks for reading.
On Error Resume Next
Folders = Array("C:\users\me","C:\SoftwareFolder1","C:\SoftwareFolder2","C:\SoftwareFolder3")
sFile="C:\myExeFiles.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const OverwriteIfExist = -1
Set fFile = objFSO.CreateTextFile(sFile, OverwriteIfExist, OpenAsASCII)
For Each x In Folders
Set objFolder = objFSO.GetFolder(x)
suckTheData objFSO, fFile, objFolder
Set objFolder = Nothing
Next
MsgBox("Done")
Set objFSO = Nothing
Sub suckTheData(objFSO, fFile, objFolder)
' *** STEP 1 *** 'Find files with a partiular extension in this folder
For Each objFile In objFolder.Files
If UCase(objFSO.GetExtensionName(objFile.Name))="EXE" Then
fFile.Write objFile & vbCrLf
If Err.Number <> 0 Then
fFile.Write "Error: " & objFile & " " & Err.Number & Err.Source & " " & Err.Description & vbCrLf
End If
End If
Next
Set objFile = Nothing
' *** STEP 2 *** 'Now that we've processed files, repeat for subdirectories
For Each subf In objFolder.SubFolders
'some folders can't/shouldn't be checked -
'16 is a normal folder, 32 is an archive, 1046 is symbolic, etc
If subf.Attributes ="16" Then
suckTheData objFSO, fFile, subf
End If
Next
Set subf = Nothing
End Sub

how to access a network folder using vbscript

I have a folder which is on a network like \\server\contents\tasks and I want to access this folder.
I am getting a "path not found" exception. What am I doing wrong here:
Dim FolderPath
FolderPath = "\\server\contents\tasks"
set FSO = CreateObject("Scripting.FileSyatemObject")
FSO.GetFolder(FolderPath)
Thanks
Edit: I found this post which answers the same thing I am trying to achieve, but the issue is I am getting an error the network share is no longer available. What I have is a local folder as a shared folder and mapped as \\servername\contents\tasks but it gives me the above error.
Edit: I was pointing at the wrong folder.
Now I have another issue trying to open a text file in the network folder. It is able to create a folder at the network path but throwing error while reading a text file in the network folder. Is there something else that needs to be done?
Set FSO = CreateObject("Scripting.FileSystemObject")
strOutputPath = strOutput1 --this is a network path
Set txsOutput = FSO.CreateTextFile(strOutputPath)
Set f = FSO.OpenTextFile(strInput1)
Open the network folder using explorer.exe and pass the location of the folder as a parameter (in this example it's sPath storing the folder path)
Example:
sPath = "\\somedrive.somecompany.ie\software"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "explorer /n," & sPath, 1, False
Terms and conditions: username and password privileges already setup for acccess to the network folder.

Resources