How to check if a service is running via batch file and start it, if it is not running?

To check a service’s state, use sc query <SERVICE_NAME>. For if blocks in batch files, check the documentation. The following code will check the status of the service MyServiceName and start it if it is not running (the if block will be executed if the service is not running): for /F “tokens=3 delims=: ” %%H … Read more

How do I set a Windows scheduled task to run in the background? [closed]

As noted by Mattias Nordqvist in the comments below, you can also select the radio button option “Run whether user is logged on or not”. When saving the task, you will be prompted once for the user password. bambams noted that this wouldn’t grant System permissions to the process, and also seems to hide the … Read more

Decode PowerShell output possibly containing non-ASCII Unicode characters into a Python string

The output character encoding may depend on specific commands e.g.: #!/usr/bin/env python3 import subprocess import sys encoding = ‘utf-32’ cmd = r”’$env:PYTHONIOENCODING = “%s”; py -3 -c “print(‘\u270c’)””’ % encoding data = subprocess.check_output([“powershell”, “-C”, cmd]) print(sys.stdout.encoding) print(data) print(ascii(data.decode(encoding))) Output cp437 b”\xff\xfe\x00\x00\x0c’\x00\x00\r\x00\x00\x00\n\x00\x00\x00″ ‘\u270c\r\n’ ✌ (U+270C) character is received successfully. The character encoding of the child script … Read more

How to automatically update an application installed with Inno Setup

Inno Setup does not have any built-in mechanism for implementing automatic updates. You need to implement that yourself: Make your application check for new versions (against your application webpage?). E.g. on startup (on a background thread?) If the application detects a new version, make it download an installer to a temporary location. Make the application … Read more

How do I ignore the Perl shebang on Windows with Apache 2?

I use #!/usr/bin/perl in my scripts and configure Apache on Windows to ignore the shebang line. Add ScriptInterpreterSource Registry-Strict to your httpd.conf and set up the Windows Registry key as explained in the Apache docs. Here is what I get when I export the key: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.pl\Shell\ExecCGI\Command] @=”c:\\opt\\perl\\bin\\perl.exe” I have been … Read more

Running another program in Windows bat file and not create child process

Synchronous. The second notepad won’t launch until you close the first. notepad.exe c:\temp\a.txt notepad.exe c:\temp\b.txt Asynchronous: The second notepad will launch even if you haven’t closed the first. start notepad.exe c:\temp\a.txt start notepad.exe c:\temp\b.txt More info about the start command: EDIT: The following comment was made elsewhere by @zhongshu, the original poster. I’m only … Read more