5

I have web based application which automatically loads on kiosk mode (full-screen) in chromium web browser on client's Computer wich is powered by Windows 7. I want to place a shutdown button on web page, so that user can directly shutdown the computer.

  • Is there any possibility to achieve this?
  • What are the best solutions for both Windows & Linux?

-P.S-

I've full control over client's computer. (installing other software or browser extensions). it is a touch screen POS unit.

Kevin
  • 153
  • 1
  • 3
  • 12

5 Answers5

11

As you have control over the target machine, this is completely feasible. One way to do it is by introducing a separate component to perform the shutdown.

  1. Create a console application (using C#, for example) that listens to stdin, that shuts down the machine when it receives the right input. Machine shutdown from C# is not entirely trivial, but Stackoverflow knows how it is done.

  2. Register this application with a proper manifest given the Google Chrome Native Messaging specification.

  3. Call this extension from your webpage (on shutdownButton.click(), for instance) using Message Passing.

The individual steps are a bit too broad to fully detail them in a single answer, but you can always open new questions on them if they give you any trouble.

Community
  • 1
  • 1
Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
3

Because of security reasons this is simply not possible without running something outside of your browser.

If however the page is served from a server and you want to shutdown this server, keep reading:

A solution which would be possible is to run a server in the background, for example node.js.

On your node.js server you could listen for a specific url you are calling, on the trigger of this event you could send a shutdown command to your host. This however opens some security issues, you need to block this call to node from the outside (or not if you want others to be able to shut it down). And your node.js server has to be running with root rights which is also risky.

Take a look at https://github.com/typicode/stop-server maybe you can find something in there that's usefull to you.

Dirk-Jan
  • 1,109
  • 10
  • 21
3

Your best bet as far as i can think would be to download a .bat that would shut down your computer and execute it, but aside from IE i'm not sure if it will work.

<script type="text/javascript" language="javascript">
    function RunFile() {
    WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
    }
</script>

something along these lines, running the .bat file you have previously downloaded instead of notepad. Note, this will only work with IE.

Elentriel
  • 1,237
  • 8
  • 21
  • 1
    this code is showing an error: `test0.html:12 Uncaught ReferenceError: ActiveXObject is not defined`. What is wrong with this? – Er. Harsh Rathore Jul 20 '19 at 21:44
  • Because like Elentriel said in his answer, ActiveXObject is a Microsoft extension that can only run on IE – xTrimy Feb 19 '20 at 11:41
1

You don't have directly access from WEB page to client's Computer, it's impossible. You only have access to the browser, but it is very limited.

You can only close window tab, using window.close(). Read more about it here - https://developer.mozilla.org/en-US/docs/Web/API/Window/close

Andrew Evt
  • 3,613
  • 1
  • 19
  • 35
  • 3
    window.close will only work if it has been triggered by a user action, like a click for example. You should mention that in your post. – Stranded Kid Nov 10 '15 at 11:14
-1

You can try the through the API call trigger the batch script for shutdown the device.

string startupPath = System.Environment.CurrentDirectory;
string path = System.IO.Path.GetFullPath(@"..\..\");
string BatchFilePath = startupPath + LogoffTriggerBatchFile;
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe", "/c " + BatchFilePath);
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
Process process = Process.Start(processStartInfo);
return new HttpResponseMessage(HttpStatusCode.OK);
Elikill58
  • 4,050
  • 24
  • 23
  • 45