Go Back  PPRuNe Forums > Misc. Forums > Computer/Internet Issues & Troubleshooting
Reload this Page >

Another for the "team that can"...

Wikiposts
Search

Notices
Computer/Internet Issues & Troubleshooting Anyone with questions about the terribly complex world of computers or the internet should try here. NOT FOR REPORTING ISSUES WITH PPRuNe FORUMS! Please use the subforum "PPRuNe Problems or Queries."

Another for the "team that can"...

Thread Tools
 
Search this Thread
 
Old 24th February 2013 | 18:24
  #1 (permalink)  
Thread Starter

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
Another for the "team that can"...

Several longstanding problems on the Keefpooter have been solved by the wise heads in here. I'm getting down to the little ones now...

I'm an owl, but M likes to turn in early, so the PC speakers go off at 10pm.
In the olden days, that was done with a timeswitch in the power connection to the speakers, and worked fine.

More recently, software fixes have been used. The first was a little app that kills the speakers according to a schedule. Then I found a clever little utility that will switch between speakers and headphones - it rejoices under the name of ToggleAudio. However, it needs an input when it starts, so using the task scheduler as-is won't do. I've written a little batch file that works perfectly.

BUT ... if I run that batch file under "Task Scheduler" it doesn't work. The .exe starts, and that's as far as it gets. If I look at Task Manager, I can see it in there (and stop it) but it doesn't do its job. Running the batch file from the desktop, it works fine, and closes OK so it's not sitting there in task manager.

What am I missing? Here's the batch file:

h:
cd H:\ToggleAudio\
toggle-audio-7.exe
choice /T 1 /C ync /CS /D y
taskkill /F /IM toggle-audio-7.exe
c:
exit

The "choice" line provides the .exe with an input to keep it happy.

The taskkill line is in there as an attempt to close it down when it's running from Task Scheduler (but doesn't work).

Last edited by Keef; 24th February 2013 at 18:24.
Keef is offline  
Reply
Old 24th February 2013 | 19:48
  #2 (permalink)  
15 Anniversary
 
Joined: Jan 2008
Posts: 1,133
Likes: 0
From: Bracknell, Berks, UK
Are you running the task in the logged-in user's security profile?
Are you setting the task to operate whether the user is logged in or not?
Mike-Bracknell is offline  
Reply
Old 24th February 2013 | 20:05
  #3 (permalink)  
Thread Starter

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
Yes, running in my user-account, which is always logged on. The PC is in my study, and nobody else goes near it.

Yes, run whether logged on or not.

Also "Run with highest privileges".
Keef is offline  
Reply
Old 24th February 2013 | 22:21
  #4 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
Keef,

Its been a while since I've done batch scripting, ever since the advent of PowerShell I've found that to be much better in the rare events I find myself writing scripts on Windows.

I'm taking a stab in the dark here..... but how about replacing

Code:
h:
 cd H:\ToggleAudio\

 toggle-audio-7.exe
with

Code:
start "ToggleAudio" /d "H:\ToggleAudio\" /wait toggle-audio-7.exe
(you might possibly need to spec the full path for the exe rather than the prog name, I can't remember).

A quick Googoo also suggests there may be alternate means to achieve your goal if you can't get the exe method working.... Toggle set default audio device in Windows 7. - Scripts - AutoHotkey Community and Windows 7 Tip: How to change the default audio device with a hotkey

Last edited by mixture; 24th February 2013 at 22:28.
mixture is offline  
Reply
Old 24th February 2013 | 22:38
  #5 (permalink)  
 
Joined: Jan 2012
Posts: 2,173
Likes: 0
From: .
Its also worth remembering that running a batch file from a network drive, or sometimes even from a removeable drive (which I presume H: is) hits a brick wall in Windows Vista / 7.......the OS just refuses to run it, even it run with admin privliges.
In the past I've got round it - sometimes - by creating a shortcut pointing to the bat file which points to the exe file........messy, but sometimes it will work.
Or you could try moving the toggleaudio exe file to a folder on the C: drive. Even then if you still have problems, run a shortcut to the bat file and run that. Don't directly run the bat file. Sounds crazy, but - in the past - its worked
Milo Minderbinder is offline  
Reply
Old 25th February 2013 | 21:06
  #6 (permalink)  
Thread Starter

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
Thanks for those.

H is the backup drive, a second SATA drive inside the case and on the motherboard. I moved the folder to the C drive. That made no difference.

Mixture's
start "ToggleAudio" /d "CToggleAudio\" /wait toggle-audio-7.exe
worked perfectly in "batch" mode, just like my batchfile.
It also locked up in exactly the same place as the batchfile when run by task scheduler.

I put in some echo > output.txt lines to track where the batchfile got to. It stopped at the line that starts the .exe file.

A separate shortcut to run the batch file did the same thing.

The .exe on its own in task scheduler was subtly different - the programme started and the audio control panel appeared on the screen, and stopped there. It didn't toggle over, although I could operate it as if I had opened it manually. The task scheduler showed "running" and task manager showed it running.

The problem seems to be that running the .exe from task scheduler (whether via a batch file or direct) it doesn't complete.

I have the batch file on a link on the desktop, and that works flawlessly every time.

Curious! I'm not that bothered about the action (the link on the desktop is enough), but I'm puzzled about the way it doesn't work.
Keef is offline  
Reply
Old 25th February 2013 | 22:02
  #7 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
Hi Keef,

How does toggle-audio-7.exe actually behave ? Does it launch an interface of some description ?
mixture is offline  
Reply
Old 25th February 2013 | 22:21
  #8 (permalink)  
Thread Starter

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
I simplified the source code to this, which when compiled works OK from a CMD line or from clicking on the .exe - but doesn't work from Task Scheduler.

Code:
; This is the "on" version


	$windowName = "Sound"
	$altPlusKey = "s"
	$numDevices = 2
	

	; Set device position to switch to 2 = Speaker
	$ItemNumber = 2

	; Run the sound control applet
 Run("control mmsys.cpl") 
	
	; Wait a second for it to be active before sending keystrokes
 Sleep (1000)

	; Put the focus on the list
 Send("{TAB}{TAB}{TAB}{TAB}")

	; Tab down to the device position.
 For $i = 1 to $ItemNumber Step 1
 Send("{DOWN}")
 Next

	; Press shortkey to set the selected device as the default
 Send("!"&$altPlusKey) 

	; Close the window.
 WinClose($windowName)
I tried running that via a batch file - same result!

Last edited by Keef; 25th February 2013 at 22:23.
Keef is offline  
Reply
Old 1st March 2013 | 23:52
  #9 (permalink)  
Thread Starter

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
FIXED IT!

The problem seems to be that Task Scheduler can't run anything that uses Control Panel items (don't ask me why!). It starts the CPL item OK, but then the CPL takes over and subsequent commands from TS aren't passed to it. If the CPL appears at all on the screen, it will be flashing and asking for attention.

Batch files called by Task Scheduler can't bypass that, because TS keeps running until the batch file exits.

Microsoft offer a free app called "Mayhem" which will do things Task Scheduler won't, such as run a program if the stock market does something. It has a raft of other toggles. One such is "if a folder contents change". Mayhem doesn't care about the Control Panel niceties that bother Task Scheduler.

So I have two little apps, one to switch from speaker to headphones, and one to go the other way (the script above).

Task scheduler runs an "audio-on" or an "audio-off" batch file, which toggles the name of a file in subdirectories called "ON" and "OFF", and TS then exits.

Mayhem sees the subdirectory contents change, and runs the appropriate script.

It's messy, but it works. I've not found a way to do it without Mayhem.

Last edited by Keef; 1st March 2013 at 23:53.
Keef is offline  
Reply

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service

Copyright © 2026 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.