+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
Scripts Thread, vbs complex run commands in Coding and Web Development; I am in the process of amending our M$ Office installations (specifically Outlook) with new email service settings etc. I ...
  1. #1

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15

    vbs complex run commands

    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:

    Code:
    "\\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:

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

  2. IDG Tech News
  3. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,973
    Thank Post
    100
    Thanked 244 Times in 223 Posts
    Rep Power
    98
    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

    Code:
    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

    Code:
    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:

    Code:
    Set objShell = CreateObject("Wscript.Shell")	
    objShell.Run CMDLine
    Last edited by ChrisH; 16th December 2008 at 10:45 PM. Reason: Wrong concat operator for VBS :P

  4. Thanks to ChrisH from:

    djones (16th December 2008)

  5. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,122
    Thank Post
    111
    Thanked 516 Times in 446 Posts
    Blog Entries
    2
    Rep Power
    117
    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.

  6. Thanks to srochford from:

    djones (16th December 2008)

  7. #4

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    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

  8. #5

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    Quote Originally Posted by srochford View Post
    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.

  9. #6

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,327
    Thank Post
    1,262
    Thanked 459 Times in 299 Posts
    Blog Entries
    6
    Rep Power
    156
    notepad++ is great. Easily as good as UE in my opinion.

  10. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,973
    Thank Post
    100
    Thanked 244 Times in 223 Posts
    Rep Power
    98
    Quote Originally Posted by djones View Post
    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.

    Code:
    If not FileName.exist
    Something like that.

  11. Thanks to ChrisH from:

    djones (16th December 2008)

  12. #8

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    So...

    Code:
    ' 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?

  13. #9

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    Ok...that hasn't worked either. If I use a bat script to run the command it works but not as a vbs script.

  14. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,973
    Thank Post
    100
    Thanked 244 Times in 223 Posts
    Rep Power
    98
    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 &

  15. Thanks to ChrisH from:

    djones (17th December 2008)

  16. #11

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,122
    Thank Post
    111
    Thanked 516 Times in 446 Posts
    Blog Entries
    2
    Rep Power
    117
    Quote Originally Posted by djones View Post
    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!)

  17. #12

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    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.

    Code:
    '~~~~~~~~~~~~~~ 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:

    Code:
    filesys.CreateTextFile "C:\Program Files\Microsoft Office\CMW_Dec08.txt", True
    This is what I had before using the log file option.

  18. #13
    DMcCoy's Avatar
    Join Date
    Oct 2005
    Location
    Isle of Wight
    Posts
    3,231
    Thank Post
    10
    Thanked 443 Times in 387 Posts
    Rep Power
    101
    Is %comspec% going to work? I didn't think vbs understood the environmental variables in that way

  19. #14

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    Just reread it and had a thought... I could, presumably, replace the path in this line...

    Code:
    '~~~~~~~~~~~~~~ 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...

    Code:
    '~~~~~~~~~~~~~~ Check Previous Run State ~~~~~~~~~~~~~~~~~
    
    If Not filesys.FileExists(strLogFile) Then

  20. #15

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    293
    Thank Post
    57
    Thanked 23 Times in 20 Posts
    Rep Power
    15
    Quote Originally Posted by DMcCoy View Post
    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!"

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. VBS startup scripts won't run
    By GoldenWonder in forum Windows
    Replies: 2
    Last Post: 10th September 2009, 10:38 PM
  2. Me + The Sims = God complex!
    By Little-Miss in forum Gaming
    Replies: 9
    Last Post: 10th November 2008, 04:23 PM
  3. Replies: 1
    Last Post: 7th December 2007, 07:58 PM
  4. Server 2003 run commands.
    By starscream in forum Wireless Networks
    Replies: 3
    Last Post: 26th June 2007, 10:49 AM
  5. Replies: 4
    Last Post: 7th March 2007, 03:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •