• Coding
  • VBScript Error: cannot find the file specified

Hello guys,

I was introduced to VBScript by a friend yesterday, and I am tinkering with it.

I have successfully written working code to do a CCleaner cleaning operation using SendKeys.

I am liking it so far :D

Now, I am having a problem writing the script for SmartDefrag. It's pretty simple for you guys I guess.

Here is my initial code:
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "C:\Program Files (x86)\IObit\IObit SmartDefrag\SmartDefrag.exe"
This code is supposed to open the software for me. The file is most definitely in that path. I think the problem is in the "spaces" in the path.

The error I am getting is the following:

Script: C:\Users\J\Desktop\VBS\smartdefrag_analyze.vbs
Line: 3
Char: 1
Error: The system cannot find the file specified.
Code: 80070002
Source: (null)


I would really appreciate your help gurus !
Try first with
c:\file.txt
then c:\somefiles\file.txt
then
c:\test dir\some file.txt

etc... as u see, keep adding spaces, parethesis, etc.. until you find what is causing it to fail. Also make sure the file actually exists.
The file exists! I found the solution: you need to add 2 more quotation marks.

This made it work:
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """C:\Program Files (x86)\IObit\IObit SmartDefrag\SmartDefrag.exe"""
WScript.Sleep 200
Yeah since this is shell execute (Run) you will need to escape spaces, the same way you would do it from the command line.
BTW I spend yesterday about 3 hours on a problem of this type (but the problem was not the spaces)
Are you a VBscript expert rolf? I am pretty good with Google, but I would not sharing some questions/thoughts with you.
I did a project in WScript but that was like 5 years ago, I forgot most of the stuff.
You gave me a real good idea with Wscript.
I am writing an installer script, and I am adding the additional functionality in DLLs. For example I created a DLL to check a port, and a DLL for copying/deleting/etc... directories. I can extend the functionality of the installer using this DLL.
I am wondering if it's possible to call WScript from a DLL, that would be great, this way I can extend the functionality of the installer with WScript functions.
If you have questions, dont hesitate to ask. As I said I forgot most of the stuff - I'm not good at memorizing, but I can still help, if not with the details.

EDIT: I also have a book about WScript
But I would not call myself a WScript expert. I just have had some experience with it.
BTW, I am saying WScript, but I did the project in VBScript. WScript is the host, which also supports some other languages.
Ok. Got it.

Thanks a lot for your help and good luck in your project.
Thanks, ill need it :)