posts - 76, comments - 26, trackbacks - 0

DOS and VBS Syntax Reminders

From time to time I have to break out skills from my past.  I needed to solve a few problems today that required a VBS script and a couple of batch scripts.  It took me longer than I care to admit to remember how to do this.

So, this post is a reminder for my future self.

Here's how to set a local variable in DOS and use them, as well as how to use a system environment variable (WinDir):

   1: SET INTERNAL_ROOT_PATH=D:\foo\trunk
   2:  
   3: svn.exe update %INTERNAL_ROOT_PATH%
   4: %WinDir%\Microsoft.NET\Framework\v2.0.50727\msbuild.exe %INTERNAL_ROOT_PATH%\Internal.sln /Property:Config=Release

Here is how to load an XML file into XML DOM and parse it using MSXML2 and VBScript.  This is also an example of how to Echo messages to the shell and process arguments

   1:  
   2:     path = WScript.Arguments(0)
   3:     root = WScript.Arguments(1)
   4:     
   5:     gacpath = "D:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe"
   6:  
   7:     If WScript.Arguments.Count = 3 Then
   8:         gacpath = WScript.Arguments(2)
   9:     End If
  10:     
  11:     WScript.Echo WScript.Arguments.Count
  12:     WScript.Echo "Parsing LibraryManifest: " & path
  13:  
  14:     Set xml = CreateObject("MSXML2.DOMDocument")
  15:     With xml
  16:         .async = False 
  17:         .validateOnParse = False 
  18:         .preserveWhiteSpace = True
  19:         .resolveExternals = False 
  20:     End With
  21:     result = xml.load(path)
  22:  
  23:     Set moduleNodes = xml.selectNodes("//LibraryManifest/Module")
  24:  
  25:     If Not moduleNodes Is Nothing Then
  26:  
  27:         For Each moduleNode in moduleNodes
  28:             
  29:             Set assemblyNodes = moduleNode.selectNodes("Assembly")
  30:             
  31:             For Each assemblyNode in assemblyNodes
  32:             
  33:                 For Each attribute in assemblyNode.Attributes
  34:                     
  35:                     If attribute.Name = "Name" Then
  36:  
  37:                         file = root & "\" & attribute.Text
  38:  
  39:                         'WScript.Echo "file: " & file
  40:  
  41:                         Set shell = CreateObject("WScript.Shell")
  42:                         gacutil = gacpath & " -uf " & attribute.Text
  43:                         Set out = shell.Exec(gacutil)
  44:  
  45:                         Do While Not out.StdOut.AtEndOfStream
  46:                             WScript.Echo out.StdOut.ReadLine()
  47:                         Loop    
  48:  
  49:                         Set shell = CreateObject("WScript.Shell")
  50:                         gacutil = gacpath & " -if " & file
  51:  
  52:                         Set out = shell.Exec(gacutil)
  53:  
  54:                         Do While Not out.StdOut.AtEndOfStream
  55:                             WScript.Echo out.StdOut.ReadLine()
  56:                         Loop    
  57:  
  58:                         Set shell = Nothing
  59:                         Set out = Nothing
  60:  
  61:                     End If
  62:                 Next
  63:             Next
  64:         Next
  65:     End If
  66:     

Print | posted on Friday, August 22, 2008 12:00 AM | Filed Under [ cheatsheet development ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 8 and type the answer here:

Powered by: