Top-rated recipes tagged "windows"http://code.activestate.com/recipes/tags/windows/top/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> 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> "raw_input" For All Versions Of Python... (Python) 2011-08-10T16:52:04-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577836-raw_input-for-all-versions-of-python/ <p style="color: grey"> Python recipe 577836 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/input/">input</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/raw_input/">raw_input</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>The code says it all... ;o)</p> <p>Put the two lines in any Python code and have universal KB input...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza, G0LCU...</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> 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> Use DebugView utility with standard python logging (Python) 2010-02-10T10:35:59-08:00Christopher Prinoshttp://code.activestate.com/recipes/users/481494/http://code.activestate.com/recipes/577040-use-debugview-utility-with-standard-python-logging/ <p style="color: grey"> Python recipe 577040 by <a href="/recipes/users/481494/">Christopher Prinos</a> (<a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/debugview/">debugview</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/sysinternals/">sysinternals</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This is a custom logging.Handler class that lets you use standard logging calls to output messages to SysInternals' DebugView utility.</p> Show OS error codes and messages from the os.errno module (Python) 2017-03-01T17:18:23-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580759-show-os-error-codes-and-messages-from-the-oserrno-/ <p style="color: grey"> Python recipe 580759 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/introspection/">introspection</a>, <a href="/recipes/tags/libraries/">libraries</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe is a simple Python introspection utility that displays the defined OS error codes and messages (that Python knows about) from the os.errno module. It works for both Python 2 and Python 3. For each kind of OS error defined in Python, it will display a serial number, the error code, and the corresponding error name, and English error message. E.g. the first few lines of its output are shown below:</p> <p>$ py -2 os_errno_info.py</p> <p>Showing error codes and names</p> <p>from the os.errno module:</p> <p>Python sys.version: 2.7.12</p> <p>Number of error codes: 86</p> <p>Idx Code Name Message</p> <p>0 1 EPERM Operation not permitted</p> <p>1 2 ENOENT No such file or directory</p> <p>2 3 ESRCH No such process</p> <p>3 4 EINTR Interrupted function call</p> <p>4 5 EIO Input/output error</p> <p>More information, full output and other details are available here:</p> <p><a href="https://jugad2.blogspot.in/2017/03/show-error-numbers-and-codes-from.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/show-error-numbers-and-codes-from.html</a></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> A pseudo-echo, (or printf), function for any Python version. (Python) 2017-01-20T22:17:23-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/580750-a-pseudo-echo-or-printf-function-for-any-python-ve/ <p style="color: grey"> Python recipe 580750 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/demo/">demo</a>, <a href="/recipes/tags/echo/">echo</a>, <a href="/recipes/tags/fs_uae/">fs_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/printf/">printf</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>A simple example of having a pseudo-echo using sys.stdout.write...</p> <p>This gives exactly the same results from Python Versions, 1.4.0, 2.0.1, 2.5.6, 2.6.9, 3.4.3 and 3.5.2 on various platforms including the classic AMIGA A1200.</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza.</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> A simple raw hexdumper. (Python) 2016-09-19T13:24:37-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/580697-a-simple-raw-hexdumper/ <p style="color: grey"> Python recipe 580697 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/fs_uae/">fs_uae</a>, <a href="/recipes/tags/hex/">hex</a>, <a href="/recipes/tags/hexdump/">hexdump</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/raw_hexdump/">raw_hexdump</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>This is not a hexreader. This code creates a raw hexdump of a binary file that is whitespace, optional, delimited. The dump is saved into the current directory with a ".hex" extension.</p> <p>It works on just about any current platform but is designed around a stock Amiga A1200(HD) with Python 1.4.0. It also works on the current stable version 3.5.2.</p> <p>I needed a hexdump some years ago for banging the Amiga hardware, and decided to modify recently for another usage but it had to still work on version 1.4.0 for the classic A1200.</p> <p>Enjoy...</p> Drop a minimal, valid Windows executable file to disk, for testing (Python) 2015-03-03T10:47:32-08:00Simon Harrisonhttp://code.activestate.com/recipes/users/4191738/http://code.activestate.com/recipes/579029-drop-a-minimal-valid-windows-executable-file-to-di/ <p style="color: grey"> Python recipe 579029 by <a href="/recipes/users/4191738/">Simon Harrison</a> (<a href="/recipes/tags/executable/">executable</a>, <a href="/recipes/tags/pe/">pe</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 3. </p> <p>Sometimes I need to create a valid windows executable file from a Python script for the sake of running a test.</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> 'Which' for Windows (Python) 2013-08-16T09:14:07-07:00Robert Pyronhttp://code.activestate.com/recipes/users/4174781/http://code.activestate.com/recipes/578642-which-for-windows/ <p style="color: grey"> Python recipe 578642 by <a href="/recipes/users/4174781/">Robert Pyron</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/which/">which</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 2. </p> <p>WHICH.PY scans through all directories specified in the system %PATH% environment variable, looking for the specified COMMAND(s). It tries to follow the sometimes bizarre rules for Windows command lookup.</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> 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> 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> Disable File System Redirector (Python) 2012-02-06T16:34:02-08:00zxwhttp://code.activestate.com/recipes/users/4180790/http://code.activestate.com/recipes/578035-disable-file-system-redirector/ <p style="color: grey"> Python recipe 578035 by <a href="/recipes/users/4180790/">zxw</a> (<a href="/recipes/tags/32bit/">32bit</a>, <a href="/recipes/tags/64bit/">64bit</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/redirector/">redirector</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 5. </p> <p>This disables the <a href="http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx">Windows File System Redirector</a>.</p> <p>When a 32 bit program runs on a 64 bit operating system the paths to C:/Windows/System32 automatically get redirected to the 32 bit version (C:/Windows/SysWow64), if you really do need to access the contents of System32, you need to disable the file system redirector first.</p> Batch Local Network Messaging System (Batch) 2012-02-03T01:41:41-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578028-batch-local-network-messaging-system/ <p style="color: grey"> Batch recipe 578028 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/alex/">alex</a>, <a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/batch_file/">batch_file</a>, <a href="/recipes/tags/dos/">dos</a>, <a href="/recipes/tags/messaging/">messaging</a>, <a href="/recipes/tags/messenger/">messenger</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/wallar/">wallar</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/wired/">wired</a>, <a href="/recipes/tags/wired_network/">wired_network</a>). Revision 3. </p> <p>This is a Batch Local Messaging System that can be used to send messages between computers that share the same file system.</p> <p>There are three files in the code below. They are separated with dashed lines. There is a comment on the top of each segment of code indicating the file name that the code needs to be saved as. They need to be saved as three separate batch files in the same folder. </p> <p>The first file, MessengerMain.bat will ask you for your name and then an address. The name should be whatever you wish your screen name to be. The address needs to be the path of the FOLDER that is shared between you and the other computer that you are communicating with. Once these pieces of information are entered, two screens will appear. The first is the Sender screen and the other is the Receiver screen. </p> <p>How does it work? The MessengerMain.bat file will create two text files, Name.txt and Address.txt, that will hold your user name and the common folder address. It will then use the START command to run Sender.bat and Receiver.bat. Sender.bat will create a text file named msgtext.txt in the address folder you specified in MessengerMain.bat. If there is already a file of this sort in existence in the address folder, it will overwrite it. Once this file is created, any message you enter will be saved in the msgtext.txt file after the name you entered (%name%: %msg%). Sender.bat the CLS (clears) the screen and asks you for another message continuously. Receiver.bat is very similar. Receiver.bat, first off, reads the Address.txt file and the Name.txt file to find your information given in MessengerMain.bat just like Sender.bat does. It will count the number of lines in the msgtext.txt file and will clear the whole screen and print out the whole contents of the file if the number of lines in msgtext.txt increases. So basically you are writing to a shared file and reading from a shared file. </p> <p>Example:</p> <p>I have a folder called MSGFolder located in the folder as I have my MessengerMain.bat, Receiver.bat, and Sender.bat files. I then run MessengerMain.bat by double clicking on the icon. I enter Alex for my Name and MSGFolder as the Address. I then double click MessengerMain.bat again and enter the name Bob for Name and MSGFolder for Address. Once you do this you can type in either of the Sender.bat interfaces and it will show up as if you are talking. </p> Manage environment variables on Windows (Python) 2011-03-31T18:27:57-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/577621-manage-environment-variables-on-windows/ <p style="color: grey"> Python recipe 577621 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/environment/">environment</a>, <a href="/recipes/tags/pywin32/">pywin32</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 7. </p> <p>This recipe facilitates getting and setting of both "user" and "system" environment variables on Windows. It uses PyWin32 (included in ActivePython) ... and works on both Python 2 and Python 3.</p>