0
votes

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?

1
To execute a command and leave you need to use cmd /c - MC ND
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. - Ansgar Wiechers
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. - Codename K
Like I said, that could only happen with missing or broken quoting. - Ansgar Wiechers
@CodenameK can you provide the setup.exe (upload it to dropbox or something) so we will test this ourselves? - user692942

1 Answers

1
votes

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:."