Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Script I stumbled upon...  (Read 897 times)

0 Members and 1 Guest are viewing this topic.

Quantos

    Topic Starter


    Guru
  • Keep Calm - Press Play
  • Thanked: 168
    • Yes
    • Yes
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Linux variant
Script I stumbled upon...
« on: April 30, 2019, 12:41:17 PM »
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: [Select]
C:\wsl\bat-launcher.vbs

If WScript.Arguments.Count <= 0 Then
    WScript.Quit
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

<edit> I guess I should describe what it does - it runs my batch file and hides the annoying flashing console </edit>
Do You Think When You Act Or Just Act Like You’re Thinking?

DaveLembke



    Sage
  • Inventor of the Magna-Broom 3000 =)
  • Thanked: 635
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Script I stumbled upon...
« Reply #1 on: April 30, 2019, 02:08:39 PM »

Salmon Trout



    Genius

    Thanked: 968
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Other
Re: Script I stumbled upon...
« Reply #2 on: April 30, 2019, 02:12:21 PM »
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


« Last Edit: April 30, 2019, 02:26:00 PM by Salmon Trout »

Quantos

    Topic Starter


    Guru
  • Keep Calm - Press Play
  • Thanked: 168
    • Yes
    • Yes
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Linux variant
Re: Script I stumbled upon...
« Reply #3 on: April 30, 2019, 02:44:22 PM »
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>
Do You Think When You Act Or Just Act Like You’re Thinking?

Salmon Trout



    Genius

    Thanked: 968
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Other
Re: Script I stumbled upon...
« Reply #4 on: April 30, 2019, 02:49:46 PM »
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.

Salmon Trout



    Genius

    Thanked: 968
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Other
Re: Script I stumbled upon...
« Reply #5 on: April 30, 2019, 02:52:20 PM »
<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>


More context needed. A link?


Salmon Trout



    Genius

    Thanked: 968
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Other
Re: Script I stumbled upon...
« Reply #6 on: April 30, 2019, 03:06:22 PM »
<edit2> Could the parameter be setting some condition to exist for XFCE?  </edit2>

Strange not to do it in WSL. I have installed LXDE in my Ubuntu WSL, and use a VNC server to get an X desktop, but I didn't need batch files to do it.

Quantos

    Topic Starter


    Guru
  • Keep Calm - Press Play
  • Thanked: 168
    • Yes
    • Yes
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Linux variant
Re: Script I stumbled upon...
« Reply #7 on: April 30, 2019, 04:45:32 PM »
More context needed. A link?

Oh sure, it took a few to find it - https://token2shell.com/howto/x410/creating-shortcut-for-wsl-gui-desktop/
That's where I found the script
Do You Think When You Act Or Just Act Like You’re Thinking?