0

I am using the following VBScript code to extract a setup file,

Set oShell = CreateObject ("WScript.Shell") 
oShell.Run "cmd.exe ""C:\Program Files\NewFolder\setup.exe"" /extract:""C:\Program Files\NewFolder"" "

This works fine when done manually in the command-prompt. But in VBScript it only opens the command-prompt and nothing happens.

I also tried this,

Set oShell = CreateObject ("WScript.Shell") 
oShell.Run "%comspec% /K ""C:\Program Files\NewFolder\setup.exe"" /extract:""C:\Program Files\NewFolder"" "

This way, it says that,

'C:\Program' is not recognized as as internal or external command, operable program or batch file.

I also tried these,

Set oShell = CreateObject ("WScript.Shell") 
oShell.Run "cmd.exe /c ""C:\Program Files\NewFolder\setup.exe"" /extract:""C:\Program Files\NewFolder"" "

Set oShell = CreateObject ("WScript.Shell") 
oShell.Exec "cmd.exe ""C:\Program Files\NewFolder\setup.exe"" /extract:""C:\Program Files\NewFolder"" "

It does not work.

What is the issue here please?

7
  • 2
    To execute a command and leave you need to use cmd /c Commented Apr 21, 2017 at 17:02
  • 2
    Either of cmd /c, cmd.exe /c, or %comspec% /c should work just fine. Use /k instead of /c to prevent the CMD window from closing, so you can inspect the command output. The error message you received when you tried that suggests that contrary to what you claimed you did not put the path to setup.exe in quotes. Commented Apr 22, 2017 at 22:45
  • I tried the /k and I get the message which says 'C:\Program' is not recognized as as internal or external command, operable program or batch file. Commented Apr 23, 2017 at 6:44
  • 2
    Like I said, that could only happen with missing or broken quoting. Commented Apr 23, 2017 at 19:08
  • 1
    @CodenameK can you provide the setup.exe (upload it to dropbox or something) so we will test this ourselves? Commented Apr 24, 2017 at 10:39

1 Answer 1

1

It looks like the self-extractor in your executable can't handle paths with spaces. As a workaround you can change the working directory and call setup without path.

Set sh = CreateObject ("WScript.Shell")
sh.CurrentDirectory = "C:\Program Files\NewFolder"
sh.Run "%COMSPEC% /c setup.exe /extract:."
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly.
Thank you Ansgar Wiechers and everyone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.