anon_user123456
anon_user123456

Reputation: 69

Why does VBS always tell me file not found even though the file is right there? (At startup)

I have a .vbs file, which I have set to run at startup through regedit. Basically what the vbs does, is execute another program in the same directory (I will paste the vbs script below). Normally, the vbs script works great and everything is good. However, whenever the vbs script run at startup (i.e auto running right after the computer is booted), I always get a error message, telling me that Windows cannot find my file (i.e hello.exe), even though the exe file is right there.

I have tried setting a delay to the script, but that resulted in the same problem. I am extremely confused because everytime I run the vbs manually (like double click it), everything works fine, no problem.

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "hello.exe" & Chr(34), 0
Set WshShell = Nothing

The expected result is that the vbs script will just run normally, like how it runs everytime i manually launch it. The error message is "Line 2: File cannot be found", or something along the lines of that.

Upvotes: 1

Views: 1177

Answers (2)

Rosski
Rosski

Reputation: 72

This will run the exe file if its in the same folder as your script.

strPath = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName,"\"))
WshShell.Run chr(34) & strPath & "hello.exe" & Chr(34), 0

Upvotes: 0

Étienne Laneville
Étienne Laneville

Reputation: 5021

As Hackoo is getting to, use the full path to the EXE you are running:

WshShell.Run chr(34) & "C:\My Hello App\hello.exe" & Chr(34), 0

Upvotes: 1

Related Questions