Most viewed recipes tagged "windows"http://code.activestate.com/recipes/tags/windows/views/2017-03-31T14:30:30-07:00ActiveState Code RecipesWin Services helper (Python)
2014-09-06T10:35:54-07:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/551780-win-services-helper/
<p style="color: grey">
Python
recipe 551780
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/services/">services</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 4.
</p>
<p>A simple way to implement Windows Service.</p>
Simple command-line alarm clock in Python (Python)
2015-10-25T18:27:27-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579117-simple-command-line-alarm-clock-in-python/
<p style="color: grey">
Python
recipe 579117
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple alarm clock in Python, that can be run from the command line in a terminal. It lets you specify the alarm time in minutes as a command line argument, and prints a wake-up message and beeps a few times, after that time arrives. You can use 0 for the minutes to test it immediately, including to adjust the volume using your speaker controls.</p>
Execute remote commands on windows like psexec (Python)
2011-11-18T11:54:42-08:00Ofer Helmanhttp://code.activestate.com/recipes/users/4179914/http://code.activestate.com/recipes/577945-execute-remote-commands-on-windows-like-psexec/
<p style="color: grey">
Python
recipe 577945
by <a href="/recipes/users/4179914/">Ofer Helman</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 4.
</p>
<p>This code attempts to implement psexec in python code, using wmi.
As part of a project of mine I had to run remote commands on remote Windows machines from other Windows machine. At first I used psexec for that with subprocess.Popen.
The reason in this code for creating .bat files and running them remotely is because complicated commands do not run properly with Win32_Process.Create</p>
<p>In this code I used this code: <a href="http://code.activestate.com/recipes/442521/history/3/" rel="nofollow">http://code.activestate.com/recipes/442521/history/3/</a></p>
<p>required installations:</p>
<p>pywin32 - <a href="http://sourceforge.net/projects/pywin32/files/pywin32/Build216/" rel="nofollow">http://sourceforge.net/projects/pywin32/files/pywin32/Build216/</a></p>
<p>wmi - <a href="http://timgolden.me.uk/python/downloads/" rel="nofollow">http://timgolden.me.uk/python/downloads/</a></p>
Recognizing speech (speech-to-text) with the Python speech module (Python)
2015-10-22T13:09:02-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579115-recognizing-speech-speech-to-text-with-the-python-/
<p style="color: grey">
Python
recipe 579115
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/language_translation/">language_translation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/speech_recognition/">speech_recognition</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to use the 'speech' (or 'pyspeech' - it seems to have two names) Python library to make the computer recognize what you say and convert it to text. Note: This library did not always give correct results for me, so it may not be advisable to use it in production. Also, the pyspeech site says that the library is no longer being maintained. Use at your own risk.</p>
Decimal Number To Byte(s) And String To Byte(s) Converter. (Python)
2012-01-24T21:11:47-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578025-decimal-number-to-bytes-and-string-to-bytes-conver/
<p style="color: grey">
Python
recipe 578025
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/bytes/">bytes</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>A function to convert decimal integer numbers, (from 0 to 255), into byte(s) format.
Another function calling the above function to convert ASCII strings into byte(s) format.</p>
<p>Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.</p>
<pre class="prettyprint"><code>>>> exec(open('/home/G0LCU/Desktop/Code/d2b.py').read())
>>> a=78
>>> type(a)
<class 'int'>
>>> b=d2b(a)
>>> print(b)
b'N'
>>> type(b)
<class 'bytes'>
>>> text="\x00(C)2012, B.Walker, G0LCU.\xFF"
>>> len(text)
27
>>> type(text)
<class 'str'>
>>> newtext=t2b(text)
>>> len(newtext)
27
>>> print(newtext)
b'\x00(C)2012, B.Walker, G0LCU.\xff'
>>> type(newtext)
<class 'bytes'>
</code></pre>
<p>It requires NOTHING special at all to work and can be run like above or imported from
the correct "Lib" drawer/folder/directorfy as:-</p>
<pre class="prettyprint"><code>>>> import d2b
</code></pre>
<p>And when imported called as:-</p>
<pre class="prettyprint"><code>>>> d2b.d2b(some_number, optional_some_other_mumber)<RETURN/ENTER>
</code></pre>
<p>OR</p>
<pre class="prettyprint"><code>>>> d2b.t2b(some_ASCII_string)<RETURN/ENTER>
</code></pre>
<p>Read the code for much more information...</p>
<p>Issued under the GPL2 licence.</p>
<p>Enjoy finding simple solutions to often very difficult problems.</p>
<p>Bazza, G0LCU.</p>
IP and MAC addresses (Python)
2016-07-07T17:52:15-07:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/577191-ip-and-mac-addresses/
<p style="color: grey">
Python
recipe 577191
by <a href="/recipes/users/2984142/">Jean Brouwers</a>
(<a href="/recipes/tags/ios/">ios</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/ipv4/">ipv4</a>, <a href="/recipes/tags/mac/">mac</a>, <a href="/recipes/tags/macos/">macos</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/python2_4/">python2_4</a>, <a href="/recipes/tags/python3_5/">python3_5</a>, <a href="/recipes/tags/uuid/">uuid</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 3.
</p>
<p>This module collects all IP and MAC addresses from several available sources on the underlying system. See the module documentation for more details, supported Python releases and platforms.</p>
Windows Event Log Viewer (Python)
2010-12-12T06:40:35-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577499-windows-event-log-viewer/
<p style="color: grey">
Python
recipe 577499
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>Windows Event Log Viewer</p>
A simple text file pager in Python (Python)
2017-02-10T21:34:45-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580755-a-simple-text-file-pager-in-python/
<p style="color: grey">
Python
recipe 580755
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/pagination/">pagination</a>, <a href="/recipes/tags/paging/">paging</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple text file pager in Python. It allows you to view text content a page at a time (with a user-definable number of lines per page). Like standard Unix utilities, it can either take a text file name as a command-line argument, or can read the text from its standard input, which can be redirected to come from a file, or to come from a pipe. The recipe is for Windows only, though, since it uses the msvcrt.getch() function, which is Windows-specific. However, the recipe can be modified to work on Unix by using things like tty, curses, termios, cbreak, etc.</p>
<p>More details here:</p>
<p><a href="https://jugad2.blogspot.in/2017/02/tp-simple-text-pager-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/02/tp-simple-text-pager-in-python.html</a></p>
Searching .dll and .exe files in PATH (Python)
2014-10-06T09:22:53-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576522-searching-dll-and-exe-files-in-path/
<p style="color: grey">
Python
recipe 576522
by <a href="/recipes/users/186902/">Michal Niklas</a>
(<a href="/recipes/tags/dll/">dll</a>, <a href="/recipes/tags/exe/">exe</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/version/">version</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 7.
</p>
<p>Returns the pathnames of the file (.exe or .dll)
which would be loaded/executed in the current environment.
It uses some dirs from configuration (SystemDir, WindowsDir)
and dirs from PATH.</p>
<p>To obtain version info it uses code from:
<a href="http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/getfilever.py" rel="nofollow">http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/getfilever.py</a></p>
<p>Example of usage:</p>
<pre class="prettyprint"><code> c:\tools\pyscripts\scripts>which_dll.py libpq.dll
2008-06-09 02:58:26 167936 [b] c:\postgresql\8.3\bin\libpq.dll ver:8.3.3.8160
2008-03-17 01:47:50 167936 [b] c:\tools\libpq.dll ver:8.3.1.8075
2008-03-17 01:47:50 167936 [b] g:\public\libpq.dll ver:8.3.1.8075
trying to load "libpq.dll" ...
c:\postgresql\8.3\bin\libpq.dll loaded
</code></pre>
Colo(u)rs Inside Text Mode Python... (Python)
2012-08-21T21:01:57-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578101-colours-inside-text-mode-python/
<p style="color: grey">
Python
recipe 578101
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/colour/">colour</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
Revision 2.
</p>
<p>A simple DEMO to show how to enhance Python inside a Terminal. This works on Classic AMIGAs, E-UAE,
Debian Linux 6.0.0, PCLinuxOS 2009, Windows XP and Vista and WinUAE, from Python 1.4.0 to 3.3A2.</p>
<p>Due to a complaint about my _fun_ upload recently I decided to post this so that the MANY can now
find out how to manipulate text inside a Python Terminal window so that it looks much better.</p>
<p>Read the code for more information...</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza...</p>
Detect when system is idle (Python)
2009-05-31T01:18:03-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576786-detect-when-system-is-idle/
<p style="color: grey">
Python
recipe 576786
by <a href="/recipes/users/924636/">Gabriel Genellina</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/idle/">idle</a>, <a href="/recipes/tags/idle_time/">idle_time</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/user_input/">user_input</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>Detect when system is idle, globally. That is, the user is not moving the mouse nor typing anything, in any application (not just our program).</p>
Python subprocess: hide console on Windows (Python)
2013-07-29T05:33:49-07:00Esteban Castro Borsanihttp://code.activestate.com/recipes/users/4184010/http://code.activestate.com/recipes/578300-python-subprocess-hide-console-on-windows/
<p style="color: grey">
Python
recipe 578300
by <a href="/recipes/users/4184010/">Esteban Castro Borsani</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>It creates a new <em>hidden</em> window, so it will work in frozen apps (.exe).</p>
Conway's Game of Life In Python (Python)
2013-06-13T15:33:41-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578559-conways-game-of-life-in-python/
<p style="color: grey">
Python
recipe 578559
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/life/">life</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/of/">of</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>Conway's Game of Life In Python</p>
add password masking ability to getpass.getpass() (Python)
2016-01-13T00:46:40-08:00KingMakhttp://code.activestate.com/recipes/users/4193393/http://code.activestate.com/recipes/579148-add-password-masking-ability-to-getpassgetpass/
<p style="color: grey">
Python
recipe 579148
by <a href="/recipes/users/4193393/">KingMak</a>
(<a href="/recipes/tags/character/">character</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/getpass/">getpass</a>, <a href="/recipes/tags/hiding/">hiding</a>, <a href="/recipes/tags/masking/">masking</a>, <a href="/recipes/tags/msvcrt/">msvcrt</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>adding the ability to display a password masking character of the programmer's choice</p>
Unix tee-like functionality via a Python class (Python)
2017-03-31T14:30:30-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580767-unix-tee-like-functionality-via-a-python-class/
<p style="color: grey">
Python
recipe 580767
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tee/">tee</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>The Unix tee commmand, when used in a command pipeline, allows you to capture the output of the preceding command to a file or files, while still sending it on to standard output (stdout) for further processing via other commands in a pipeline, or to print it, etc.</p>
<p>This recipe shows how to implement simple tee-like functionality via a Python class. I do not aim to exactly replicate the functionality of the Unix tee, only something similar.</p>
<p>More details and sample output here:</p>
<p><a href="https://jugad2.blogspot.in/2017/03/a-python-class-like-unix-tee-command.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/a-python-class-like-unix-tee-command.html</a></p>
Get a value un windows registry (Python)
2013-10-15T07:30:39-07:00Garel Alexhttp://code.activestate.com/recipes/users/2757636/http://code.activestate.com/recipes/578689-get-a-value-un-windows-registry/
<p style="color: grey">
Python
recipe 578689
by <a href="/recipes/users/2757636/">Garel Alex</a>
(<a href="/recipes/tags/registry/">registry</a>, <a href="/recipes/tags/win32api/">win32api</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>A small function to get a value in windows registry from its key path and value name.</p>
<p>Note that recipe <a href="http://code.activestate.com/recipes/502268/" rel="nofollow">http://code.activestate.com/recipes/502268/</a> gives a more complete solution.</p>
Win Registry module (Python)
2010-07-20T14:30:04-07:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/502268-win-registry-module/
<p style="color: grey">
Python
recipe 502268
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/registry/">registry</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 5.
</p>
<p>_winreg module wrapper.
Provides easy access, walking and creation/modification of keys and values.
Tested with Win98 and XP (admin)</p>
Get memory usage of Windows processes using GetProcessMemoryInfo (via ctypes) (Python)
2013-04-25T01:26:19-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/578513-get-memory-usage-of-windows-processes-using-getpro/
<p style="color: grey">
Python
recipe 578513
by <a href="/recipes/users/4170919/">Ben Hoyt</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/win32/">win32</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>These functions call the Win32 function GetProcessMemoryInfo() using ctypes to get the memory usage of the current process. Works on both 32-bit and 64-bit Windows and Python 2.6+ (including Python 3.x).</p>
Clear screen and beep for various platforms. (Python)
2011-02-26T14:26:02-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/
<p style="color: grey">
Python
recipe 577588
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/clearscreen/">clearscreen</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/error_beep/">error_beep</a>, <a href="/recipes/tags/error_sound/">error_sound</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/screenclear/">screenclear</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
</p>
<p>This little module gives a clear screen and beep for the classic AMIGA, WinUAE, Windows and Linux all in
CLI/Command-Prompt/Terminal mode.</p>
<p>It works from Python 1.4.x to 2.7.x; talk about backwards compatibility... ;oD
With very little modification it will work on Python 3.x.x easily.)</p>
<p>See the file clsbeep.py attached for more information.</p>
<p>it is saved as clsbeep.py and placed into the Python - Lib drawer or where-ever the modules are located
and called as a module:-</p>
<pre class="prettyprint"><code>>>> import clsbeep
</code></pre>
<p>Its usage is:-</p>
<p>clsbeep.cls() and clears the screen.
clsbeep.beep() and creates an error beep.
clsbeep.both() creates an error beep first then clears the screen.</p>
<p>It is Public Domain and if you modify it to suit other platforms please let me have a copy of your code... :)</p>
<p>Enjoy finding simple solutions to often very difficult problems. ;o)</p>
Quick-and-dirty Windows drive detector (Python)
2016-09-20T17:46:37-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580699-quick-and-dirty-windows-drive-detector/
<p style="color: grey">
Python
recipe 580699
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/drives/">drives</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/system_programming/">system_programming</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This is a quick-and-dirty Python script to detect the currently available drives on your Windows PC.</p>