Making a repeating alarm in a batch file - batch-file

Ok, so I have 0 experience with this, yet I managed to put this together by reading from different forums:
:loop
"sndrec32 /play /close
"C:\Users\...\sound.mp3"
timeout /t x
goto loop
It plays a sound every x seconds. Is there a way to make it play the sound without the media player popping-out on the screen, and when it's done playing the sound - to close itself (the player)? What about the command promt not popping-out on the screen? I basically want to have as few pop-ups on the screen as possible when launching the file.
Thanks!
EDIT: Solved, see my reply

With MediaPlayer ActiveX object . This could be problem for a people without installed MediaPlayer (e.g. Windows XP required genuine authentication in order to install it) and it can acts differently on different windows versions (e.g. on some windows version auto closing does not work as expected). Here's my implementation (does not create temporary files).Example:
call mediaRunner.bat "C:\Windows\Media\Ring05.wav"
On every windows machine there are installed SP ActiveX objects which are capable to run .wav files (no mp3 and so on). Here's one script.Expample:
call spPlayer.bat "C:\Windows\Media\Ring05.wav"
and we have also HTA/InternetExplorer applications and their bgsound tag.Which also allows you to control the volume of the played song:
call htaplayer.bat "C:\Windows\Media\Ring05.wav" -1000

Related

How can I play mp3 files in Windows 11 using cmd?

I made an app recently that I'm proud of. It's an alarm that plays music at a designated time. I use the Windows Command Prompt to play the .mp3 file. I'm using C, so I've been trying to use the system() method. However, I've realized that this won't work on computers that have Windows 11, as they got rid of Windows Media Player being installed with Win11. I also have Win11, but it worked on my computer because I installed it.
Win11's media player is called "Media Player," and I can't find a way to play mp3 files through the command line with it. I've tried "fmedia," "wmplayer," "start," and others but none of them work.
So how can I play an mp3 file on Windows 11 using the Command Prompt without installing extra software?

Flash/AS3 - Saving a File without Prompt

I need to save a file in Flash without a prompt; what my program does is it gets all the frames from the stage and then it saves them as png files, along with a text file that has the name of the object, and some other properties about it. The code that I have does save it without any problems, but I need it to not prompt me, because I have lots of frames to do this with.
Is there a way to do this with Flash the program or actionscript?
No, unless you're using Adobe AIR. The reason for this is Flash Player and its programs are generally run through a browser over the Internet, and if people could use Flash Player to just start saving files on other people's computers, there would be some very serious security issues. AIR, on the other hand, is generally run on a desktop, laptop, or mobile device, and its programs are run directly off the same, having been pre-installed. So whereas a website can suddenly just start running a script with Flash Player without asking you first, AIR requires you to have already installed the script/program on your computer, meaning that it should be there intentionally. So security restrictions are lighter, enabling the use of the File class in your programs.
The only way to save a local file with the Flash Player (in the browser) is with FileReference and it will always prompt the user.
However, using AIR (desktop or mobile app) you can save to the local file system without user input, using File and FileStream. You can create an AIR app using Flash Pro, usually without any code changes other than the AIR APIs you need (flash.filesystem in this case).
Another idea, if you must use Flash Player and not AIR, is to first zip all the PNGs and only save to file after they are all packaged. This way there's only one file and prompt to save.

Batch files/Windows 7 - Open UAC prompt minimized on purpose

There are many users struggling with UAC prompts opening in background instead of foreground. Well, I want to do exactly the opposite, ie having the UAC prompt flash on the taskbar and waiting for my attention instead of dimming my whole screen and messing my workflow.
Here's my setup: I'm working on a Win7 x64 machine, and I placed this link in my Startup folder:
C:\CLUs\chp.exe "apps.bat"
chp.exe is an utility that loads batch files without showing the command prompt.
apps.bat calls several unelevated programs (easier to manage apps in this way rather than putting a bunch of links in Startup). The last line of such bat is
elevate chp "elevapps.bat"
elevate.exe is an utility that, as the name says, elevates whatever is called with issuing an UAC prompt. And, clearly, elevapps.bat contains another bunch of programs that require admin rights to start properly.
Now, for a number of reasons I'd like the UAC prompt to start minimized/in background. Ie, once I've logged in Windows, all I want to see is the taskbar containing the flashing icon of the UAC, but no dimmed screen.
Is this possible with batch files? All I know is that UAC "smartly" detects whether it is stealing focus or not and (doesn't) show up accordingly. And clearly during the startup there's nothing to steal focus from, so looks like I'm having no luck. However it also seems that badly coded software (namely not assigning HWNDs somewhere, see here and here) precisely produces this effect. Is there a way to reproduce this "bug" (I'd call it a feature, in my case) with some code in a batch file? Also using a third party utility would be fine, however I'm not a programmer.
I solved the problem by using winapiexec.exe, an utility that allows (as per site) to run WinAPI functions through command line parameters.
winapiexec shell32.dll#ShellExecuteW NULL "runas" "chp" "elevapps.bat" NULL 7

Start Play Application and Close Window

I have a play application on a Windows 7 machine which I want to start via double click on a batch file.
This batch file starts a service. Calls the play application to run in production mode, waits for 5 seconds and open a browser with a specified url.
Therefore I used the following script:
call net start service1
CALL "D:\play-1.2.5\play.bat" start --%%%%prod -Dprecompiled=true
TIMEOUT /T 4
call "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" localhost:9000
exit
Now when I start the batch file the window opens and all commands are executed. Sadly Play is still writing his output to cmd and the window is not disappearing. If I close the window manually play is stop executing.
If I run play with "play start" from cmd, play is starting in the background and everything is fine. Play still runs even if I close the window.
I want to have exactly this behaviour when I start the application with my batch file.
Thanks
If you were using a linux-like environment, I' d recommend you to use 'nohup' command and a '&' sign in the end. However, as far as I know there is no direct equivalent of beautiful 'nohup' command on Windows, unfortunately. So, what I can think of is, you can create a tiny win api application that utilizes CreateProcess command and give it the required parameter to hide command line window as soon as the process is created. There are also other process creation functions such as WinExec that you can use to hide command line.
I don't know what Play is so I can only take a guess :) but try using the batch without the call's as I don't think they are necessary, and you never know, might fix the issue.
1) You see Play's output because ot redirect only system.out but write system.err to the same console.
2) I also have this problem and looking for a solution. As a workaround you could try to use some Java Wrapper and install your Play! application as a Windows Service.
3) Play! app could be started via Ant task. I haven't tried this yet.

Avoiding all system messages and messages from other software

Here is the situation. The company I work for builds this piece of software in c that can make a Windows computer act a bit like a TV. Essentially, our piece of software is meant to be played full screen and content is displayed from the internet without the user having to ever touch the computer again.
The problem is that once in a while, the system brings up pop-ups like "Your Windows system is ready for an upgrade." or "Please renew your Norton subscription" etc. which the user has to periodically and manually remove.
Is there a way to display content full screen without being bothered by those warnings?
Yah, whether or not the development community agrees, Microsoft has several standards for when and why it might be acceptable to have exclusive use of the monitor.
The most official strategy is to use DirectX in exclusive mode. This is what games do, what windows media player does in full screen video with hardware acceleration enabled, etc... If your application is multimedia intensive (as suggested by TV like functionality), you should probably be using DirectX too. Besides giving you the exclusive display access it will also increase your applications performance while lowering the CPU load (as it will overload graphics work to the video card when possible).
If DirectX is not an option, there are a great number of hacks available that seem to all behave differently between various generations of windows operating systems. So you might have to be prepared to implement several techniques to cover each OS you plan to support.
One technique is to set your application as the currently running screensaver. A screensaver if really just an EXE renamed to SCR with certain command line switches it should support. But you can write your own application to be such a screensaver and a little launcher stub that sets it as the screensaver and launches it. Upon exit the application should return the original screensaver settings (perhaps the launcher waits for the process to exit so that it returns the settings in both graceful exits and any unplanned process terminations ie: app crash). I'm not sure if this behavior is consistent across platforms though, you'll have to test it.
Preventing other applications from creating window handles is truly a hack in my opinion and pretty bad one that I wouldn't appreciate as a customer of such software.
A constant BringWindowToTop() call to keep you in front is better (it doesn't break other software) but still a little hack-ish.
Catch window creation messages with a global hook. This way you can close or hide unwanted windows before they become visible.
EDIT: If you definitely want to avoid hooks, then you can call a function periodically, which puts your window to the top of the z-stack.
You could disable system updates http://support.microsoft.com/kb/901037 and remove the norton malware.
You could also connect a second screen so that the bubbles appear in the the first monitor.
Or you rewrite it for linux or windows ce.
One final option is to install software that reconfigures your os into a kiosk http://shop.inteset.com/Products/9-securelockdown.aspx
If you don't need keyboard or mouse input, how about running your application as a screensaver?
A lot of thoses messages are trigged/managed by Windows Explorer.
Just replace it with your dummy c#/winform.
By changing the registry value
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"Shell"="Explorer.exe"
You can specify virtually any exe as an alternative to explorer.exe
That's the way all windows based (embedded) system (ATM & co) do.
There's still few adjustment (disable services you dont need / dr watson & others), and of course, you'll want to keep a "restart explorer.exe" backdoor.
But that's a good start

Resources