Hi!
I've been lurking NBR forums for some time and you guys have "silently" helped me with choosing laptop and laptop bag!
Now I've run into a problem, or a snag really.
I have a HP dv2700 with Vista Ultimate x64.
It comes with Wireless and Bluetooth built in.
It has a switch where I can turn off both WiFi and BT.
If the switch is on I can use "HP wireless asistant" to turn on/off either WiFi, BT or both.
Either by using the graphical interface it has OR it's command line:
Wireless <Device> <on/off>.
Here comes my snag. I have managed to make TWO separate batch files that turns Bluetooth ON and the other turns it OFF, but what I'd like is ONE batch file that turns it ON if it's OFF and OFF if it's ON.
I found something called SET and SETX. Which creates variables in windows. But none help me as SET requires the command line to be running or it will delete the variable and SETX requires the command line to be running or it will REVERT the variable to it's "original" value until reboot.
I've googled and searched countless places on how to perhaps "refresh" the system variables so that setx wouldn't require reboot. I've also looked for some way to keep a command window in the background where I can send setx commands to but to no avail.
Sorry for the wall of text, but in summation:
I need one batchfile to turn bluetooth on or off depending on if it's on or off.
This is what I have tried which kinda worked at some point:
Thanks in advance!Code:@ECHO OFF cd "C:\Program Files (x86)\Hewlett-Packard\HP Wireless Assistant\" goto %BT% :av Wireless Bluetooth on setx BT pa goto end :pa Wireless Bluetooth off setx BT av goto end :end
-
Tar väl detta på engelska
While i can't really help you with SET and SETX (i have far too little experience with Windows command line), however the simplest way to just save a setting would probably to use a standard text file.
However, the best way to do what you are trying to do is probably to check for a running process. When Bluetooth is turned on there is probably a background process launched; if you can find the name of this process, you can determine if Bluetooth is on by checking if the process is running.
Now i have Windows XP, so this might be different on Vista, however, both of these commands are included by default on Windows XP Pro.
Code:tasklist.exe | find "*name-of-bt-process*"
So if the code above returns anything like "bluetoothProcess.exe 2660 Console 0 130*060 kB",
then your Bluetooth is ON, if Bluetooth is OFF you will just get an empty string.
If you still want to create a file you can doCode:echo "Hello" > file.txt
Code:for /f %a in (file.txt) do (echo %a)
(just realized an even simpler way would be to see if a certain file exists, eg. when you turn Bluetooth on, you create a file named "Bt.on", then in the script you check to see if that file exists, if it doesnt, bluetooth is obviously off) -
Here's a simple script that increases a counter, remembering its value between executions:
Code:@echo off set /a i = %count% + 1 setx count %i% set count="%i%" echo count = %count% pause
"set" sets it for the current command shell, while "setx" sets it for future shells. (And "set /a" lets you do math.) Notice the different syntax used for set vs. setx.
Now, if that works for you... I think you can probably adapt this to do what you need. However, I haven't tested whether it'll persist across a reboot... I think it probably will, so you may need another script to reset the variable to the right value at startup. -
Allright! Thank you for your advice, I'll fiddle with it a bit and get back with my results.
-
Code here:
Code:@ECHO OFF cd "C:\Program Files (x86)\Hewlett-Packard\HP Wireless Assistant" IF EXIST bt.txt ( del bt.txt Wireless Bluetooth off ) ELSE ( echo ON > bt.txt Wireless Bluetooth on )
Batch file for bluetooth
Discussion in 'Windows OS and Software' started by Pbottie, Aug 15, 2008.