0

I have two files in one folder, a vbs file called notify.vbs and an executable called foo.exe.
the foo.exe is a node.js pkg-bundled executable that triggers a native desktop notification with a random message from a local text file after 5 seconds from execution. Although pkg had one inconvencience which is that executing foo.exe launches a cmd interface, which doesn't suit my purpose.
This is where notify.vbs come in handy as it can execute foo.exe while keeping the cmd interface hidden just like I wanted. notify.vbs looks like this:

Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "foo.exe", , , "runas", 1

It works fine. But then, when I change the location of foo.exe for example in a folder called bar directly in the C drive and change the path in the script to:

Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "C:\bar\foo.exe", , , "runas", 1

the script starts foo.exe and closes it immediately. Basically notify.vbs only executes foo.exe when they're in the same folder. When I change the location of either of them it does that weird behaviour I mentioned. I verified the functionality of foo.exe in different locations. It always works. I even verified the path in script each time I tried a different location, it's always correct as it actually does execute foo.exe but it closes it immediately after. I have no experience with VBScript as I copy pasted that script. Thanks in advance.

  • Didn't you just ask this a few days ago? – user692942 May 17 '21 at 11:13
  • 1
    It depends what `foo.exe` is doing if it behaves differently when you change its location, maybe it's expecting a dependency that is lost when you move it? There's not enough here to go on. – user692942 May 17 '21 at 11:16
  • @user692942 the `foo.exe` is a node.js pkg-bundled executable that triggers a native desktop notification with a random message from a local text file. I verified the functionality of `foo.exe` in different locations. It always works. `notify.vbs` only executes `foo.exe` when they're in the same folder. When I change the location of either of them it does that weird behaviour i mentioned. I even verified the path it's correct as I said it actually starts up but closes immediately after. Is this detailed enough? – Wassim Tahraoui May 17 '21 at 11:20
  • 1
    That's definitely more detail, but it belongs in the question so [edit] it. – user692942 May 17 '21 at 11:21
  • Is it a console app (run from command line), if so try running through `cmd.exe` to see if that helps shed light on why it closes instantly. See [How to keep the VBScript command window open during execution](https://stackoverflow.com/a/7526707) – user692942 May 17 '21 at 11:24
  • @user692942 it's not a console app so I definitely don't want to keep the command window open, I've provided more details in the question. it's more of a "silent app" that only triggers a notification after 5 seconds and closes. But `notify.vbs` is not letting those 5 seconds occur. – Wassim Tahraoui May 17 '21 at 11:37
  • @WassimTahraoui _random message from a local text file_ Where is this text file located? – Flakes May 17 '21 at 13:56
  • @Flakes it's always located wherever the foo.exe is, I move them together. but the text file is not the issue here at all, i'm not saying the message is not read. I'm saying that the app launches and quits immediately. – Wassim Tahraoui May 17 '21 at 13:58
  • 2
    You could _try_ passing in the _working directory_ : `oShell.ShellExecute "C:\bar\foo.exe", , "C:\bar", "runas", 1` – Flakes May 17 '21 at 14:36
  • 1
    Glad it worked. @user692942 said it in his second commen,, about the dependency. – Flakes May 17 '21 at 14:50

0 Answers0