Petri.com forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.com is happy to award RicklesP the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read
Notices

Script to report on current mapped drive connect

Script to report on current mapped drive connect

this thread has 10 replies and has been viewed 5843 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10th April 2008, 15:39
Octagon's Avatar
Octagon Octagon is offline
Casual
It's not a coincidence
 
 Join Date: Feb 2008
  6 month star 12 month star
 Posts: 80
 Reputation: Octagon is on a distinguished road (18)
Default Script to report on currently connected mapped drives

Has anyone found or written a script which will report back on a user's current mapped drives?
I am about migrate an old file server to a new AD domain but am finding the data is all over the place with people being mapped to the same drives on different letters, some using H:\ for personal drives , others using H:\ to access public shares etc etc. I want to look at who has what before I move the data and connect everyone back with proper structured mappings.

Last edited by Octagon; 10th April 2008 at 16:37..
  #2  
Old 10th April 2008, 16:38
karatecki's Avatar
karatecki karatecki is offline
Casual
Casual
 
 Join Date: Jan 2008
  6 month star 12 month star
 Location: Missouri, USA
 Posts: 37
 Reputation: karatecki is on a distinguished road (39)
Default Re: Script to report on current mapped drive connect

Perhaps this will do what you are looking for:

The PsTools suite from SysInternals has a lot of great tools which can do all sorts of things on remote machines. Specifically, you will be interested in the PsLoggedOn tool. Download the full suite here:
http://technet.microsoft.com/en-us/s.../bb896649.aspx

From the PSLoggedOn information on said site:
"PsLoggedOn is an applet that displays both the locally logged on users and users logged on via resources for either the local computer, or a remote one."

You can also script this, I'm not sure if you have a known naming scheme for all computers...you will need the computer names. Let me know if I can help any more...but I think this will do the trick.

As a side note...the PsShutdown is handy for remotely restarting machines. I particularly like scripting this one, when the machines in a computer lab shut down one by one in order, it's fun to watch!

Have a great day.
~Kara
  #3  
Old 10th April 2008, 17:43
Octagon's Avatar
Octagon Octagon is offline
Casual
It's not a coincidence
 
 Join Date: Feb 2008
  6 month star 12 month star
 Posts: 80
 Reputation: Octagon is on a distinguished road (18)
Default Re: Script to report on current mapped drive connect

Thanks for that, I ran the tool but it doesn't output any network drive information, I have very little scripting knowledge so can't mod this to suit. I have all the computer names for the domain.
  #4  
Old 10th April 2008, 19:34
karatecki's Avatar
karatecki karatecki is offline
Casual
Casual
 
 Join Date: Jan 2008
  6 month star 12 month star
 Location: Missouri, USA
 Posts: 37
 Reputation: karatecki is on a distinguished road (39)
Default Re: Script to report on current mapped drive connect

How many computers are we talking about here? The reason I ask is because you can access mount points (mapped drives) from the registry. You can do this from a centralized workstation/server, by running regedit and going to File>Connect Network Registry, entering the computer name and browsing to the following key:
HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\MountPoints2\

The issue that comes up here with scripting is that since "HKCU" refers to the current user, if you're running regedit from a remote machine you can browse all the users keys, but not the "current user" that I know of.

Anyway, what I am thinking here is that I could help you write a script which would export the correct registry key, and if you put it on a shared drive for all users, and instructed them to run it, you could gather data about what each user has mapped. This may end up being the simplest way. By the way, I did try that PsLoggedOn and saw that it didn't report the mapped drives, it only reports the shares being accessed by a user. Sorry about that!
  #5  
Old 11th April 2008, 03:49
joeqwerty's Avatar
joeqwerty joeqwerty is offline
Moderator
 
 Join Date: Jul 2007
  6 month star 12 month star
 Posts: 4,870
 Reputation: joeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to behold (669)
Default Re: Script to report on current mapped drive connect

This may seem old school but you could put a command in your logon script (assuming you use one) like this:

net use >C:\netuse.txt

This will output a list of all drive mappings on each computer to a file called netuse.txt in the root of the C: drive on each computer. You can then 'pick up" these files and review them. I'm sure someone with more scripting knowledge than me can come up with a script that names the files based on the user name and automates the collection of the files.
  #6  
Old 11th April 2008, 13:49
Octagon's Avatar
Octagon Octagon is offline
Casual
It's not a coincidence
 
 Join Date: Feb 2008
  6 month star 12 month star
 Posts: 80
 Reputation: Octagon is on a distinguished road (18)
Default Re: Script to report on current mapped drive connect

thanks for the ideas chaps, I have been doing some digging around the registry to try and find the required info, the Key which holds the data is :

HKCU\Network

there are subkeys within that key which correspond to the network drive mapping info. Now all I need to do is try and bodge a script together to read it and output.
  #7  
Old 11th April 2008, 15:21
karatecki's Avatar
karatecki karatecki is offline
Casual
Casual
 
 Join Date: Jan 2008
  6 month star 12 month star
 Location: Missouri, USA
 Posts: 37
 Reputation: karatecki is on a distinguished road (39)
Default Re: Script to report on current mapped drive connect

Joe-Good idea!
I forgot that net use by itself will report the mapped drives...I was making it much more difficult than needed-doh!


Octagon,
A really simple logon batch file will get you what you need, you could even redirect the text file to a share location which you make and everyone has access to if you wanted. I just tested this command:

net use >\\servername\some_share\%username%Mapped.txt

The %username% inserts the username into the name of the file. And the output's much easier to read than what you'd get with a reg file. Put that command inside a text file and save it as whatever.bat (make sure in the type drop down you select "all files") and you have yourself a script.

You can put login scripts in either the local policy or group policy (group policy preferred since it's easier to manage). But I'm not sure you currently have a domain since you said you were migrating an old file server, is this old file server also on an existing domain?

If you don't have a domain, I think the easiest thing to do would be to put the script out on a share that everyone can access and have them run it. Let them know they won't have their mapped drives if they don't

By the way, might I suggest moving to a standard mapping scheme? I'm new at my company so I still can't remember what ours is...but across the board (we have 30 locations in the US) we have the same drive mapping (X to public, V to personal, etc). It helps, but there are always exceptions.

~Kara
  #8  
Old 11th April 2008, 15:23
joeqwerty's Avatar
joeqwerty joeqwerty is offline
Moderator
 
 Join Date: Jul 2007
  6 month star 12 month star
 Posts: 4,870
 Reputation: joeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to beholdjoeqwerty is a splendid one to behold (669)
Default Re: Script to report on current mapped drive connect

Kara, I wasn't sure if the %username% variable would work or not. Thanks for pointing out that it does. That will make it easier as it can be piped to a network share as you suggested and have a uniquly named file for each user instaed of having to manually colect the files from each computer.

Last edited by joeqwerty; 11th April 2008 at 15:26..
  #9  
Old 11th April 2008, 15:38
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Script to report on current mapped drive connect

The subkeys under HKCU\Network are for the persistent mappings only.

If you want to see all mappings, here is joeqwerty's solution scripted for logonscript.
Code:
:: http://forums.petri.com/showthread.php?t=23061

@echo off

Set "destinationfile=\\unc\folder\NetUseCollection.txt"

:dateparts (%yy% and %mm% and %dd%)
for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
   for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
      (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )

SetLocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

Set "userfolder=%userprofile%"
Set "flagP=NetUse %username%.flag"
Set "nwflag=%userfolder%\%yy%%mm% - %flagP%"  (add_or_remove dateparts to filename, see post)

IF NOT EXIST "%nwflag%" (
  For /f "tokens=*" %%* in ('dir /B "%userfolder%\*%flagP%" 2^>nul') Do (
   Del /F "%userfolder%\%%*"
  )
  For /f "tokens=1*" %%i in ('net.exe use^|Find "\\"^|Find ":"') Do (
   If /i "!firstline!" NEQ "done" (
    > "%nwflag%" echo.%yy%-%mm%-%dd% %userdomain%\%username% [on %computername%]
    >>"%nwflag%" echo.----------------------------------------------------------------
   )
   Set "firstline=done"
   >>"%nwflag%" echo.%%i %%j
  )
  IF NOT EXIST "%destinationfile%" echo.>>"%destinationfile%"
  >>"%nwflag%" echo.& >>"%nwflag%" echo.
  IF EXIST "%destinationfile%" (
    Copy "%destinationfile%"/b + "%nwflag%"/b "%destinationfile%"
  )
)

EndLocal
If you want to query the registry, to can use Reg.exe query in a batch.
Or you can write a vbscipt to collect more information.

\Rems
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts

Last edited by Rems; 11th April 2008 at 18:09.. Reason: added the GREEN - !see also my next repy
  #10  
Old 11th April 2008, 16:14
Octagon's Avatar
Octagon Octagon is offline
Casual
It's not a coincidence
 
 Join Date: Feb 2008
  6 month star 12 month star
 Posts: 80
 Reputation: Octagon is on a distinguished road (18)
Default Re: Script to report on current mapped drive connect

Thanks again all for the input, Rems that script is perfect, exactly what I was after.

who gets the karma?
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapped Drive Problem parklabel Windows Server 2000 / 2003 / 2003 R2 8 9th April 2008 07:37
Renaming The Mapped Drive MetalSmith General Scripting 3 22nd September 2007 02:35
Cannot disconnect mapped drive humbletech99 Windows 2000 Pro, XP Pro 23 29th January 2007 23:46
Strange mapped drive problem ghughes87 Windows Server 2000 / 2003 / 2003 R2 8 20th April 2006 12:09
Mapped network doesn't always connect flying goose Windows Server 2000 / 2003 / 2003 R2 4 21st May 2004 13:27


All times are GMT +3. The time now is 17:19.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri