[python-win32] Mapping Drives and windows folders
Christopher Nilsson
can at optiver.com.au
Wed Jan 14 20:49:15 EST 2004
Not sure about (II), but for (I), give this a go:
import win32wnet
def CloseConnection( name, revoke_permanency=True, force=True ):
try:
win32wnet.WNetCancelConnection2(name, revoke_permanency, force)
except Exception, why:
print 'Failed to close: %s\n%s' % (name, why)
# Kill the evil network drive...
CloseConnection("X:")
The microsoft doco reckons that WNetCancelConnection2 should remove
"remembered" connections like you're talking about, but I can't test
that part myself at the moment (sorry).
Cheers,
Chris.
Michael Montagne wrote:
>I.
>I'm using a combination like this to unmap drives so I can remap them
>due to a machine name change. 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)
>
>II.
>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)
>
>sDesktopFolder=oShell.SpecialFolders.Item("Desktop")
>set oDesktopFolder=objFSO.GetFolder(sDesktopFolder)
>
>sAllDesktopFolder=oShell.SpecialFolders.Item("AllUsersDesktop")
>set oAllDesktopFolder=objFSO.GetFolder(sAllDesktopFolder)
>
>
> Then I walk the files collection looking for the ones I want to delete.
>But I'm having trouble with the Envoronment variables part using python.
>
>
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32 at python.org
>http://mail.python.org/mailman/listinfo/python-win32
>
>
More information about the Python-win32
mailing list