Unable to locate files with long names on Windows with Python

Use the 8.3 fallback to avoid the long pathname, browsing in Win7 explorer this seems to be what windows itself does, ie every long paths has a shorter ‘true name’: >>> long_unc=”\\\\K53\\Users\\Tolan\\testing\\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxxxxdddddddddddddddddddddwgggggggggggggggggggggggggggggggggggxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\esssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggeee” >>> os.listdir(long_unc) FileNotFoundError: [WinError 3] but you can use win32api (pywin32) to ‘build’ up a shorter version, ie short_unc=win32api.GetShortPathName(win32api.GetShortPathName(win32api.GetShortPathName(“\\\\K53\\Users\\Tolan\\testing\\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”)+”\\xxxxxxxxxxxxxxxxxxxxxxxxdddddddddddddddddddddwgggggggggggggggggggggggggggggggggggxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”) + “\\esssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggeee”) >>> print(short_unc) … Read more

How can I detect when Windows 10 enters tablet mode in a Windows Forms application?

To get whether the system is in tablet mode or not, query the system metric ConvertibleSlateMode like so (not tested, but it should work fine as far back as XP): public static class TabletPCSupport { private static readonly int SM_CONVERTIBLESLATEMODE = 0x2003; private static readonly int SM_TABLETPC = 0x56; private static Boolean isTabletPC = false; … Read more

How can I programmatically manipulate Windows desktop icon locations?

If I’m not mistaken the desktop is just a ListView, and you’ll have to send the LVM_SETITEMPOSITION message to the handle of the desktop. I googled a bit for some c# code and couldn’t find a example, but I did found the following article. Torry: …get/set the positions of desktop icons?. It’s delphi code, but … Read more

How to get the z-order in windows?

You can use the GetTopWindow function to search all child windows of a parent window and return a handle to the child window that is highest in z-order. The GetNextWindow function retrieves a handle to the next or previous window in z-order. GetTopWindow: http://msdn.microsoft.com/en-us/library/ms633514(VS.85).aspx GetNextWindow: http://msdn.microsoft.com/en-us/library/ms633509(VS.85).aspx

Analyzing a crash in Windows: what does the error message tell us?

The 64-bit time stamp is the time application’s primary thread was created in 100-nanosecond intervals since January 1, 1601 (UTC) (this is known as FILETIME). The 32-bit timestamp is indeed in time_t format (it tells the time the module was created and is stored in the module’s header). I’d say 0x0002d160 is an offset from … Read more

Windows Impersonation from C#

It’s possible, although it requires you to do a lot of code. See NtCreateToken and CreateToken. You need SeCreateTokenPrivilege, although that won’t be a problem since you’re running under NT AUTHORITY\SYSTEM. You can then use the created token to impersonate inside a thread.

Can a Windows dll retrieve its own filename?

I think you’re looking for GetModuleFileName. http://www.swissdelphicenter.ch/torry/showcode.php?id=143: { If you are working on a DLL and are interested in the filename of the DLL rather than the filename of the application, then you can use this function: } function GetModuleName: string; var szFileName: array[0..MAX_PATH] of Char; begin FillChar(szFileName, SizeOf(szFileName), #0); GetModuleFileName(hInstance, szFileName, MAX_PATH); Result := … Read more

How to programmatically create a shortcut using Win32

Try Windows Shell Links. This page also contains a C++ example. Descriptive Snippet: Using Shell Links This section contains examples that demonstrate how to create and resolve shortcuts from within a Win32-based application. This section assumes you are familiar with Win32, C++, and OLE COM programming. EDIT: Adding the code sample in case the link … Read more