Removing network drives

I had a need to unmap and remap drives to various UNC paths in a utility I’m writing.  Using the IWshRuntimeLibrary.WshNetwork gave me the RemoveNetworkDrive function, which I happily used.  Well, happy until it gave me this error:

The local device name has a remembered connection to another network resource. (Exception from HRESULT: 0x800704B2)

Looking at the documentation showed me the third parameter:
bUpdateProfile Optional. If bUpdateProfile is supplied and its value is TRUE, this mapping is removed from the user profile.

Setting this to True ensures the mapping is removed from the user’s profile and allows you to map that device name to a new path right after removing it without getting an error.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.