djones Posted December 16, 2008 Posted December 16, 2008 I am in the process of amending our M$ Office installations (specifically Outlook) with new email service settings etc. I am using the 'maintwiz.exe' and a CMW file which runs correctly when called using: "\\server\applications$\Office 2k3\MaintWiz.exe" /c "\\server\applications$\Office 2k3\OfficeUpdate.CMW" /qb- However, I am now at the stage where I'd like to incorporate this command into a startup script and so far have tried to run the command as part of a vbs script using: Set objShell = CreateObject("Wscript.Shell") objShell.Run "\\server\applications$\Office 2k3\MaintWiz.exe" /c "\\server\applications$\Office 2k3\OfficeUpdate.CMW" /qb- ...but this fails, I presume because of the quotes, and more specifically, having two sets of quotes on the same line/command? Eventually, I'd like to have a flag file set on successful completion so that the script is only run once (i.e. script checks for flag file beforehand etc...) but I have no idea how to go about that bit. Cheers, Dave.
ChrisH Posted December 16, 2008 Posted December 16, 2008 (edited) You will have to escape the extra quotes by doing doing double quotes, which can get complicated or use the chr() function to insert the quotes to the string. Either way it is better to build the string up and assign it to a variable eg CMDLine= ""\\server\applications$\Office 2k3\MaintWiz.exe"" /c ""\\server\applications$\Office 2k3\OfficeUpdate.CMW"" /qb-" That probably isnt 100% accurate but you get the idea the other way would be CMDLine=Chr(34) & "\\server\applications$\Office 2k3\MaintWiz.exe" & Chr(34) & "/c " & Chr(34) & "\\server\applications$\Office 2k3\OfficeUpdate.CMW" & Chr(34) & " /qb-"" Again probably not 100% accurate but you get the right idea then it would just be a case of: Set objShell = CreateObject("Wscript.Shell") objShell.Run CMDLine Edited December 16, 2008 by ChrisH Wrong concat operator for VBS :P 1
srochford Posted December 16, 2008 Posted December 16, 2008 Whenever I get stuck with things like this, I build the line like @ChrisH and then check it by sticking in a wscript.echo - that way you can see if you've got the quotes right. Also worth using a text editor which understands the syntax - it will then highlight literals etc and you can see better if the quotes are correct as you type. 1
djones Posted December 16, 2008 Author Posted December 16, 2008 Great, thanks - and very speedy too! The second one seems to have done the trick with not generating any error messages at least. I'll have to wait until the morning to see if it really works properly though. Now, how about the checking for / creating flag files to ensure the command is only run once? Dave
djones Posted December 16, 2008 Author Posted December 16, 2008 Whenever I get stuck with things like this, I build the line like @ChrisH and then check it by sticking in a wscript.echo - that way you can see if you've got the quotes right. Also worth using a text editor which understands the syntax - it will then highlight literals etc and you can see better if the quotes are correct as you type. Cheers Steve. Can you suggest any favourite editors? I've used UltraEdit in the past.
RabbieBurns Posted December 16, 2008 Posted December 16, 2008 notepad++ is great. Easily as good as UE in my opinion.
ChrisH Posted December 16, 2008 Posted December 16, 2008 Great, thanks - and very speedy too! The second one seems to have done the trick with not generating any error messages at least. I'll have to wait until the morning to see if it really works properly though. Now, how about the checking for / creating flag files to ensure the command is only run once? Dave I would create a textfile with a certain name to show its run or look for one of the new files/folder that the new install creates. If not FileName.exist Something like that. 1
djones Posted December 16, 2008 Author Posted December 16, 2008 So... ' Set Environment Variables Dim filesys Set filesys = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") 'Build & Run Command CMDLine=Chr(34) & "\\server\applications$\Office 2k3\MaintWiz.exe" & Chr(34) + "/c " & Chr(34) & "\\server\applications$\Office 2k3\OfficeUpdate.CMW" & Chr(34) & " /qb-" ' Check Previous Run State If Not filesys.FileExists("C:\OfficeUpdate.txt") Then objShell.Run CMDLine filesys.CreateTextFile "c:\OfficeUpdate.txt", True End If ...something like this?
djones Posted December 17, 2008 Author Posted December 17, 2008 Ok...that hasn't worked either. If I use a bat script to run the command it works but not as a vbs script.
ChrisH Posted December 17, 2008 Posted December 17, 2008 You have include a "+" which I edited. I was having abrain freeze and couldn't remember the VBS concat operator as I have been scripting in other stuff recently. Change + to & 1
srochford Posted December 18, 2008 Posted December 18, 2008 Cheers Steve. Can you suggest any favourite editors? I've used UltraEdit in the past. I mostly use Context It's free, it works reasonably well but development has pretty much stopped (and there's some pretty acrimonious discussions in the forums about it!)
djones Posted December 18, 2008 Author Posted December 18, 2008 Ok, this is what I've come up with. The only bit that remains untested (as I've only just added it) is the creation of a log file during the CMW process. This is then the file that is subsequently checked for to see if running the CMW is necessary another time the script is run. This will hopefully allow me to keep the script as a semi-permanent startup script for any future changes to the Office installations. '~~~~~~~~~~~~~~ Set Environment Variables ~~~~~~~~~~~~~~~~ Dim filesys Set filesys = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") strApp = "\\server\applications$\Office 2k3\MAINTWIZ.EXE" strCfgFile = "\\server\applications$\Office 2k3\UpdateOutlook.CMW" strLogFile = "C:\Program Files\Microsoft Office\CMW_Dec08.txt" strTitle = "Office 2003 Custom Maintenance Wizard" '~~~~~~~~~~~~~~ Check Previous Run State ~~~~~~~~~~~~~~~~~ If Not filesys.FileExists("C:\Program Files\Microsoft Office\CMW_Dec08.txt") Then '~~~~~~~~~~~~~~ Run Command If Necessary ~~~~~~~~~~~~~~~~~ objShell.Run "%comspec% /c title " & strTitle & "|" & Chr(34) & strApp & Chr(34) & " /c " & Chr(34) & strCfgFile & Chr(34) & " /qb-" & " /l " & Chr(34) & strLogFile & Chr(34) ,,true End If In case anyone else on here is wondering or needs it in the future, the code for adding a file (to use as the basis for checking) is here: filesys.CreateTextFile "C:\Program Files\Microsoft Office\CMW_Dec08.txt", True This is what I had before using the log file option.
DMcCoy Posted December 18, 2008 Posted December 18, 2008 Is %comspec% going to work? I didn't think vbs understood the environmental variables in that way
djones Posted December 18, 2008 Author Posted December 18, 2008 Just reread it and had a thought... I could, presumably, replace the path in this line... '~~~~~~~~~~~~~~ Check Previous Run State ~~~~~~~~~~~~~~~~~ If Not filesys.FileExists("C:\Program Files\Microsoft Office\CMW_Dec08.txt") Then ...with the variable set for the log file... '~~~~~~~~~~~~~~ Check Previous Run State ~~~~~~~~~~~~~~~~~ If Not filesys.FileExists(strLogFile) Then
djones Posted December 18, 2008 Author Posted December 18, 2008 Is %comspec% going to work? I didn't think vbs understood the environmental variables in that way It appears to work fine - I did copy that part from another example somewhere in Internet land when trying to find ways of using variables to make future editing and explaining to others easier. I have no idea what it actually means though!! ;-) Edit: "In the land of the blind, the one-eyed man is King!"
DMcCoy Posted December 18, 2008 Posted December 18, 2008 It's the location of cmd ComSpec=C:\WINDOWS\system32\cmd.exe And, no vbs won't expand it although you could try importing it Set oShell = CreateObject( "WScript.Shell" ) comspec=oShell.ExpandEnvironmentStrings("%ComSpec%")
djones Posted December 18, 2008 Author Posted December 18, 2008 So if it just runs the cmd.exe, do I really need it? If not then I might as well simplify things again and just use this... '~~~~~~~~~~~~~~ Set Environment Variables ~~~~~~~~~~~~~~~~ Dim filesys Set filesys = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") strApp = "\\server\applications$\Office 2k3\MAINTWIZ.EXE" strCfgFile = "\\server\applications$\Office 2k3\UpdateOutlook.CMW" strLogFile = "C:\Program Files\Microsoft Office\CMW_Dec08.txt" '~~~~~~~~~~~~~~ Build Run Command ~~~~~~~~~~~~~~~~~~~~~~~~ CMDLine=Chr(34) & strApp & Chr(34) & " /c " & Chr(34) & strCfgFile & Chr(34) & " /qb-" & " /l " & Chr(34) & strLogFile & Chr(34) '~~~~~~~~~~~~~~ Check Previous Run State ~~~~~~~~~~~~~~~~~ If Not filesys.FileExists(strLogFile) Then '~~~~~~~~~~~~~~ Run Command If Necessary ~~~~~~~~~~~~~~~~~ objShell.Run CMDLine, True End If
DMcCoy Posted December 18, 2008 Posted December 18, 2008 %comspec% is special it will work. Hmm, ok then. I didn't know that So vbs can't directly use environmental variables *except* comspec because it's different and it makes it harder to remember!
ChrisH Posted December 18, 2008 Posted December 18, 2008 Hmm, ok then. I didn't know that So vbs can't directly use environmental variables *except* comspec because it's different and it makes it harder to remember! Thats pretty much it . They should of really made it look like something else but they like to keep us on our toes . If you google it you will find plenty of code without a mention of expanding it.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now