Jump to content

Syntax Problem with VBScript


Recommended Posts

Hello All,

I'm trying to install Symantec Antivirus 10 & Windows Media Player 10 but I can't seem to figure out the proper syntax for the VBScript function:

WshShell.Run("\"D:\Symantec AntiVirus.msi\" /qb-!", 1, True)

WshShell.Run("D:\WMP10.exe /Q:A /C:\"setup_wm.exe /Q /R:N /DisallowSystemRestore\"", 1, True)

The problem is coming from the use of surrounding \"

BTW, I know all I have to do for Symantec is to rename the .msi file without space and remove the surrounding \" but this won't work for Media Player...

Edited by Incroyable HULK
Link to comment
Share on other sites


Here is a script that should illustrate two things for you. First is the proper way to install .msi based software from within a VBscript. Second, there is a demonstration of constructing and executing a fairly complex 7-Zip command line from within a VBscript.

There are times when you need to get a little creative as well. Here is an example where you actually need to use four quotes on either side of a variable:

If fs.FileExists(OEM & "\101_AllUsers.7z") Then ws.Run(str7Zcmd & "\101_AllUsers.7z -o" & """" & allusers & """"),0,True

the variable allusers is mapped to the environment variable %AllUsersProfile% elsewhere in the script. The thing to keep in mind is that with native WSH commands you often don't need to worry about long file names with spaces in them, but with ws.Run whatever is in there is being passed along to the command interpreter. So you do need to care. Keeping in mind the rule of using double quotes to simulate a quote, I figured (correctly) that using four quotes would simulate a double quote :wacko: Whenever you need to simulate a double quote however you need to seperate it off from the rest by use of the &.

EDIT: Got a little carried away there and forgot to mention that your options need to be outside of the parenthesis. Notice in the code above """"), 0, True. The options are after the closing parenthesis.

130_Streets.7z

Edited by RogueSpear
Link to comment
Share on other sites

You do not need extra backslashes in the path

("\"D:\Symantec AntiVirus.msi\" /qb-!", 1, True)

"D:\WMP10.exe /Q:A /C:\"setup_wm.exe /Q /R:N /DisallowSystemRestore\"",

I have included 2 examples I works the other does not work

This does not worked
Dim Act : Set Act = CreateObject("Wscript.shell")
Act.Run("D:\Net Radio Test.exe")1, True

This worked
Dim Act : Set Act = CreateObject("Wscript.shell")
Act.Run(chr(34) & "D:\Net Radio Test.exe" & chr(34)), 1, True

I have edited the Symantec so it correct. You may have to add chr(34) to this WMP code, but the rest is correct for it.
Dim Act : Set Act = CreateObject("Wscript.shell")
Act.Run(chr(34) & "D:\Symantec AntiVirus.msi\ /qb-!" & chr(34)), 1, True
Act.Run("D:\WMP10.exe /Q:A /C:\setup_wm.exe /Q /R:N /DisallowSystemRestore"), 1, True

Link to comment
Share on other sites

@ GunSmokingMan

Sorry GSM but it doesn't work...

I tried several combinations and most of the time I get a warning about "File not Found" for SAV10 or "Syntax error in command line" for WMP10

The extra backslashes (\") in the command line are there to escape the quote caracter... I don't understand why you kept them in your example:

You do not need extra backslashes in the path

I have edited the Symantec so it correct. You may have to add chr(34) to this WMP code, but the rest is correct for it.

Dim Act : Set Act = CreateObject("Wscript.shell")
Act.Run(chr(34) & "D:\Symantec AntiVirus.msi\ /qb-!" & chr(34)), 1, True
Act.Run("D:\WMP10.exe /Q:A /C:\setup_wm.exe /Q /R:N /DisallowSystemRestore"), 1, True

@ RogueSpear

OMG! I don't even know where to start to modify my syntax!

Regarding the parenthesis, I think there is several way to do this:

WshShell.Run("D:\SymantecAntiVirus.msi /qb-!", 1, True)
or
WshShell.Run("D:\SymantecAntiVirus.msi /qb-!"), 1, True
or
WshShell.Run "D:\SymantecAntiVirus.msi /qb-!", 1, True

All of them works!

Edited by Incroyable HULK
Link to comment
Share on other sites

It's amazing how often doubling up is overlooked in place of Chr(34).

I usually find it easier to test by replacing WshShell.Run with WScript.Echo and look at the screen output.

Anyway glad to have helped

Link to comment
Share on other sites

I will have to remeber using double quotes if the chr(34) does not work.

You may want to try a script like this this to install, I tested this on Vista to install Winamp, it worked.

Dim Act, Fso, Winamp
Set Act = CreateObject("Wscript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Winamp = Act.ExpandEnvironmentStrings("%Systemdrive%\Winamp5.msi")
If Fso.FileExists(Winamp) Then
Act.Run(winamp & " Xname=Spad Xkey=XXXXX-XXXXX-XXXXX-XXXXX Xagent=0 Xlibrary=0 Xintex=1 Xmodernskin=1 Xaudio=1 Xvideo=0 Xvisual=1 Xextra=1 Xregopt=0 /qr"),1,True
Fso.DeleteFile(Winamp)
End If

Another way using a Array

Dim Act, CT, Fso, Install
Set Act = CreateObject("Wscript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Install = Array(Act.ExpandEnvironmentStrings("%Systemdrive%\SomeApp1.msi"),_
Act.ExpandEnvironmentStrings("%Systemdrive%\SomeApp2.exe"),_
Act.ExpandEnvironmentStrings("%Systemdrive%\SomeApp3.msi"),_
Act.ExpandEnvironmentStrings("%Systemdrive%\SomeApp4.exe"),_
Act.ExpandEnvironmentStrings("%Systemdrive%\Some App 5.exe"))
CT = 0
For Each strApp In Install
CT = CT + 1
If Fso.FileExists(strApp) Then
If CT = 1 Then
Act.Run(strApp & " Xname=Spad Xkey=XXXXX-XXXXX-XXXXX-XXXXX Xagent=0 Xlibrary=0 Xintex=1 Xmodernskin=1 Xaudio=1 Xvideo=0 Xvisual=1 Xextra=1 Xregopt=0 /qr"),1,True
Fso.DeleteFile(strApp)
End If
If CT = 2 Then : Act.Run(strApp & " /silent"),1,True : Fso.DeleteFile(strApp) : End If
If CT = 3 Then : Act.Run(strApp & " /quiet /noreboot"),1,True : Fso.DeleteFile(strApp) : End If
If CT = 4 Then : Act.Run(strApp & " /s /q"),1,True : Fso.DeleteFile(strApp) : End If
If CT = 5 Then : Act.Run(Chr(34) & strApp & " /s /q" & Chr(34)),1,True : Fso.DeleteFile(strApp) : End If
End If
Next

Link to comment
Share on other sites

Just so you guys know, WMI is a bit faster and uses less resources when installing something from an .msi installer. I always try to minimize the amount of times the command interpreter is invoked. It generally makes for faster running less resource hogging scripts.

Link to comment
Share on other sites

Just so you guys know, WMI is a bit faster and uses less resources when installing something from an .msi installer. I always try to minimize the amount of times the command interpreter is invoked. It generally makes for faster running less resource hogging scripts.

You mean using the Win32_Products class?

Link to comment
Share on other sites

There's certainly something going on. If you take a look at the Symantec AntiVirus Corp V10 distribution, any of the 32-bit application installs (SAV, SSC, etc.) contain the two Windows Installer runtime files, but the SAV x64 client does not. Yet the 64-bit install is an .msi installer. I don't know if this is because XP x64 comes with a more up to date version of Windows Installer where as the 32-bit applications are supposed to be compatible all the way down to NT4.

I have a feeling all of this 64-bit stuff is going to require a lot of relearning and workarounds.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...