2

I want to run a program (that is not in the same directory as the script) with a MSG box, here's the code (it doesen't work because it needs the program to be on desktop like the script)

    puls = MsgBox("Want to open steam?", vbYesNo + vbQuestion)

    if puls = vbYes then
    CreateObject("WScript.Shell").Run "C:\Program Files(x86)\Steam\Steam.exe"
    CreateObject("WScript.Shell").Run "C:\Users\Dario Loi\AppData\Local\TeamSpeak 3 Client\ts3client_win64.exe"
    else
    MsgBox "Okay :(", vbInformation
    end if

now, as you can see, i want to execute this at system startup to get my gaming programs running, but i can't put steam on the desktop because it will dump it's assets there, and it would be a mess, i can't put the script in steam's directory too, same thing for TS3, also, i tried to replace the name of the file with it's path, but it does not work either

EDIT: Just for making things clear, i've got a VBS File on my desktop, along with it, on the desktop i've got 2 links (not the original EXEs), to steam and TS, (the programs i want to run), i would want to open these 2 programs without putting the script and the program in the same folder, so

  1. by making the script refer to the link and
  2. by making the script refer to the path, if you got ideas, please tell me
Madknight
  • 23
  • 5
  • @Hackoo answered the OQ succesfully: his code snippet _works_. Please consider accepting his answer. Your edit extends the original question exceedingly, beyond all limits. so ask another question, please... – JosefZ May 24 '15 at 20:07
  • but actually i didn't understand it, (it's my fault, not his) so... if you could explain it to me – Madknight May 25 '15 at 12:32
  • The command line in `.Run strCommand` should appear exactly as it would if you typed it at the command prompt. So if the path contains any white space characters then should be surrounded with `"` double quotes (i.e. characters with `ASCII` code of **34**). Read again and thoroughly check the `Chr(34) & Str & Chr(34)`... – JosefZ May 25 '15 at 13:11

2 Answers2

2

And if you try like this ?

puls = MsgBox("Want to open steam?", vbYesNo + vbQuestion)
Set ws = CreateObject("WScript.Shell")
if puls = vbYes then
    ws.Run DblQuote("C:\Program Files(x86)\Steam\Steam.exe")
    ws.Run DblQuote("C:\Users\Dario Loi\AppData\Local\TeamSpeak 3 Client\ts3client_win64.exe")
else
    MsgBox "Okay :(", vbInformation
end if
'*****************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • copied all the code ( with * too) and runned it, it asks me if i want to open steam, pressed yes, it doesen't recognize file name at 4 line (might not recognize even the 5,) also, if I press no the scripts outputs "okay :(" as normal – Madknight May 24 '15 at 16:48
0

Add a cd (change directory) line to the full path of your executables which will bring the cmd prompt to that directory, and do your run command.

digwig
  • 154
  • 12
  • so, i opened properties of my executable, changed the destination from "C:\Program Files (x86)\Steam\Steam.exe", to "C:\Program Files (x86)\Steam\Steam.exe" -cd, runned my VBS, and it gave me an error on the fourth line, 2 character, file not found, the same error as the previous, so could you explain this a bit better? please? – Madknight May 24 '15 at 14:57
  • Is that your full script above? I just see CreateObject("WScript.Shell").Run "Steam.exe", and nothing referencing a full path or a cd command. Can you add your script if it's been amended? – digwig May 24 '15 at 15:00
  • You're code works fine for me. Go to the folder manually, and right click the address bar and select "copy text " just to make sure that the path is totally correct. – digwig May 24 '15 at 17:55
  • i copied it and it still doesen't work, check my edit for clarifications – Madknight May 24 '15 at 18:27
  • Your script works for me using other applications since I don't have steam. What happens if you open a command prompt and type: start "C:\Program Files (x86)\Steam\Steam.exe" – digwig May 24 '15 at 18:45
  • it opens up another promt named "C:\Program Files (x86)\Steam\Steam.exe" – Madknight May 24 '15 at 18:49
  • That's really strange, and if you go to the folder and click on steam.exe? – digwig May 24 '15 at 18:54
  • it starts my steam, as normal – Madknight May 24 '15 at 19:48
  • I've been reading on Steam forums for this issue, and it looks like you're not alone. Try making a desktop shortcut and launching that. If it works, modify your path to reference the shortcut. I think it has something to do with the steam itself. – digwig May 24 '15 at 20:19
  • oh, thanks a lot :D i'll try it tomorrow i think, as now i've to go to sleep, i'll inform you if something happens – Madknight May 24 '15 at 20:21