bj-kaiser Posted June 29, 2009 Share Posted June 29, 2009 Option ExplicitConst strConnection = "RAS"Const strUsername = "UserXYZ"Dim oShellSet oShell = CreateObject ("WScript.Shell")'run command and wait for it to exitoShell.Run("rasdial.exe " & strConnection & " " & strUsername, 1, true)OK, I'm new to vbscript, can somebody point out what in heck is wrong with that script? it looks good to me...seems to be ok until WSH hits the "oShell.Run" line, there I get a compile error "no brackets allowed in subroutine call" or something like that. (german windows xp) Link to comment Share on other sites More sharing options...
Yzöwl Posted June 29, 2009 Share Posted June 29, 2009 Option ExplicitConst strConnection = "RAS"Const strUsername = "UserXYZ"Dim oShellSet oShell = CreateObject ("WScript.Shell")'run command and wait for it to exitoShell.Run("rasdial.exe " & strConnection & " " & strUsername, 1, true)OK, I'm new to vbscript, can somebody point out what in heck is wrong with that script? it looks good to me...seems to be ok until WSH hits the "oShell.Run" line, there I get a compile error "no brackets allowed in subroutine call" or something like that. (german windows xp)Try either one of the following:oShell.Run "rasdial.exe" & " " & strConnection & " " & strUsername, 1, trueoShell.Run("rasdial.exe" & " " & strConnection & " " & strUsername), 1, true Link to comment Share on other sites More sharing options...
Mijzelf Posted June 29, 2009 Share Posted June 29, 2009 Well then remove the brackets:oShell.Run "rasdial.exe " & strConnection & " " & strUsername, 1, trueWorks. Personally I hate VBScript for this kind of (apparent?) inconsistencies. CreateObject has to have brackets, and Run should not have. My advice is to use JScript instead. You can do the same things with a much more clear syntax. Link to comment Share on other sites More sharing options...
MHz Posted June 29, 2009 Share Posted June 29, 2009 (edited) ... I get a compile error "no brackets allowed in subroutine call" or something like that. (german windows xp)You will find that subroutines do not return a value so do not use brackets. On the use of functions with storing the returned value into a variable, then you may need to use brackets. I keep to that concept and has proven consistent with good results.So this should be finesubroutine "parameter"and thisvariable = function("parameter")The below (reversed usage of brackets) will occur error that I would expect.subroutine ("parameter")and thisvariable = function "parameter"So if it returns a value, then use brackets, else do not. I'm not sure by my memory atm about the following, but if you do not store the value of a function return, then do not use brackets (like a subroutines behavior) to avoid error. A function may require brackets if used with an IF statement like below to also avoid error.If function("parameter") ThenEdit:Added last sentence about using IF statement Edited June 29, 2009 by MHz Link to comment Share on other sites More sharing options...
bj-kaiser Posted June 29, 2009 Author Share Posted June 29, 2009 I figured it out by now... brackets without storing the value = BAD.one reason why I like AutoIt over vbscript... but for what I am working on I am trying to work with what comes in the box with Windows, since I dont want to add too much additional stuff. (Thin client system= XP embedde) Link to comment Share on other sites More sharing options...
Mijzelf Posted June 30, 2009 Share Posted June 30, 2009 but for what I am working on I am trying to work with what comes in the box with Windows, since I dont want to add too much additional stuff.JScript is as available as VBScript. It's the same engine (WScript.exe or CScript.exe), only a different syntax. Your code in JScript would be:var strConnection = "RAS";var strUsername = "UserXYZ";var oShell;oShell = WScript.CreateObject ("WScript.Shell");// run command and wait for it to exitoShell.Run("rasdial.exe " + strConnection + " " + strUsername, 1, true);save as .js file, and it just works. Link to comment Share on other sites More sharing options...
gunsmokingman Posted June 30, 2009 Share Posted June 30, 2009 You could just make this a oneline script.CreateObject ("WScript.Shell").Run("rasdial.exe RAS UserXYZ"),1,true Link to comment Share on other sites More sharing options...
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