1.

Solve : quick vbs help?

Answer» HI guys,

I'm converting a old (fully working batch file) to vbs. Mainly because I'm trying to learn vbs, but also because I can do a few extra things with vbs that can't be done via batch.

I'm using the following line (DOS) to install antivirus software silently.

Code: [Select]start /wait X:\setup.exe /s /v"/l*v log.txt /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress

my vbs version reads like this;

Code: [Select]If (objFSO.FolderExists("C:\Program Files\Symantec AntiVirus") = false) Then
shell.run """X:\setup.exe"" /s /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress", 1, True
end if

If you look closely you see that I've had to remove some of the switch's as the DOS version contained an extra " which confuses vbs.


Is there a way to have an extra " within a pair of " " while still having the commented section run to the last "


example;

"some stuff here - an extra " would stop the comments there, but I'd like to contine you here."

any ideas???

EDIT;

I have since made a new varaible with the full command (including the extra "). I managed to use the chr(34) to add it.

The problem now is I'm unsure how to run a .exe file with paramaters as a varaible.

any ideas??I've never encountered quotes and stars as run time switches, but hey, according to the TV, I'm no smarter than a fifth grader

This will balance the quotes, but testing this was limited. Perhaps it will work.

Code: [Select]shell.run """X:\setup.exe /s /v""/l*v /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress""", 1, True

Quote
but also because I can do a few extra things with vbs that can't be done via batch.

This should win the understatement of the month award.

Cheers for the reply.

Quote from: Sidewinder on May 22, 2008, 05:16:59 AM

shell.run """X:\setup.exe /s /v""/l*v /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress""", 1, True


Sadly that doesn't work, it looks for a file name "x:\setup.exe /s /v" and so keeps failing.

I have managed to build a varaiable with all the swicth's:

/s /v"/l*v log.txt /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress

but I'm unsure how to get this varaiable in to the rull command. I've tried;

shell.run "x:\setup.exe", commands, 1, true

but it doesn't go. Shell.exec seems to have the same problem. Or have I missed something???


Quote
I have since made a new varaible with the full command (including the extra "). I managed to use the chr(34) to add it.

Can you not concatenate the strings on the run method:

Code: [Select]shell.run "X:\setup.exe " & parameterstring,1,True

Note: the space between setup.exe and the end quote.

Are there really quotes and stars in the parameter string? This seems very strange to me especially where switches are USED.

You may have to experiment with quotes or double quotes on the parameter string.



I've used your suggested code and from a small test case it seems to work great.

I'm working on a larger script to install programs, make system changes and generally make a fresh install of XP ready for a new user to log on.

I'm just installing XP on another machine, once that has finished I'll GIVE it a bash and I'll update you.

Cheers again sidewinder.

UPDATE:

I've noticed that if a pass this long string to a batch file and echo %1 I get everyting up to the first space, when it stops.

vbs script;

Code: [Select]set shell = WScript.CreateObject("Wscript.Shell")

par = "/s /v"
par2 = "/l*v log.txt /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress"

compar = par + Chr(34) + par2

WScript.Echo compar

shell.run "C:\echo.bat " & compar, 1, True

wscript.quit


batch file to display echo;

Code: [Select]@echo off

echo %1

pause
exit

if you run these you'll see what I mean.

Is there a way to get %1 to see passed the space?

cheers again.Not sure what you're asking. My results displayed the entire string:

Quote
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

/s /v"/l*v log.txt /qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress

I get the same results with both CScript and WScript. If your results are different try changing echo.bat as batch code uses the space as a default delimiter:

Code: [Select]@echo off

echo %*

pause
exit

Hope this helps.
Nice,

echo %* does the job.

I think this is my problem. I guessing the setup.exe will only take %1. (hench why everytime I run it, it just opens the setup.exe and doesn't install)

I think I might have to start a batch file in vbs and have the batch file do the work. (tacky)

what do you reakon??? Quote
I think I might have to start a batch file in vbs and have the batch file do the work. (tacky)

I had a problem similar to this only the passed parameter was a switch followed by a path with those pesky embedded spaces.

Quote
I think this is my problem. I guessing the setup.exe will only take %1. (hench why everytime I run it, it just opens the setup.exe and doesn't install)

I'm guessing only the log.txt is resolving to %1 (in batch speak). The other parms should are switches and keywords which are not positional and are handled differently by the program.

This mishmash sets up a string with the embedded quote and the quotes around the entire string that the run method requires

Code: [Select]str = """X:\setup.exe /s /v" & """/l*v""" & " Log.txt " & """/qn NETWORKTYPE=1 SERVERNAME=basdc01 ENABLEAUTOPROTECT=1 RUNLIVEUPDATE=0 REBOOT=ReallySuppress"""
shell.Run str, 1, True

I'll let you test this and you can let us know how you made out.

PS. You don't have to build a string. Should be ok inline on the shell.run statement.
or just add the ascii value for " in the string, that works fine for me when I do stuff like thatHi guys,

Sorry I forgot I started this thread !!

I've got it running now, by using a bacth file to run the ACTUAL install. works a treat.



Cheers for all your help


Discussion

No Comment Found