0

I would like to create a .bat file that has the following qualities:

  1. detect power cable unplug

  2. detect power cable re-plug/reinserted

  3. start when windows starts

  4. detect shutdown and/or power button push (turn off)

  5. play sound on repeat until the correct password is provided

  6. If [X]/exit is pressed while waiting for correct password it will reopen, continue sound and ask for password.

  7. If a user whant to exit the bat it will ask for pass and play sound on repeat.

Basically I want to create a very simple anti theft script

When the power cable in un-plugged/plugged the power usage/option icon on the task bar changes from eather power=100%/power=7-100%/power=(charging)7-99%

The unplug/re-plug is an event windows recognizes. I think This is the hardest part just tried Google and it is mostly going on about USBs and criptocurrencies.

UPDATE: this has something to do with

C:\Windows\system32\svchost.exe -k DcomLaunch

If any one has info on any of the 7 things i want to achieve feel free to reply.... in the mean tim I have found a few bat websites and I will be updating this question as-and-when I discover I will put examples for each parts under here...

------------------------------------------- Anti theft bat Tutorial:

  1. Create a new txt file then right click and rename > [secure_name].[bat]
unclemeat
  • 5,029
  • 5
  • 28
  • 52
BENZ.404
  • 401
  • 1
  • 5
  • 20
  • Almost certainly something that a batch file by itself wont be able to achieve, best you could do with a batch file is to call external programs that can help achieve this. – ServerMonkey Mar 25 '14 at 01:15
  • You won't be able to stop the user from killing the batch file's process. Try running a batch file consisting of just `pause`, for example. Now click the [X] on its window. Gone. – Blorgbeard Mar 25 '14 at 01:18
  • I can make another bat to monitor the other then restart if exit is pressesd – BENZ.404 Mar 25 '14 at 01:24
  • @BENZ.404 Curious, have you managed to get anything working for this problem? – unclemeat Mar 30 '14 at 08:08

1 Answers1

0

To find out whether or not the power adapter is plugged in you could try using wmic. You can use wmic computersystem list to list all available options - I think PowerState might be what you want wmic computersystem get PowerState. Try checking these values while the cable is plugged in, and while it is not. Obviously looking for whatever differs.

The only way I can think to stop the system from shutting down is by constantly running shutdown /a. I'm not sure that you can detect if the system is shutting down, but this will constantly abort any shutdowns in progress. If the system is not shutting down when you run this command, it tells you just that. This will abort a shutdown if the button is pressed, but not if the button is held, that cannot be stopped (or detected using batch).

As for playing a sound, you can use alt + 7 which will output a beep. To get this in your batch file, at the command prompt type echo the press ctrl + 7 followed by >>batchfile.bat. Obviously replacing batchfile.bat with the name of your batch file. That will append the 'beep character' to the end of your batch file. From there you can copy and paste it to where you want. It will look like this from the command prompt:

echo •>>batchfile.bat

The • character will look different in notepad (presumably in most text editors). It might be a good idea to also make sure the volume is set to 100%. For this you can download and use nircmd - the command nircmd.exe setsysvolume 65535 will set the volume to max.

To stop the user from closing the batch file readily, you can use a simple vbscript to call the batch script with no window associated with it, so it will run in the background. See: https://serverfault.com/questions/9038/run-a-bat-file-in-a-scheduled-task-without-a-window

For getting the password, take a look at my answer to a question here - Can I mask an input text in a bat file. You could spawn another window to take the password.

These are my ideas of how you might achieve this idea of yours - I'll leave the other technicalities of implementation up to you. Feel free to ask more questions as you run into any problems writing this script.

Community
  • 1
  • 1
unclemeat
  • 5,029
  • 5
  • 28
  • 52