Software > Computer programming

Script I stumbled upon...

(1/2) > >>

I came across this script last week and tried it out for WSL, it works great - is there a downside to using it that anyone can see?

--- Code: ---C:\wsl\bat-launcher.vbs

If WScript.Arguments.Count <= 0 Then
End If

bat = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")) & WScript.Arguments(0) & ".bat"
arg = ""

If WScript.Arguments.Count > 1 Then
    arg = WScript.Arguments(1)
End If

CreateObject("WScript.Shell").Run """" & bat & """ """ & arg & """", 0, False
--- End code ---

<edit> I guess I should describe what it does - it runs my batch file and hides the annoying flashing console </edit>

Is WSL Windows Subsystem for Linux?

Salmon Trout:
No downside, at least in operation, as long as the batch script actually exists in the script folder. Did you write it yourself? What I write about it depends on your answer.

Another question - do you really need to pass a parameter to the batch script?

What do you mean by WSL?

I will say this pending your reply...

If you just want to run a named batch invisibly, and you don't need to pass a parameter to the batch. this is all you need

If it is called Myrun.vbs, use it like so - Myrun.vbs batname.bat

CreateObject("WScript.Shell").Run """" & wscript.arguments(0) & """", 0, False

Yes, Windows Subsystem for Linux
No, I didn't write it, like I said I just stumbled across it looking for information about Ubuntu installs on WSL
Yes, it seems to do what it says it does.
I don't know enough about scripting to know if it's actually safe to use though

<edit> I haven't any idea what parameter is being passed </edit>

<edit2> Could the parameter be setting some condition to exist for XFCE?  </edit2>

Salmon Trout:
It's safe, as long as you use it to run your own batch scripts. Script kiddies use the technique to run batch scripts without any betraying console window. As VBS scripts go, it's a bit crude. Like it was written by someone just starting out. It helpfully checks that you supplied some parameters, but silently quits if you didn't, and makes you supply the batch bare name and adds '.bat' to it, and decodes the script name to get its folder name, none of which is necessary. And all without checking if the batch actually exists.


[0] Message Index

[#] Next page

Go to full version