ChrisPremo Posted June 2, 2011 Share Posted June 2, 2011 I want to create a simple drive mapping exe for management purposes (to access various District office File Server share folders). I created this script and it partially works. It will create the drive mapping if none currently exists. However, what I want it to do is check if a current "X:" mapping exists and delete that mapping then continue with the mapping entered. Eventually, I also want to have a selection of 12 server names rather than have the user enter the name. Specifically, I'd like there to be 12 options, the user picks the appropriate one and then the selected option provides the "$Server" name. Current Script **************************************************************************************************************************************************** ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) $answer = MsgBox(4, "District Office Drive Mapping", "This script will create an "X:\" Drive mapping for the selected District Office. Run?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(4096, "DO Drive Mapping", "OK. Bye!") Exit EndIf $Current = DriveMapGet("X:") If $Current <> "" Then DriveMapDel("X:\\Dist03FileSvr\d$") EndIf $Server = InputBox("District Office Server.", "Please enter the District Office File Server to map.") ; Map X drive to Selected server's D:\ drive. DriveMapAdd("X:", "\\" & $Server & "\D$") ; Finished! Link to comment Share on other sites More sharing options...
sleepydvdr Posted June 2, 2011 Share Posted June 2, 2011 I think the DriveMapDel("X:\\Dist03FileSvr\d$") simply needs to be DriveMapDel("X:"). #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 2, 2011 Author Share Posted June 2, 2011 (edited) That's what I tried first and nothing happened. I even tried the DriveMapGet("X:") command to get the "Actual" map name and sent that to the DriveMapDel(DriveMapGet("X:")) command and nothing happend. The only way I can map is to manually delete the drive mapping. Edited June 2, 2011 by ChrisPremo Link to comment Share on other sites More sharing options...
Developers Jos Posted June 2, 2011 Developers Share Posted June 2, 2011 and with: DriveMapDel("X:") ? SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 2, 2011 Author Share Posted June 2, 2011 (edited) Yes both ways DriveMapDel("X:") and DriveMapDel(DriveMapGet("X:")) neither worked. I should note that this testing has been on a Windows 7 SP1 PC. Edited June 2, 2011 by ChrisPremo Link to comment Share on other sites More sharing options...
Developers Jos Posted June 2, 2011 Developers Share Posted June 2, 2011 Yes both ways DriveMapDel("X:")and DriveMapDel(DriveMapGet("X:"))neither worked.So the mapped drive for X: remains?What is the returncode given?do run the script in the same context (user rights)?You can remove the mapped drive when doing a "Net use x: /del" from the commandprompt? SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 2, 2011 Author Share Posted June 2, 2011 So the mapped drive for X: remains? YESWhat is the returncode given?Don't know. I'm not seeing any error code. What would I add to the script to display that.Do run the script in the same context (user rights)?I'm an administrator on the PC and network.You can remove the mapped drive when doing a "Net use x: /del" from the commandprompt?Yes I can delete the Drive mapping using theNet use x: /delcommand line. Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 2, 2011 Author Share Posted June 2, 2011 I just found that if I run this command Run("Net use x: /del") the drive mapping is removed and the new mapping is created. However, there is a "quick" DOS box that flashes on the screen as the "Net use . . . " command is executed. I'd rather not see any command box flash on screen. Now I need to figure out how to present a "Choice" of server names to select from rather than having the user enter the server name. Then I want to use that selection to set my "Drive mapping" unc name. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 2, 2011 Developers Share Posted June 2, 2011 1. returncode wanted was the returncode from DriveMapDel("X:") command that you can capture in a variable. 2. The reason I asked about the context was to make sue you are running the script in the same context or else the command doesn't do much. So are you running this script in the same user account as you are seeing the mapping for? SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 2, 2011 Author Share Posted June 2, 2011 1. returncode wanted was the returncode from DriveMapDel("X:") command that you can capture in a variable.2. The reason I asked about the context was to make sue you are running the script in the same context or else the command doesn't do much.So are you running this script in the same user account as you are seeing the mapping for?What is the script command that will display the returncode????Yes I'm running the command in the same account (mine) that I'm seeing the mapping for (my computer). Link to comment Share on other sites More sharing options...
Maffe811 Posted June 2, 2011 Share Posted June 2, 2011 Now I need to figure out how to present a "Choice" of server names to select from rather than having the user enter the server name. Then I want to use that selection to set my "Drive mapping" unc name.Dropdown menu ?You could even have multiple buttons. [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 3, 2011 Author Share Posted June 3, 2011 Dropdown menu ?You could even have multiple buttons.Either would be great, but dropdown probably the best. Any examples????? Link to comment Share on other sites More sharing options...
ChrisPremo Posted June 3, 2011 Author Share Posted June 3, 2011 After searching around yesterday evening, I found this code and modified it to my needs. Also found that I needed to add a "WinWaitActive("Test","Test",5)" statement between the Map-Delete and Map-Add statements to get them to work properly. expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Original Author: Jonathan Bennett (jon@hiddensoft.com) ; Modification Author: Chris Premo (Christopher.Premo@mbc.ca.gov) ; ; Script Function: ; Use InputBox to map network Drive. ; #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Creates the GUI ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Connecto = GUICreate("Connector", 268, 107, 342, 126) GUISetBkColor(0xFFFFFF) $Label1 = GUICtrlCreateLabel("Select a server to connect to:", 8, 8, 250, 27) GUICtrlSetFont(-1, 14, 400, 0, "Tahoma") $DropDown = GUICtrlCreateCombo("Server...", 8, 40, 249, 25) GUICtrlSetData($DropDown, "Dist02FileSvr|Dist03FileSvr|Dist04FileSvr|Dist05FileSvr|Dist06FileSvr|Dist08FileSvr|Dist09FileSvr|Dist10FileSvr|Dist11FileSvr|Dist12FileSvr|Dist17FileSvr|Dist18FileSvr", "Server...") $DMP = GUICtrlCreateButton("DriveMap", 8, 72, 75, 25, $WS_GROUP) $Exit = GUICtrlCreateButton("Exit", 184, 72, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Sets conditions of the GUI ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ; Sets Combo box Case $DropDown ; Sets RDP button to connect to selected server Case $DMP $Current = DriveMapGet("X:") $ServerChoice=GUICtrlRead($DropDown) if DriveMapGet("X:")="" Then ;Run("Net use x: /del", "",@SW_HIDE ) Else DriveMapDel("X:") EndIf WinWaitActive("Test","Test",5) ; Map X drive to \\myserver\stuff using current user DriveMapAdd("X:", "\\" & $ServerChoice & "\D$") Exit ; Sets Exit button to exit GUI Case $Exit Exit EndSwitch WEnd ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Finished! 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