BroKeR
BroKeR

Reputation: 1

Starting a vbs script from a HTML file

I've been wrapping my head around this problem for a couple of days searching for all possible solutions on the forums and online but can't seem to get it working.

I'm calling a script by a link on a "button" to start a script on a server (in HTML):

<a href="#" onClick="RunScript();">

The script code is:

<script type="text/javascript" language="javascript">
    function RunScript() {
    var objShell = new ActiveXObject("WScript.Shell");
    objShell.Run("%comspec% /k my_projects_EN.vbs" "), 1, false;
    }
</script>

So why am I using a vbs? What I'm trying to do is create custom pages for each employee. So the vbs is actually checking the computer name and an if clause directs the employee to a custom page. With my basic knowledge of programming and a lot of hours of searching I did not find a better solution for this yet. So I'm trying to make this one to work.

And it does but only if I'm running the script locally (desktop). But as the webpage will be used in an intranet location this script will be on a server. And this is where it became a bit hairy as I can't seem to find the right combination of commands to do so. I already tried pushd for creating a mounted volume or currentDir for setting up the location of script but nothing seems to work completely.

I assume that I'm missing a subroutine for the function as adding anything there just stops the script - but how to go at it is beyond me.

All help is appreciated even if it means I have to bury myself into another program language (not preferred of course).

I am certain that there is a way to solve this other than sending a script to each employee to put on their desktop (each time a new employee comes to work).

Thanks

Edit: I see an additional clarification is in order:

We're creating an intranet webpage as a help for more efficient work for our employees. We're on the same level as the rest so not IT or admin rights guys so we're on our own. The point is to have a personal page for each employee which can be accessed via the same interface. So a link has to send each person to another page that is why I've created the vbs code which helps with that. Checking several other options this seemed to be the simplest and best one - and it works at least partially. I don't see any security risks as all will be done on each client computer - the files themselves will be located on the server. The script itself does not represent any risk at least not that I would see it - but of course I'm not a specialist.

So in short this is what we're trying to do:

Main page -> link to My_projects button -> start script (located on the same server as the main page) -> determine the client computer name -> redirect to the right webpage.

Sorry for a lack of details, I see that it's sometimes hard to explain exactly what you want if you're not a pro in these things.

Thanks again.

Upvotes: 0

Views: 599

Answers (2)

BroKeR
BroKeR

Reputation: 1

thanks for the effort

Everything is actually located on the server so the client computer only runs the page or interface which is in \Server\folder\folder for example. In your browser you open the start page which contains a button with a link to this script (located on the same server).

When the script executes it searches for the computer name and send the user to his personal page:

Set wshShell = CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

On Error Resume Next

'#01 name_surname If strComputerName = "XXXXXXXX" Then

CreateObject("WScript.Shell").Run """name_surname.html"""

and so on.

And this is all there is. As mentioned before we don't have admin rights to change anything on the client computer. So nothing is being done on the client side other that executing a script located on the server.

Upvotes: 0

MichalVales
MichalVales

Reputation: 445

If those computers are physically located at your workplace and you have control over the system, it would be better to tweak DNS redirections on those computers. Otherwise, more general and OS independent solution, would be session, cookie, or token on employee's computer. Still, some kind of authentication other than having one piece of machine, could be more versatile and secure (unless your PCs are 1000 feet underground :-) ).

Edit: What kind of info/data are sent to the server script? Server script runs on server and everything related to "this computer" (e.g. name) is actually referring to the server itself. Thus the script needs some data from the client to recognise his computer.

Upvotes: 0

Related Questions