[python-win32] Mapping Drives and windows folders

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Jan 15 03:45:13 EST 2004

> ... But the drive will not disconnect because the share 
>  does not exist anymore.  Is there aother way to disconnect a drive?
> import win32com.client
> wnt=win32com.client.Dispatch('Wscript.Network')
> wnt.RemoveNetworkDrive(driveletter)

OK. In short, check out win32wnet from the win32all extensions.
 You're looking for things like: WNetCancelConnection2 and
 WNetAddConnection2 &c. If the wsh code fails, this might too,
 but after that you're down to editing the registry and other
 weird hacks like that.

Can you give a dump of an interpreter output to show what happens?

> I need to manipulate users desktop contents at startup.  
> Using vbscript, this works good.

> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set oShell = WScript.CreateObject("WScript.Shell")
> Set colEnvironmentVariables = oShell.Environment("Volatile")
> sFolder = colEnvironmentVariables.Item("APPDATA") & _
>    "\Microsoft\Internet Explorer\Quick Launch"
> set oFolder=objFSO.GetFolder(sFolder)

Although there are ways to get to the environment from within
 Python (os.environ and the _winreg module, for example), I
 suggest you look at:
from win32com.shell import shell, shellcon
print shell.SHGetPathFromIDList (
  shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)

or, if you're feeling lazy, have a look at the winshell module in:


which wraps this code lightly because I never remember what the
 constants are called.

eg, to list all the files on the desktop:
import os, sys
import winshell

desktop = winshell.desktop ()
for f in os.listdir (desktop):
  print f



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

More information about the Python-win32 mailing list