drwoobie Posted September 8, 2008 Share Posted September 8, 2008 (edited) Network Drive Profile ToolComments greatly appreciated, and let me know if you find any bugs (that I don't find first). 09/11/08 Edit: Version 1.0.1.0 - Code Block updated and current .EXE uploadedJunked Help & About menu items (till I learn how to do them right)(Thx 2 ResNullius) - Program displays empty left window if no mapped drives, opens profile in right window(Thx 2 ResNullius) - If no current mapped drives AND no profile, program auto-opens File open dialogueIssues to address:If the UserProfile folder doesn't exist, it doesn't create itNo way to update profile from inside program (you can always rename the .txt file...)1. AboutThis program was written to be used as a way to back up a list of mapped network drives for a users profile and provide a simple interface for restoring (remapping) those drives. This program was designed to be used when it is not safe/desirable to use a users NTuser.dat file when migrating user settings.In English, I had a users profile that got corrupted and I feared that re-using the current NTuser.dat file would just let the errors migrate to the new profile. I remapped 15 or so drives and started thinking there should be a better way. So here is my answer.2. UsageFiles: NDprofileTool.exe is a stand-alone executable with no install. I designed it to run from a USB drive with no dependencies. All you need is the NDprofileTool.exe1st Execution:The first time your run NDprofileTool.exe, it will check for the presence of a UserProfile folder in the same directory that the executable started in, and if it is not found, it will create it.Next, NDprofileTool will look for a .txt file with the same name as the user (that is currently running the program) in the UserProfile directory. If a matching file is not found, one will be created. This file becomes the archive.Example: The current user is John Doe, with a user name JohnDoe. The computer technician runs the NDprofileTool from his USB drive. The program checks for a JohnDoe.txt file, doesnt find it, and creates it. No message about the creation is given.Subsequent Executions:The next time NDprofileTool is run under the user JohnDoe, the program will find a JohnDoe.txt file in the UserProfile directory. The program will then display the current drive listing in the left-hand pane, and the archived copy in the right-hand pane (read-only).You select the drive to be mapped in the right-hand pane and click the Map Drive button. The drive will be mapped as persistent under the current users credentials. Successful actions and errors will generate a popup window and the current view (Left side) will be update with the new drive.Other Actions:You have the ability to disconnect mapped network drive connections from within the program. Select the drive in the current view (Left pane) and click the Disconnect Drive buttonA success or failure message will be displayed and the current view (left pane) will refresh to show the current mapped drives.You can also open any other profile using the programs file menu.The refresh button refreshes the current view (left pane)Edit: create your own list of commonly mapped drives. Create your own file and use the following format: e:,\\Server\share\folder\3. LicenseThis program is released under the GPL, which can be found here: http://www.gnu.org/copyleft/gpl.htmlThe author may be contacted.Here's the code. (Be gentle )CODE#NoTrayIcon#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_outfile=NDprofileTool.exe#AutoIt3Wrapper_Res_Comment=Created by: Joe Livaudais (drwoobie@gmail.com)#AutoIt3Wrapper_Res_Description=Network Drive Profile Tool#AutoIt3Wrapper_Res_Fileversion=1.0.1.0#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p#AutoIt3Wrapper_Res_LegalCopyright=Published under GPL#AutoIt3Wrapper_Res_Language=1033#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****;***************************************; ; Network Drive Profile Tool; Written by Joe Livaudais - drwoobie@gmail.com; ;***************************************#include <GuiConstants.au3>#include <GuiListView.au3>#include <Process.au3>#include <file.au3>#include <ListViewConstants.au3>; GUI - create, showGuiCreate("Network Drive Profile Tool", 420, 353)GuiSetState() ; MENUs - create and populate$filemenu = GUICtrlCreateMenu ("&File")$Open_item = GUICtrlCreateMenuitem ("&Open",$filemenu)$Exit_item = GUICtrlCreateMenuitem ("E&xit",$filemenu); Variables$currentDir = "."$getFile = ""$numofDrives = ""$allDrives = DriveGetDrive( "network" ) if $allDrives = "" AND FileExists("UserProfile\" & @UserName & ".txt") = @error Then $leftView = GuiCtrlCreateListView("Drive | Source", 5, 26, 203, 275) readCurrent($numofDrives, $allDrives) $rightView = GuiCtrlCreateListView("Drive | Source", 212, 26, 203, 275, -1) getProfile($rightView) ElseIf $allDrives = "" Then $leftView = GuiCtrlCreateListView("Drive | Source", 5, 26, 203, 275) readCurrent($numofDrives, $allDrives) $rightView = GuiCtrlCreateListView("Drive | Source", 212, 26, 203, 275, -1) profileRead() else $numofDrives = $allDrives[0] if FileExists( $currentDir & "\UserProfile") then If FileExists("UserProfile\" & @UserName & ".txt") Then $leftView = GuiCtrlCreateListView("Drive | Source", 5, 26, 203, 275) readCurrent($numofDrives, $allDrives) $rightView = GuiCtrlCreateListView("Drive | Source", 212, 26, 203, 275, -1) profileRead() Else $leftView = GuiCtrlCreateListView("Drive | Source", 5, 26, 203, 275) profileWrite($numofDrives, $allDrives) EndIf Else DirCreate( $currentDir & "\UserProfile") $leftView = GuiCtrlCreateListView("Drive | Source", 5, 26, 203, 275) profileWrite($numofDrives, $allDrives) $rightView = GuiCtrlCreateListView("Drive | Source", 212, 26, 203, 275, -1) EndIfEndIf ; BUTTON$mapDrive = GuiCtrlCreateButton("Map Drive", 212, 306, 65, 20)$refreshView = GuiCtrlCreateButton("Refresh", 144, 306, 65, 20)$whackDrive = GuiCtrlCreateButton ("Disconnect Drive", 5, 306, 95, 20); Leftview FunctionsFunc profileWrite($numofDrives, $allDrives) GUICtrlCreateLabel($numofDrives & " drives currently mapped for " & @UserName & ":", 5, 5) $archiveFile = FileOpen("UserProfile\" & @UserName & ".txt", 2) For $i = 1 to $numofDrives Step 1 $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) FileWriteLine($archiveFile, $curDriveLtr & "," & $curDrivePath ) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $leftView) Next FileClose($archiveFile) ;Return EndFunc Func readCurrent($numofDrives, $allDrives) if $allDrives = "" then GUICtrlCreateLabel("No drives currently mapped for " & @UserName & ":", 5, 5) else GUICtrlCreateLabel($numofDrives & " drives currently mapped for " & @UserName & ":", 5, 5) For $i = 1 to $numofDrives Step 1 $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $leftView) Next endif ;Return EndFuncFunc disconnetDrive() $dropTarget = GUICtrlRead(GUICtrlRead($leftView, 1)) $splitDropLine = StringSplit ( $dropTarget, "|") $dropDriveLtr = StringTrimLeft($splitDropLine[1], 4) $dropDriveLtr = StringTrimright($dropDriveLtr, 1) DriveMapDel($dropDriveLtr) if @error = "1" Then msgbox (16, "Error", "Disconnection of " & $dropDriveLtr & " unsuccessful") Else MsgBox (64, "Completed", $dropDriveLtr & " successfully disconnected") EndIf refreshLeft($numofDrives, $allDrives) EndFuncFunc refreshLeft($numofDrives, $allDrives) _GUICtrlListView_DeleteAllItems($leftView) $allDrives = DriveGetDrive( "network" ) if $allDrives = "" Then $numofDrives = "0" Else $numofDrives = $allDrives[0] EndIf readCurrent($numofDrives, $allDrives) EndFunc; Rightview FunctionsFunc profileRead() $profileLineCount = _FileCountLines("UserProfile\" & @UserName & ".txt") GUICtrlCreateLabel($profileLineCount & " drives previously mapped for " & @UserName & ":", 210, 5) $archiveFile = FileOpen("UserProfile\" & @UserName & ".txt", 0) For $i = 1 to $profileLineCount Step 1 $archiveline = FileReadLine($archiveFile) $splitLine = StringSplit ( $archiveline, ",") GuiCtrlCreateListViewItem( " " & $splitLine[1] & " | " & $splitLine[2], $rightView) Next FileClose ( $archiveFile ) ;Return EndFuncFunc readFile() _GUICtrlListView_DeleteAllItems($rightView) $otherLineCount = _FileCountLines($getFile) $splitSource = StringSplit ( $getFile, "\") $sourceFile = _ArrayPop($splitSource) $sourceFile = StringTrimRight($sourceFile, 4) GUICtrlCreateLabel($otherLineCount & " drives mapped in the " & $sourceFile & " file: ", 210, 5) For $i = 1 to $otherLineCount Step 1 $archiveline = FileReadLine($getFile, $i) $splitLine = StringSplit ( $archiveline, ",") GuiCtrlCreateListViewItem( " " & $splitLine[1] & " | " & $splitLine[2], $rightView) Next ;Return EndFunc Func mapdrive() $mapTarget = GUICtrlRead(GUICtrlRead($rightView, 1)) $splitTargetLine = StringSplit ( $mapTarget, "|") $newDriveLtr = StringTrimLeft($splitTargetLine[1], 4) $newDriveLtr = StringTrimright($newDriveLtr, 1) $newDrivePath = StringStripWS($splitTargetLine[2], 1) DriveMapAdd($newDriveLtr, $newDrivePath, 1) if @error = "1" Then MsgBox (16, "Error", "An unknown error occured") ElseIf @error = "2" Then MsgBox (16, "Error", "Access to the remote share was denied") ElseIf @error = "3" Then MsgBox (16, "Error", "The device is already assigned") ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else MsgBox (64, "Completed!", $newDriveLtr & " mapped to " & $newDrivePath) EndIf refreshLeft($numofDrives, $allDrives) EndFuncfunc getProfile($rightView) $getFile = FileOpenDialog( "Pick the Drive Profile to open...", "UserProfile\", "Text (*.txt)", 1 + 2 ) if @error Then _GUICtrlListView_DeleteAllItems($rightView) profileRead() Else readFile() EndIf EndFuncWhile 1 $msg = GUIGetMsg() Select Case $msg = $Open_item getProfile($rightView) Case $msg = $Exit_item or $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $refreshView refreshLeft($numofDrives, $allDrives) Case $msg = $mapDrive mapdrive() Case $msg = $whackDrive disconnetDrive() EndSelect WEndGUIDelete()ExitNDprofileTool.exe Edited September 11, 2008 by drwoobie Thanks,drwoobieMy Projects:Network Drive Profile Tool Link to comment Share on other sites More sharing options...
ptrex Posted September 11, 2008 Share Posted September 11, 2008 @drwoobie If you create a .bat file using this command, and let the user run it, or put it in the startup folder. It will recreate the mappings as well. net use M: \\IPaddress\UserName /USER:UserName net use P: \\IPaddress\company /USER:UserName net use O: \\IPaddress\department /USER:UserName Does your appl. do anything different ? Regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
drwoobie Posted September 11, 2008 Author Share Posted September 11, 2008 (edited) @drwoobieIf you create a .bat file using this command, and let the user run it, or put it in the startup folder.It will recreate the mappings as well.net use M: \\IPaddress\UserName /USER:UserNamenet use P: \\IPaddress\company /USER:UserNamenet use O: \\IPaddress\department /USER:UserNameDoes your appl. do anything different ?Regards,ptrexptrex, Thanks for offering up your suggestion. All of this actually started with the thought of piping a NET USE command to a .txt file to back up a list of mapped drives.That is the essential nature of this app. Where I work, some drives are mapped as part of a novell login script, but I have some users that have some-to-many "extra" mapped drives. And because of the nature of some of the software we run, when a new user gets a new computer (or the local profile gets corrupt), we do not bring over their old ntuser.dat file. I wanted a way to archive their old mappings and compare it to a fresh profile so I could visually see what extra drives need to be mapped. The ability to open other profiles gives me the option of building a list of "extra" drives by group or department, not taken care of by login script. Edited September 11, 2008 by drwoobie Thanks,drwoobieMy Projects:Network Drive Profile Tool Link to comment Share on other sites More sharing options...
ResNullius Posted September 11, 2008 Share Posted September 11, 2008 (edited) Nicely thought out drwoobie.One suggestion: if you run it on a system with no mapped drive(s) the compiled version gives the "Line -1: Subscript used with non-Array variable" error.The problem in your code are these lines:$allDrives = DriveGetDrive( "network" ) $numofDrives = $allDrives[0]May want to think about error checking for no mapped drives and starting the Gui anyway, so at least the backed up drive list can be restored on machines that have no default mappings to start with.Edit: Added the "DriveGetDrive" line to the quoted code Edited September 11, 2008 by ResNullius Link to comment Share on other sites More sharing options...
drwoobie Posted September 11, 2008 Author Share Posted September 11, 2008 Nicely thought out drwoobie. One suggestion: if you run it on a system with no mapped drive(s) the compiled version gives the "Line -1: Subscript used with non-Array variable" error. The problem in your code are these lines: $allDrives = DriveGetDrive( "network" ) $numofDrives = $allDrives[0] May want to think about error checking for no mapped drives and starting the Gui anyway, so at least the backed up drive list can be restored on machines that have no default mappings to start with. Edit: Added the "DriveGetDrive" line to the quoted code Thank you for catching that ResNullius! I don't think I would have ever been in a situation to catch that particular error. I think I have a idea on how I want to fix it... Thanks,drwoobieMy Projects:Network Drive Profile Tool Link to comment Share on other sites More sharing options...
drwoobie Posted September 11, 2008 Author Share Posted September 11, 2008 if you run it on a system with no mapped drive(s) the compiled version gives the "Line -1: Subscript used with non-Array variable" error.Version 1.0.1.0 Code and executable updated. See original Post. Thanks,drwoobieMy Projects:Network Drive Profile Tool Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now