is there a way to make this batch into a vbs

Discussion in 'Software' started by red death68, Jul 2, 2011.

  1. red death68

    red death68 Command Sergeant Major

    ok so im deciding to completly cut batch from my project since some people may have cmd blocked and it would break the program so im sticking strictly to vbs and hta i need to convert this script here

    Code:
    @echo off
    
    :start
    
    setlocal enabledelayedexpansion
    set SEPARATOR=/
    set filecontent=
    for /f "delims=" %%a in (option1.txt) do (
      set currentline=%%a
      set filecontent2=!filecontent!%SEPARATOR%!currentline!
    )
    
    setlocal enabledelayedexpansion
    set SEPARATOR=/
    set filecontent=
    for /f "delims=" %%a in (option2.txt) do (
      set currentline=%%a
      set filecontent3=!filecontent!%SEPARATOR%!currentline!
    )
    
    setlocal enabledelayedexpansion
    set SEPARATOR=/
    set filecontent=
    for /f "delims=" %%a in (option3.txt) do (
      set currentline=%%a
      set filecontent4=!filecontent!%SEPARATOR%!currentline!
    )
    
    setlocal enabledelayedexpansion
    set SEPARATOR=/
    set filecontent=
    for /f "delims=" %%a in (option4.txt) do (
      set currentline=%%a
      set filecontent5=!filecontent!%SEPARATOR%!currentline!
    )
    
    setlocal enabledelayedexpansion
    set SEPARATOR=/
    set filecontent=
    for /f "delims=" %%a in (option5.txt) do (
      set currentline=%%a
      set filecontent6=!filecontent!%SEPARATOR%!currentline!
    )
    
    
    :sound
    if /i "%filecontent2%" == "/sound" goto :copy-s
    goto :background
    
    
    :background
    if /i "%filecontent3%" == "/background" goto :copy-bg
    goto :bgm
    
    :bgm
    if /i "%filecontent4%" == "/background music" goto :copy-bgm
    goto :ui
    
    :ui
    if /i "%filecontent5%" == "/user interface" goto :copy-ui
    goto :km
    
    :km
    if /i "%filecontent6%" == "/kill marks" goto :copy-km
    goto eof
    
    :copy-s
    start sounds.vbs
    goto :background
    
    :copy-bg
    start bg.vbs
    goto :bgm
    
    :copy-bgm
    start bgm.vbs
    goto :ui
    
    :copy-ui
    start ui.vbs
    goto :km
    
    :copy-km
    start km.vbs
    goto eof
    
    to a vbs equivilent but im horribly new to vbs and wouldnt know where to start
     
  2. GermanOne

    GermanOne Guest

    True, but VBS could be disabled as well.
    BTW Your Batch code should look like that:
    Code:
    @echo off
    
    for /f "delims=" %%a in (option1.txt) do set "filecontent2=/%%a"
    for /f "delims=" %%a in (option2.txt) do set "filecontent3=/%%a"
    for /f "delims=" %%a in (option3.txt) do set "filecontent4=/%%a"
    for /f "delims=" %%a in (option4.txt) do set "filecontent5=/%%a"
    for /f "delims=" %%a in (option5.txt) do set "filecontent6=/%%a"
    
    if /i "%filecontent2%" == "/sound" start sounds.vbs
    if /i "%filecontent3%" == "/background" start bg.vbs
    if /i "%filecontent4%" == "/background music" start bgm.vbs
    if /i "%filecontent5%" == "/user interface" start ui.vbs
    if /i "%filecontent6%" == "/kill marks" start km.vbs
    
    One question before I will convert it to VBS. How many lines are saved in your .txt files?

    Regards
    GermanOne
     
  3. red death68

    red death68 Command Sergeant Major

    one line in each text doc and how common is iit to have vbs disabled? especialy since target audience is gamers?
     
  4. GermanOne

    GermanOne Guest

    Depends on the administration. VBS is not needed for games.
    Try that code.
    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objWSh = CreateObject("WScript.Shell")
    On Error Resume Next
    If LCase(objFSO.OpenTextFile("option1.txt").ReadLine) = "sound" Then objWSh.Run "sounds.vbs"
    If LCase(objFSO.OpenTextFile("option2.txt").ReadLine) = "background" Then objWSh.Run "bg.vbs"
    If LCase(objFSO.OpenTextFile("option3.txt").ReadLine) = "background music" Then objWSh.Run "bgm.vbs"
    If LCase(objFSO.OpenTextFile("option4.txt").ReadLine) = "user interface" Then objWSh.Run "ui.vbs"
    If LCase(objFSO.OpenTextFile("option5.txt").ReadLine) = "kill marks" Then objWSh.Run "km.vbs"
    
    Regards
    GermanOne
     
  5. red death68

    red death68 Command Sergeant Major

    works like a charm man

    ima assume most people have vbs enabled only because most users will realy on a personal computer not an administrated one from say a school or place of buissness(at least i hope)
     
  6. GermanOne

    GermanOne Guest

    Fine, but I don't understand why you have to write and read files. As far as I remember you're writing the files depending on the values of check boxes in your .hta. Why not directly start your scripts depending on this values?
    Well, in this case also cmd isn't blocked by default. But of course it's a better style to use only one language.

    Regards
    GermanOne
     
  7. red death68

    red death68 Command Sergeant Major

    in my exp cmd is blocked the most often of the 2 and cmd windows tend to make not so techy users nervus

    i may incorperate everything into a single hta later but right now its been months after the original release date i was gonna use so i figure its best to get it out first before i starts combining code and what not
     
  8. GermanOne

    GermanOne Guest

    Haha, agreed :-D It looks outmoded DOS-like and the user could close it before the program is finished.

    Yeah, thats a way to get it step by step. The reason why I suggest to write an all-in-one code is that the calling of other scripts and the writing/reading of files will waste a lot of time (on my machine approx. 250 ms for each). It slows down your code enormously. Further more you will not find a slick program on your PC which will save temporary values in files (except of settings (.ini, .xml ...), logs or similar). That's not a good style ;)

    Regards
    GermanOne
     
  9. red death68

    red death68 Command Sergeant Major

    they also tend to not know whats happening and assume its a virus

    i will work on the full combo of code into the single hta soon right now im doing a few more minor codes and then creating a custom ui then i will release temperarly before i combine whole code instead


    also since vbs may be blocked any suggestion to unblock it run program and reblock it

    im assuming probably java script to do this
     
    Last edited: Jul 5, 2011
  10. GermanOne

    GermanOne Guest

    No. It's a registry setting. Changing it will not cause an effect. You have to restart your Windows session or explorer.exe. Also, users with disabled cmd or WSH will probably not have access to these registry values.

    Read:
    Disabling Windows Script Host
    VBS and JS, both belong to the WSH. If the WSH is disabled ... hmm, no.
    OK, JS and Java Script seem to be the same thing, but it isn't. But afaik there is no stand-allone Java Script file (only JS) and I'm not sure whether Java Script in HTA is parsed as JS (because HTA is Microsoft) :confused

    Regards
    GermanOne
     
  11. red death68

    red death68 Command Sergeant Major

    o well ill worry about it if the problem arises then since i dont see many people having vbs disabled and i will be learning some programming soon when i start college aug 25th
     
  12. GermanOne

    GermanOne Guest

    I'm going to learn C++. Maybe you could teach me some programming in a while.

    Regards
    GermanOne
     
  13. PC-XT

    PC-XT Master Sergeant

    MS only uses JScript, saying it is better than JavaScript. The kind used in IE, HTA, WSH, and classic ASP is called Active Scripting JScript because it uses an Active Scripting engine. There is also a new one for .NET.

    Both JavaScript and JScript can be abbreviated JS as a generic name, since they are closer than most other ECMAScript dialects, such as Flash ActionScript. JS can basically be assumed to mean JScript in MS context, ECMAScript in Opera, and JavaScript otherwise. JScript was initially designed to be the same language as JavaScript with extra features, like a Y2K-compliant Date object rather than the one based on Java.util.Date. The name was only changed to avoid trademark issues, however, they are different enough that it pays to know which dialect you are working with.
     
  14. GermanOne

    GermanOne Guest

    Yes, I know the differences between JavaScrip, JScript and ECMAScript. And sorry for confusing, when I wrote JS I meant the M$ JScript.
    That's the point where I wasn't sure. You can define the language
    Code:
    <script language="jscript">...</script>
    or
    Code:
    <script language="javascript">...</script>
    Both will work also in a HTA. But what script engine is used? Has mshta.exe its own script engine? Will disabling of WSH affect it?

    Regards
    GermanOne
     
  15. red death68

    red death68 Command Sergeant Major

    its my understanding u cant use wscript in hta
     
  16. GermanOne

    GermanOne Guest

    That's not the same. You cannot use the WScript Object in HTA and a *.hta file is parsed by mshta.exe, not by wscript.exe or cscript.exe which are parsing e.g. *.vbs and *.js files.
    Latest I'm not sure whether the script engines (.dll files) for the script interpretation are the same for HTA and for stand-alone VBS or JS files. Also I'm not sure whether disabling WSH will affect the script codes inside of HTAs.

    Regards
    GermanOne
     
  17. red death68

    red death68 Command Sergeant Major

    i see what your saying only way to know would be extensie tests like disabling wsh and trying to run an hta and by removing dll's ments for js and vbs and then try running the hta

    by the way do all computers come standerd with mshta?
     
  18. GermanOne

    GermanOne Guest

    I agree. I was just wondering if somebody could answer these issues without testing by myself.


    As far as I remember HTA doesn't work without Internet Explorer (min. version 5). Not sure whether it comes with windows by default. On each computer I ever bought the Internet Explorer was pre installed.

    Regards
    GermanOne
     
  19. red death68

    red death68 Command Sergeant Major

    well since pretty much everyone has internet explorer im gonna assume it works

    and if u can provide a list of dll's i got a junk computer i can test on to answer these questions
     
  20. PC-XT

    PC-XT Master Sergeant

    HTA and WSH both use Windows Script, which has one engine for each language, so they both use the same JScript Active Scripting engine. It is installed with IE5+ and with Windows 98 and higher by default. I think it is possible to just disable WSH stand-alone script files, (cscript and wscript,) but continue to use Windows Script through other programs, like IE. I might test it myself...
     
  21. GermanOne

    GermanOne Guest

    Thanks for this information.

    Regards
    GermanOne
     
  22. PC-XT

    PC-XT Master Sergeant

    I tried the link given to Disable Windows Script Host on an XP, and it only disabled cscript and wscript. HTA still worked.

    cscript and wscript are also the only ones listed in
    HKLM\SOFTWARE\Microsoft\Windows Scripting Host\Locations
     
  23. GermanOne

    GermanOne Guest

    Thanks for testing.
    I'm not surprised. Jscript.dll and vbscript.dll are accessible for mshta.exe irrespectively.

    Regards
    GermanOne
     
  24. red death68

    red death68 Command Sergeant Major

    german you suggested adding all my script into a single hta any advice on doing so?

    also i need 1 more script converted if you would be so kind heres the batch version(yes its messy i make them work not look pretty)


    Code:
    @echo off
    
    :o1
    if not exist "option1.txt" goto :o2
    exit
    
    :o2
    if not exist "option2.txt" goto :o3
    exit
    
    :o3
    if not exist "option3.txt" goto :o4
    exit
    
    :o4
    if not exist "option4.txt" goto :o5
    exit
    
    :o5
    if not exist "option5.txt" goto :msg
    exit
    
    :msg
    del path.txt
    "finished.vbs"
    the code is basicly ment to see if the option files are still intact and if they have been deleted like they should be at the end it moves to the next option till all have been cleared then displays and end message using a msgbox in a vbs
     
  25. GermanOne

    GermanOne Guest

    Not really. I don't know all your single scripts and I don't know how they are interdependent...

    OK, here's the VBScript:
    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    For i = 1 To 5
      If objFSO.FileExists("option" & i & ".txt") Then WScript.Quit
    Next
    If objFSO.FileExists("path.txt") Then objFSO.DeleteFile "path.txt", True
    MsgBox "Your Message", vbInformation, "Your Title"
    
    Regards
    GermanOne
     
  26. red death68

    red death68 Command Sergeant Major

    ty man ill see what i can do about combining the code
    once i finally make the ui im doing a background image for it
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds