SystemUtil.Run in UFT gives me “invalid procedure

2019-09-08 15:26发布

问题:

I'm using SystemUtil.Run (pathName) in UFT, VBScript. But it gives me

invalid procedure call or argument.

I'm sure about pathName, I'm sure about the command, I'm sure about everything. What do you think might be the cause?

回答1:

If you look at the examples here, you'll see that the approved call is

SystemUtil.Run pathName

(passing pathName per reference) instead of

SystemUtil.Run (pathName)

(passing a const copy).

Eric Lippert's essay should help you to understand the use of () in VBScript.

Evidence:

As I don't use UFT, I can only use .NET to demonstrate that the ()/parameter passing mode matters:

>> Set m_oSB = CreateObject("System.Text.StringBuilder")
>> aData = Split("a b c")
>> m_oSB.AppendFormat_4 "{0}-{1}-{2}", (aData)
>> WScript.Echo m_oSB.ToString()
>>
a-b-c
>> m_oSB.AppendFormat_4 "{0}-{1}-{2}", aData
>>
Error Number:       5
Error Description:  Invalid procedure call or argument
>>


回答2:

I have ran into the same issue. I had to write the full path name for the error to go away.

example: SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe", "www.google.com"

I hope this helps you.