質問

I've made a vbs script with code:

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("""MainForm.exe""")
Set objShell = Nothing

This script is running in the folder where MainForm.exe is located. Everything is OK, and MainForm.exe starts running with this script.

But, I need that script to run just one folder up. And here the problem starts (the folder containing MainForm.exe is called Deploy). I've made a script in upper folder:

CreateObject("WScript.Shell").Run("""G:\ROOT\KnowledgeBaseProdukcija\Deploy\MainForm.exe""")

But it's keep telling me this:

enter image description here

It seems like MainForm.exe gets running, but something is wrong? I've also tried relative path (which is my preferred way), but with same result:

CreateObject("WScript.Shell").Run("""..\KnowledgeBaseProdukcija\Deploy\MainForm.exe""")

I just don't understand what's the difference between two scripts?

役に立ちましたか?

解決

It looks like your MainForm.exe is looking for files in the working directory. Since it has been called from outside the directory where the MainForm.exe binary is lcoated, it won't be able to find what it's looking for.

This is probably something that needs to be fixed in the MainForm application code. It's probably trying to open a file using a relative path and expecting it to be relative from the directory containing teh binary, but it's now actually looking relative to the working directory.

You can work around this by setting the CurrentDirectory property of the Shell object:

Dim shell
Set shell = CreateObject("WScript.Shell")
shell.currentdirectory = "G:\ROOT\KnowledgeBaseProdukcija\Deploy\"
shell.Run("""G:\ROOT\KnowledgeBaseProdukcija\Deploy\MainForm.exe""")

Inside the MainForm.exes sources use string thatpath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) to find the installation path and use Path.Combine(thatpath, "./relative/path/to/resource") to load any files that you expect to be in a path relative to the executable to fix the issue at the source.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top