Please use the script to get list of all mapped network drives on your target machine
Note:
Please run the script as System User to get all mapped drives for all users
Please run the script as Logged in User to get only the user’s mapped drives - But before running the script as Logged in User, we should have the computer that is logged in by any user.
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
import subprocess
with disable_file_system_redirection():
pObj = subprocess.Popen('net use', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print pObj.communicate()[0]
Sample Output: 20170527-Mapped-Drives.json
20170527-Mapped-Drives.json (1.08 KB)
Hi
i noticed 1 thing.
this should run as Logged In user, as mapped drive are per user ?
also if there is no active session, it can return error.
so with full respect and with no intention of “plagiarism” i merged to procedures found in this forum.
code:
‘’’
To check mapped network drives
only if user is Loged on
‘’’
import os
import subprocess
import re
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def enter(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def exit(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
with disable_file_system_redirection():
current_user = os.popen(‘query user’).read()
user_details = os.popen(“WMIC PATH Win32_NetworkLoginProfile GET LastLogon,Name”).read()
if current_user == “”:
print “Current User : No user has logged in : can’t check mapped network drives”
print " "
print “The Last logged on details”
for i in [i.strip() for i in user_details.split(’
') if ‘NT AUTHORITY’ not in i if i.strip()]:
print i
else:
print “The Current user details”
print current_user
print " "
import subprocess
pObj = subprocess.Popen(‘net use’, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print pObj.communicate()[0]
Hi @phcsolutions,
Thanks for the update
I have updated the conditions on the same post above - https://forum.mspconsortium.com/forum/script-library/5417-get-list-of-mapped-network-drives#post5417
Note:
Please run the script as System User to get all mapped drives for all users
Please run the script as Logged in User to get only the user’s mapped drives - But before running the script as Logged in User, we should have the computer that is logged in by any user.
Your modification on the script, really helps to avoid the presence of the error that if we run the script as Logged in User when the computer has not been logged in by any local/domain user.
Thank you. We welcome your ideas 