-2

I'am trying create Windows 10 notification using shell script and I want to execute it with vbscript but it only seems to prompt me to find program to handle this in Microsoft Store.

I tried to execute .sh file using code in vbscript, like WshShell.Run.

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "Notification.sh"

I've got an Microsoft Store dialog asking me how to run the .sh file, but I wanted to run it, but there is no system program that could handle it, except for Windows Shell Console.

user692942
  • 16,398
  • 7
  • 76
  • 175
Daw588
  • 56
  • 6
  • 1
    Pass the `.sh` script as a parameter to `bash.exe` – Larry Song Jul 04 '19 at 23:48
  • 1
    @DavidRakProgrammingTutorial - your post dd not mention any such thing. am i supposed to read your mind? [*grin*] plus, the process listed in the article has a GREAT deal more than what you posted. so ... have you actually red it and tried it? – Lee_Dailey Jul 05 '19 at 00:24
  • @DavidRakProgrammingTutorial You know what I find rude, when people can't be bothered to form a coherent question. [The answer you have posted](https://stackoverflow.com/a/56895347/692942) doesn't seem to answer the question you asked. How do you go from [shell script](https://stackoverflow.com/a/32263486/692942) to powershell, which is it? – user692942 Jul 05 '19 at 07:02

2 Answers2

0
WshShell.Run "powershell.exe -nologo -command C:\ShellFile.ps1"
Daw588
  • 56
  • 6
0

Comes a bit late but - it is possible with run method of WScript.Shell ...

With CreateObject("WScript.Shell")
    .run "cmd.exe /C ""c:\Program Files\Git\bin\sh.exe"" > c:\out.txt --login -i -c d:\yourfolder\bash.sh -R", 0, True
End With

' Read the output and remove the file when done...
Dim strOutput
With CreateObject("Scripting.FileSystemObject")
    strOutput = .OpenTextFile("c:\out.txt").ReadAll()
    .DeleteFile "c:\out.txt"
    WScript.Echo strOutput
End With

So, here you first run sh.exe by cmd.exe and then sh.exe runs the bash.sh command file. We also read the console output into file (out.txt) and later read it into variable to catch the output. Note also that we can hide window frame by using 0 as the second parameter for run-method.

It is also possible to use exec-method and receive output directly into variable but then we cannot hide window ...

Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")

outVar = objShell.exec("cmd.exe /C ""c:\Program Files\Git\bin\sh.exe"" --login -i -c d:/yourfolder/bash.sh -R").stdout.readall
WScript.Echo outVar

Set objShell = Nothing
M.Y.
  • 549
  • 1
  • 3
  • 23