redoules.github.io/python/list_windows.html
Guillaume 44f740504b added an article
about uploading data to a sharepoint site
2020-07-20 20:20:09 +02:00

266 lines
14 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="Data Science for Political and Social Phenomena">
<meta name="author" content="Guillaume Redoulès">
<link rel="icon" href="../favicon.ico">
<title>List all opened windows on Windows - Python</title>
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="../theme/js/jquery.min.js"><\/script>')
</script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="../theme/css/bootstrap.css" />
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link rel="stylesheet" type="text/css" href="../theme/css/ie10-viewport-bug-workaround.css" />
<!-- Custom styles for this template -->
<link rel="stylesheet" type="text/css" href="../theme/css/style.css" />
<link rel="stylesheet" type="text/css" href="../theme/css/notebooks.css" />
<link href='https://fonts.googleapis.com/css?family=PT+Serif:400,700|Roboto:400,500,700' rel='stylesheet' type='text/css'>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<meta name="tags" content="Other" />
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="..">Guillaume Redoulès</a>
</div>
<div class="navbar-collapse collapse" id="searchbar">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="../pages/about.html">About Guillaume</a></li>
<li><a href="https://github.com/redoules">GitHub</a></li>
<li><a href="https://www.linkedin.com/in/guillaume-redoul%C3%A8s-33923860/">LinkedIn</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Data Science<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="..#Blog">Blog</a></li>
<li><a href="..#Python">Python</a></li>
<li><a href="..#Bash">Bash</a></li>
<li><a href="..#SQL">SQL</a></li>
<li><a href="..#Mathematics">Mathematics</a></li>
<li><a href="..#Machine_Learning">Machine Learning</a></li>
<li><a href="..#Projects">Projects</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Projects<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://github.com/redoules/redoules.github.io">Notes (Github)</a></li>
</ul>
</li>
<!--<li class="dropdown">
<a href="../feeds/blog.rss.xml">Blog RSS</a>
</li>-->
</ul>
<form class="navbar-form" action="../search.html" onsubmit="return validateForm(this.elements['q'].value);">
<div class="form-group" style="display:inline;">
<div class="input-group" style="display:table;">
<span class="input-group-addon" style="width:1%;"><span class="glyphicon glyphicon-search"></span></span>
<input class="form-control search-query" name="q" id="tipue_search_input" placeholder="e.g. scikit KNN, pandas merge" required autocomplete="off" type="text">
</div>
</div>
</form>
</div>
<!--/.nav-collapse -->
</div>
</div>
<!-- end of header section -->
<div class="container">
<!-- <div class="alert alert-warning" role="alert">
Did you find this page useful? Please do me a quick favor and <a href="#" class="alert-link">endorse me for data science on LinkedIn</a>.
</div> -->
<section id="content" class="body">
<header>
<h1>
List all opened windows on Windows
</h1>
<ol class="breadcrumb">
<li>
<time class="published" datetime="2019-08-03T11:36:00+02:00">
03 août 2019
</time>
</li>
<li>Python</li>
<li>Other</li>
</ol>
</header>
<div class='article_content'>
<p>You can use the function <code>get_all_windows</code> to get a dictonnary containing the titles of the opened windows as keys and the handles of those windows as values</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">win32gui</span>
<span class="k">def</span> <span class="nf">get_all_windows</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns dict with window desc and hwnd,</span>
<span class="sd">  &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">_MyCallback</span><span class="p">(</span> <span class="n">hwnd</span><span class="p">,</span> <span class="n">extra</span> <span class="p">):</span>
<span class="n">hwnds</span><span class="p">,</span> <span class="n">classes</span> <span class="o">=</span> <span class="n">extra</span>
<span class="n">hwnds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">hwnd</span><span class="p">)</span>
<span class="n">classes</span><span class="p">[</span><span class="n">win32gui</span><span class="o">.</span><span class="n">GetWindowText</span><span class="p">(</span><span class="n">hwnd</span><span class="p">)]</span> <span class="o">=</span> <span class="n">hwnd</span>
<span class="n">windows</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">classes</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">win32gui</span><span class="o">.</span><span class="n">EnumWindows</span><span class="p">(</span><span class="n">_MyCallback</span><span class="p">,</span> <span class="p">(</span><span class="n">windows</span><span class="p">,</span> <span class="n">classes</span><span class="p">))</span>
<span class="k">return</span> <span class="n">classes</span>
</pre></div>
<div class="highlight"><pre><span></span><span class="n">get_all_windows</span><span class="p">()</span>
</pre></div>
<div class="highlight"><pre><span></span><span class="err">{&#39;&#39;: 3802422,</span>
<span class="err"> &#39;Forcepad driver tray window&#39;: 65676,</span>
<span class="err"> &#39;Jauge de batterie&#39;: 131542,</span>
<span class="err"> &#39;Network Flyout&#39;: 131650,</span>
<span class="err"> &#39;Dashlane&#39;: 5570658,</span>
<span class="err"> &#39;Wox&#39;: 131770,</span>
<span class="err"> &#39;JupyterLab - Brave&#39;: 66990,</span>
<span class="err"> &#39;python&#39;: 4261478,</span>
<span class="err"> &#39;Visual Studio Code - Insiders&#39;: 329780,</span>
<span class="err"> &#39;Code - Insiders&#39;: 526478,</span>
<span class="err"> &#39;Documents&#39;: 526010,</span>
<span class="err"> &#39;Windows PowerShell&#39;: 198580,</span>
<span class="err"> &#39;Progression&#39;: 394934,</span>
<span class="err"> &#39;Microsoft Edge&#39;: 131586,</span>
<span class="err"> &#39;Microsoft Store&#39;: 197328,</span>
<span class="err"> &#39;QTrayIconMessageWindow&#39;: 327816,</span>
<span class="err"> &#39;Hidden Window&#39;: 459506,</span>
<span class="err"> &#39;.NET-BroadcastEventWindow.4.0.0.0.3e2c690.0&#39;: 131824,</span>
<span class="err"> &#39;SystemResourceNotifyWindow&#39;: 197346,</span>
<span class="err"> &#39;MediaContextNotificationWindow&#39;: 197344,</span>
<span class="err"> &#39;Resilio Sync 2.6.3&#39;: 262934,</span>
</pre></div>
<p>}</p>
<div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;List of all opened windows : &quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">get_all_windows</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="s2">* &quot;</span> <span class="o">+</span> <span class="n">key</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
</pre></div>
<div class="highlight"><pre><span></span><span class="err">List of all opened windows : </span>
<span class="err"> * Forcepad driver tray window</span>
<span class="err"> * Jauge de batterie</span>
<span class="err"> * Network Flyout</span>
<span class="err"> * Dashlane</span>
<span class="err"> * Wox</span>
<span class="err"> * JupyterLab - Brave</span>
<span class="err"> * python</span>
<span class="err"> * Visual Studio Code - Insiders</span>
<span class="err"> * Code - Insiders</span>
<span class="err"> * Documents</span>
<span class="err"> * Windows PowerShell</span>
<span class="err"> * Progression</span>
<span class="err"> * Microsoft Edge</span>
<span class="err"> * Microsoft Store</span>
<span class="err"> * QTrayIconMessageWindow</span>
<span class="err"> * Hidden Window</span>
<span class="err"> * .NET-BroadcastEventWindow.4.0.0.0.3e2c690.0</span>
<span class="err"> * SystemResourceNotifyWindow</span>
<span class="err"> * MediaContextNotificationWindow</span>
<span class="err"> * Resilio Sync 2.6.3</span>
</pre></div>
</div>
<aside>
<div class="bug-reporting__panel">
<h3>Find an error or bug? Have a suggestion?</h3>
<p>Everything on this site is avaliable on GitHub. Head on over and <a href='https://github.com/redoules/redoules.github.io/issues/new'>submit an issue.</a> You can also message me directly by <a href='mailto:guillaume.redoules@gadz.org'>email</a>.</p>
</div>
</aside>
</section>
</div>
<!-- start of footer section -->
<footer class="footer">
<div class="container">
<p class="text-muted">
<center>This project contains 119 pages and is available on <a href="https://github.com/redoules/redoules.github.io">GitHub</a>.
<br/>
Copyright &copy; Guillaume Redoulès,
<time datetime="2018">2018</time>.
</center>
</p>
</div>
</footer>
<!-- This jQuery line finds any span that contains code highlighting classes and then selects the parent <pre> tag and adds a border. This is done as a workaround to visually distinguish the code inputs and outputs -->
<script>
$( ".hll, .n, .c, .err, .k, .o, .cm, .cp, .c1, .cs, .gd, .ge, .gr, .gh, .gi, .go, .gp, .gs, .gu, .gt, .kc, .kd, .kn, .kp, .kr, .kt, .m, .s, .na, .nb, .nc, .no, .nd, .ni, .ne, .nf, .nl, .nn, .nt, .nv, .ow, .w, .mf, .mh, .mi, .mo, .sb, .sc, .sd, .s2, .se, .sh, .si, .sx, .sr, .s1, .ss, .bp, .vc, .vg, .vi, .il" ).parent( "pre" ).css( "border", "1px solid #DEDEDE" );
</script>
<!-- Load Google Analytics -->
<script>
/*
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-66582-32', 'auto');
ga('send', 'pageview');
*/
</script>
<!-- End of Google Analytics -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../theme/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../theme/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>