3

I have a VBScript that accepts 5 arguments as parameters from command line. Two of the 5 arguments contains complete absolute path to some .txt file, so the command line parameter length might get so long and my automation script may fail in such case.

Can someone tell me if we have any restriction on text length to be passed in command line for VBScript? Actually, I want to know, if there's limit from VB script point of view ?

I am running the script as follows:

cscript.exe Sample.vbs "C:\Program Files\z.txt" param2 param3 D:\abcd.txt param5
Prashant2329
  • 327
  • 3
  • 7
  • 21
  • 1
    possible duplicate of [Maximum Length of Command Line String](http://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string) – Ansgar Wiechers May 25 '15 at 12:26
  • I have modified my question .. Actually, I want to know, if there's limit from VB script point of view ? – Prashant2329 May 26 '15 at 05:58
  • 2
    The limitations outlined in the answers (and comments) to the other question apply to VBScript as well. AFAIK there's no additional VBScript-specific limit. – Ansgar Wiechers May 26 '15 at 08:06
  • I didn't know if there's any .. Thanks to all.. Derek's answer that specified "Script: C:\temp\vbscripttest\a.vbs Line: 9 Char: 1 Error: The filename or extension is too long. Code: 800700CE Source: (null)" helped me to solve my issue... – Prashant2329 May 27 '15 at 05:10

1 Answers1

2

I found this: http://blogs.msdn.com/b/oldnewthing/archive/2003/12/10/56028.aspx

But your best bet is to test it out yourself. Try calling it with an insanely long string, then in your vb script output the string, or output the string's length. I don't think you are going to have a problem with file path lengths.

a.vbs

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")

Dim arguments
For i = 1 To 6540
  arguments = arguments & LPad(i,4,"0") & ","
Next

objShell.Run "b.vbs " & arguments

' Using Set is mandatory
Set objShell = Nothing


Function LPad(s, l, c)
  Dim n : n = 0
  If l > Len(s) Then n = l - Len(s)
  LPad = String(n, c) & s
End Function

b.vbs

WriteString "C:\temp\vbscripttest\c.txt",WScript.Arguments.Item(0) 

Function WriteString( filename, contents )
    Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile( filename,2,true)
    objFileToWrite.WriteLine(contents)
    objFileToWrite.Close
    Set objFileToWrite = Nothing
End Function

It maxed out at 6540 * 5 characters = 32700. You can play around with it more if you want. If I put 6541, I got:


Windows Script Host

Script: C:\temp\vbscripttest\a.vbs Line: 9 Char: 1 Error: The filename or extension is too long. Code: 800700CE Source: (null)


OK

Derek
  • 7,615
  • 5
  • 33
  • 58
  • Actually, I want to know, if there's limit from VB script point of view ? – Prashant2329 May 26 '15 at 05:57
  • But you might want to tweak the test to execute the script exactly as you are going to call it. e.g. cscript.exe Sample.vbs OneReallyLongStringHere – Derek May 26 '15 at 11:04
  • Thanks a lot Derek.. The "Script: C:\temp\vbscripttest\a.vbs Line: 9 Char: 1 Error: The filename or extension is too long. Code: 800700CE Source: (null)" helped me solve my problem.. Once again Thanks a lot .. – Prashant2329 May 27 '15 at 05:12