I've written a software that customers will install on Windows Server, and I wrote a HTML page for installation guide. How do I create a link on HTML page that will invoke my .bat script as an administrator. The .bat script will handle installation for customers. HTML page will be run as a file, that is without any server (including local host). The .bat script, html page, and binary will be in the same folder. The folder could be anywhere on the Windows server (I don't know where customers will place the folder).
One way of doing this would be to use a combination of AJAX and a script to accomplish this.
I'm going to assume the use of jQuery and PHP (just because they're so common) for this example.
jQuery just makes it shorter and this functionality will be available in most/all languages.
Let's say you have a page like this:
<html>
<body>
<a id="foo" href="#">Install</a>
<script src="install.js"></script>
</body>
</html>
And your javascript looks like this:
$("#foo").on("click", function(){
$.post('install.php');
});
In your install.php file, you could have this:
<?php
exec("mybatch.bat");
or
<?php
exec("cmd.exe /c test.bat");
However
Please note that what you are wanting to do has security problems.
Only do this if you are sure the environment is a secure one.
Running as administrator
This is a very difficult thing to do without cooperation from the client computer.
You more or less have to be running PHP or whatever language is installed locally as administrator.
Also, if running a batch file from a POST request is a bad idea, running a batch file as administrator is even worse. Avoid this.
In internet explorer:
file://mydirectory/myfolder/mybatchfile.bat
Most browsers don't allow this functionality because it poses a huge security risk for a link on a web page to be able to run local files. Most of them have extensions that disable that security feature. I haven't tested any of them to see if they work, however.
Even when this happens, however, the .bat run will happen like a download. The browser will "download" the .bat file, then give the user the opportunity to save it or run it. Unless your batch file is doing the administration elevation within the file itself, the user will have to manually run it as administrator.
Please keep in mind that these safeguards exist for a reason, and going around them is not a good idea. At the end of the day, however, there is no way to make the browser execute that code on its own. (Thankfully so!) There are better ways of accomplishing these kinds of tasks.
If you wanted to provide more details on what you are trying to accomplish, i'm sure we could come up with a more secure of doing what you want to do.
Related
So, I'm pretty new to Django, python, and javascript.
I have a partially functional Django webserver that, while developing it, I host locally on my machine.
I've made a button with HTML which I've figured out can be tied to a javascript script. The next step for me was to make this button "execute" a python script that's sitting on my machine, particularly on the /desktop directory. I can of course move the script though, but the important part is that I want that python script (let's call it django_test_script.py) to open its own window on my machine. It's just a file that says "hi" in stdout, then closes after 5 seconds, but due to the plan for this whole project, I want that to happen. I want to have my website open on my machine, click that button, then have the script's console pop up on my desktop and run/finish.
The eventual goal is to control an LED strip that's plugged into my raspberry pi. I want colored buttons on the website that, when clicked, run appropriate python scripts that turn the lights to that color. It wouldn't take me long to write up the python scripts themselves that would change colors, but I need to bridge the gap between "button causes a py script to run" and the python script actually running.
I see a ton of questions similar to this, but they all seem to involve running the python scripts WITHIN the webserver, like internal files that do everything and then return something to the server via an HttpResponse.
I don't need an HttpResponse. Literally all I want to do for right now is figure out how to make a script that's stored on the machine run.
I've done some reading on AJAX and I'm guessing that's involved, however everything I've tried has failed with AJAX in terms of actually getting the server to RUN a script. I've been scouring the internet for over an hour now and have found basically nothing useful (as far as I can tell) so I figured I may as well ask for help. Can someone please point me in the right direction in terms of what I'll need to do?
I'm afraid that's not possible. The browser doesn't allow to execute local scripts since everything is (for security reasons) in a sandbox.
If you want to execute something you could do one of the following:
Use a http server which executes the script and call it via AJAX
You build it into an exectron / nodejs app which opens more possibilities to access the system. See this example
But from your requirement I assume the website will be opened on another device to remote control the Pi led? If you you'll need to use some sort of http server as otherwise you can't run the script on the pi itself.
someone knows how to open a program that is installed on the desktop from a web page, something like the onedrive option where from the web you can tell them to open a document and open word with that document or like when you open a torrent link ?
You basically have to download a file that is recognized by the program you wish to start. That program has to be pre-installed on the machine. The file should include instructions the program understand, and can execute.
In any case, this is quite fragile, and depends on many variables you have little control over, including the user, who might decline the download, or just save the file without opening it. So you should try a different approach to achieve what you want, than running a program on a user's computer.
There is probably a better title for I'd like to accomplish, but the details should be helpful.
I've recently learned that specifying a script's src path as //some.domain.com rather than http://some.domain.com or https://some.domain.com will cause the browser to request the script using whichever protocol was used to load the page. This works great when the page is loaded from a site, but often I debug on my local system, so the protocol is file, and of course errors occur whenever resources or scripts aren't found.
Other than changing src paths, is there a better way to debug locally? I imagine there is code solution that detects when the page is running locally versus loaded from a domain, but I haven't found examples yet.
Install a product such as wampserver, then you'll have a localhost webserver you can test everything on. This is how I do it, works like a charm.
There are similar products available for ASP or other non-PHP server-side technologies (you didn't specify), if you are just doing HTML + JS then any old server would do.
Greetings, all! I have hit a bit of a brick wall and was hoping that I could get some help. I'm trying to write a site that people can access with IE6+ that will allow them to click a link that will open a piece of software on their desktop (the run/save dialog is OK) that also contains variables. Thoughts, ideas? It should look something like this:
<html>
<head>App Launcher</head>
<body>
Primary ABCD
</body>
</html>
This is not possible, you will need to use third party application like Flash,Java applets but directly from html this is not allowed in the browser.
but you can create an exe file and tell the user to download it and run it to open the designated application and you can send the parameters that you want through that exe.
You can do this using an ActiveX Control. Once the user grant permission to execute the ActiveX, the .exe file can be executed on the client machine.
Edit:
Here is an example about how to do it:
<SCRIPT Language="JScript">
function runcmd() {
File="http://www.yoursite.com/your_executable.exe";
WSH=new ActiveXObject("WScript.Shell");
WSH.run(File);
}
</SCRIPT>
Run
But note that this will only work under IE. To produce the same effect on Mozilla browsers, Safari and others, just this will work:
Run
Both solutions will prompt the user to choose to run or not the application from the link. You can't force programs to run on the user's machine without his permission because its a security issue.
Hope this works for you =)
this will lead to huge security issues and therefore isn't possible trough plain HTML. You will need a java applet or something similar that where the user gets the choice to accept.
I noticed that when I open HTML file locally by double clicking on it, it will not "run" the same as if I had it on a web server and opened it by HTTP GET request.
I need to have a local HTML file a user can open by double clicking on it. This HTML file has several JQuery load calls such as this:
$("#content").load("http://somepage.com/index.html");
I want to update several divs with content from remote sites.
This works fine If I have this file on a web server but not if I double click it under windows explorer... How can I "make" the file "run" as it would on a web server?
I think you pretty much cannot. This has to do with domain-access restrictions, which are there to avoid cross site scripting and the likes.
The files on your hard drive are especially limited - think what the life could be if they were allowed to treat your whole hard-drive as a single domain.
If you want things to work properly you need to be running a server. XAMPP is a pretty good bet as it's easy to install and set up.
Any non-AJAX javascript will work fine as is though, as long as the paths to include any css or js are relative.
You can't do this locally. You have to have it hosted somewhere for this to work. It's done this way for the sake of security.
What are you trying to do that you "need" to have this?