Announcement

Collapse
No announcement yet.

Command button selection to run a batch file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Command button selection to run a batch file

    I'm new to this site, but have been working all day to get something to work.

    I need to create a script that gives the user a choice of 6 option buttons, and depending on which one they select it launches a batch file that maps the network drives. We have 6 offices, and I want the user to be able to select the office and based on their selection, run the network mapping script for that office's servers.

    While I can create a VBScript to call the bat file, and that work successfully when I run that file, when I try to add the same script to an HTML form to be powered by a command button, I cannot get the script to work.

    I've tried various codes this afternoon trying to get this working, the latest is:

    <INPUT TYPE=button NAME="Office1" VALUE="Office1">
    <SCRIPT FOR="Office1" EVENT="onClick" LANGUAGE="vbscript">
    <!---
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run("c:\drivemapO1.bat"), 1, True
    msgbox "Drive Mappings Complete"
    -->
    </SCRIPT>

    If I rem out the the two lines that start with Set ObjShell and objShell and run the form, the message box appears. But I cannot seem to get the proper code to run in IE. But if I save the code to a vbs file, it runs fine.

  • #2
    Re: Command button selection to run a batch file

    Originally posted by cruzenbye View Post
    when I try to add the same script to an HTML form to be powered by a command button, I cannot get the script to work.
    You really do not want to run programs from within a web page. Think twice about the security problems it would cause.

    A solution would be HTA, that is, HTML Application. Those are IE specific solutions.

    Another a way would be to create a menu within the batch file and read user input with set /p. Yet another would be declaring an environment variable that specifies the computer location and using that data in order to call the correct mapping script.

    -vP

    Comment


    • #3
      Re: Command button selection to run a batch file

      Point well taken,

      I prefer the visual effects of using IE, so I will look into HTA. The GUI aspect is better at getting an end users attention than a batch file menu.

      Unfortately, I can't create a script based on the user's location, as there are many cases where a user resides in location1, but needs to work from location2, and needs to have their drives mapped to location2.

      I'm also hoping this can script (or a variation of) can be used for those individuals who work for multiple locations, so they can simply run the script, select the office and have their drives remapped.

      Comment


      • #4
        Re: Command button selection to run a batch file

        How about scripts in a site level GPO?
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: Command button selection to run a batch file

          Originally posted by Ossian View Post
          How about scripts in a site level GPO?
          Not sure as to how that would work.

          This particular issue only applies to some users who have certain software installed that requires specific drives mapped directly to drive letters (does not work off UNC naming). And then of those users who have the software - only a limted number will work across offices.

          So from a GPO standpoint, I'd have to 1. check if software exists, 2. check for drive mappings to the network shares. 3. If the drives don't exist, then prompt them to pick their office and run the batch file that maps the drives for that office.

          Comment


          • #6
            Re: Command button selection to run a batch file

            I might be missing something here but why not make the script a .vbs file instead of a .bat file?

            Comment


            • #7
              Re: Command button selection to run a batch file

              Originally posted by joeqwerty View Post
              I might be missing something here but why not make the script a .vbs file instead of a .bat file?
              I could make the login scripts a vbs file to map the drives - that isn't the problem.

              The problem is- I need the user to be able to choose from a *pretty graphical interface that is lowtech friendly* to pick which office they want to connect to, in order to then launch the proper vbs (or bat) script to map the drives to that office. (note - I think I have found a workaround ... but I'd love to make this a cleaner interface)

              I'd like this to be long term maintainable - therefore if IT retires a server, they can simply update the login script file on the server with the updated server name - and not worry about this updating little app that is loaded on the user's PC.

              Here is the background info:
              We have an application that requires static network drives mapped to specific letters. (ie. M: is mapped to \\*server*\data, L: is mapped to \\*server*\admin ) If a user tries to use the application and is not connected to the proper drives, then the application will not load correctly and actually writes incorrect info to the registry thus causing alot of extra work from IT to fix - and the files under *\Data they try to access are not loaded correctly.

              In theory - all users who use this application should have a special login script that automatically maps them to these drives - this script I am writing double checks that, because sometimes IT forgets to connect the users to the proper login script (and yes, I am part of IT )

              To complicate matters - we have a multi office setup. Each office has its own servers with the same shares on them. (server1\data, server2\data, etc) But we have some users who are physically located in office1, but work for office2 or office3. Therefore they need to be able to choose which office they want, so I cannot run a system check based on IP to automatically pick which script to run. I need the user to be able to choose.

              My little script will run at login on the local pc, check for the drive mappings to the correct location to make sure they are present - if not, popup a window with a pretty user interface for them to pick which office they want to map to, then the script will recheck the mappings again before confirming to the user that its ok to use the software. (and on failure or denial, tell them they should not use the software).

              My background is primarily in batch scripting - with minimal experience in vbs scripting. This upgrade is the first time we are trying to implement these system checks to help IT from having to fixed messed up installs because the user was not mapped properly. Hence, I need some assistance from folks who know what they are doing and are generous enough to spend a little time to help a newbie like me.

              Comment


              • #8
                Re: Command button selection to run a batch file

                Save this as menu.hta and see if you can modify its contents to suit your needs.

                Code:
                <HTML>
                <HEAD>
                <TITLE>Simple menu</TITLE>
                
                <HTA:APPLICATION 
                     ID="menu"
                     VERSION="1.0"
                     APPLICATIONNAME="Simple menu"
                     SCROLL="yes"
                     SINGLEINSTANCE="yes"
                     WINDOWSTATE="normal"
                >
                </HEAD>
                <body>
                <SCRIPT Language="VBScript">
                
                Option Explicit
                
                sub selectLocation
                    dim btn
                    dim ret
                
                    for each btn in selectedSystem
                        if btn.checked then
                
                            ret = msgbox ("Selection: " & btn.Value & " OK?", vbOKCancel )
                            
                            if vbOK = ret then
                                startInstall btn.value
                            end if
                        end if
                    next
                end sub
                
                sub startInstall(byval val)
                    dim objShell
                    set objShell = CreateObject("wscript.shell")
                    objShell.run("something.cmd " & val), 1, true
                    
                end sub
                
                </script>
                
                <input type="radio" name="selectedSystem" value="Helsinki" checked="checked"> HQ <br>
                <input type="radio" name="selectedSystem" value="Berlin"> R&D<br>
                <input type="radio" name="selectedSystem" value="Paris"> HR<br>
                <input type="button" name="OK" value="OK" onclick="selectLocation">
                
                </body>
                </html>
                Take a look at MS Scripting guy's archives too.

                -vP

                Comment

                Working...
                X