Jump to content

Mapping Network Drives


MMedina
 Share

Recommended Posts

Hello all, 

Been looking for and playing around with a script that would prompt me for a UserName and Password then Map a network drive.

I have included the code: 

#AutoIt3Wrapper_icon=your_icon.ico
#AutoIt3Wrapper_Run_Obfuscator=y
#obfuscator_parameters=/striponly
#NoTrayIcon

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Connect To Your Drive", 265, 135)
$username_id = GUICtrlCreateInput("", 88, 16, 153, 21)
$password_id = GUICtrlCreateInput("", 87, 44, 153, 21, $ES_PASSWORD)
GUICtrlCreateLabel("&Username", 24, 16, 52, 17)
GUICtrlCreateLabel("&Password", 26, 46, 50, 17)
$connect = GUICtrlCreateButton("&Connect", 24, 80, 217, 33, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON))
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $connect
            $username = GUICtrlRead($username_id)
            $password = GUICtrlRead($password_id)

            If $username = '' Or $password = '' Then
                MsgBox(16, 'Error', 'Empty username or password')
                ContinueLoop
            EndIf

            If DriveMapGet("X:") <> '' Then ; very fast
                MsgBox(16, 'Error', 'The device is already assigned')
                ContinueLoop
            EndIf

            GUISetCursor(15,1)
            DriveMapAdd("X:", "\\Server\share\filestore\" & $username, 0, $username, $password) ; slow
            If @error Then
                Switch @error
                    Case 1
                        $err_message = 'Undefined / Other error. Windows API return code: ' & @extended
                    Case 2
                        $err_message = 'Access to the remote share was denied'
                    Case 3
                        $err_message = 'The device is already assigned'
                    Case 4
                        $err_message = 'Invalid device name'
                    Case 5
                        $err_message = 'Invalid remote share'
                    Case 6
                        $err_message = 'Invalid password'
                EndSwitch
                GUISetCursor(2)
                MsgBox(16, 'Error', $err_message)
            Else ; everything OK
                Exit
            EndIf

    EndSwitch
WEnd

 

When I attempt the build I get the following:

 Obfuscator support has been discontinued and is replaced by Au3Stripper using "#Au3Stripper_" directives.
! The directive to run Au3Stripper is: #AutoIt3Wrapper_Run_Au3Stripper=y  ; Default is n
! #Au3Stripper_Parameters options are: 
/pe  : Replace and reference to a Global Const variable with its actual value.
/tl  : Create Au3Stripper.Log with a trace of all actions.
/debug: add Debug information to Au3Stripper.Log.
/so : This is the default when no parameters are provided. same as /sf + /sv
/sf : Strip all unused Func's
/sv : Strip all unused Global var records.
/mo : Just merges the Include files into the source and strips the Comments.
      This is similar to aut2exe and helps finding the errorline.
/mi : Sets the maximum Iterations Au3Stripper will perform. Default is 5.
/rm : Rename Variables and Functions to a shorter name.
/rsln: Replace @ScriptLineNumber with the actual line number.
/Beta: Use Beta Includes.
- Icon not found:  your_icon.ico ==> Changing to default ICON.
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\SMS.au3
+>18:28:11 AU3Check ended.rc:0
>Running Au3Stripper (18.708.1148.0)  from:C:\Program Files (x86)\AutoIt3\SciTE\Au3Stripper cmdline:
- 0.22 Iteration 1 Strip Functions result: Output  1050 lines, stripped 0 Func lines and 234 Commentlines
- 0.61 Iteration 2 Strip Variables result: Output  88 lines and stripped 962 lines
- 0.63 Iteration 3 Strip Variables result: Output  58 lines and stripped 30 lines
- 0.64 Iteration 4 Strip Variables result: Output  52 lines and stripped 6 lines
- 0.66 Iteration 5 Strip Variables result: Output  51 lines and stripped 1 lines
+> Source    1285 lines 48435 Characters.
+> Stripped  999 Func/Var lines and  234 comment lines, Total 46893 Characters.
+> Saved     95% lines 96% Characters.
+> Au3Stripper v18.708.1148.0 finished created:C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\SMS_stripped.au3
+>18:28:12 Au3Stripper ended.rc:0
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\SMS_stripped.au3
+>18:28:12 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\aut2exe\aut2exe.exe  /in "C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\SMS_stripped.au3" /out "C:\Users\Migue\AppData\Local\AutoIt v3\Aut2exe\~AU495C.tmp.exe" /nopack /comp 2
+>18:28:13 Aut2exe.exe ended.C:\Users\Migue\AppData\Local\AutoIt v3\Aut2exe\~AU495C.tmp.exe. rc:0
!>18:28:13 Problem copying file from: C:\Users\Migue\AppData\Local\AutoIt v3\Aut2exe\~AU495C.tmp.exe To :C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\SMS.exe
+>18:28:14 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 3.046

 

When I attempt to run the executable I get the following:
image.png.958b355268112965e718e97dab393724.png

Many thanks in advance

Link to comment
Share on other sites

Quote

Problem copying file from: C:\Users\Migue\AppData\Local\AutoIt v3\Aut2exe\~AU495C.tmp.exe To :C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\SMS.exe

Just try to add 

C:\Users\Migue\AppData\Local\AutoIt v3\Aut2exe\

and

C:\Users\Migue\Documents\Sync\Batches and Scripts\WDW-Scripts\

to your AVSoftware to the exclusion list.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...