Echbiahn

Drive Mapping Issue

12 posts in this topic

#1 ·  Posted

Hello,

I've been writing a script to help automate a big installation that usually requires a bunch of manual work. On one of the steps is to map the N:\ drive. I created a function to run this step, but for some reason it never visibly shows it mapped the drive and the function always returns as successful (True). Sometimes if I run it again it will return the error: "The device is already assigned", which is why I added the DriveMapDel beforehand.

Func _StepSeven()
    $remoteShare = "\\" & GUICtrlRead($serverName) & "\RNAPGM"
    $remoteShare = String($remoteShare)
    DriveMapDel("N:")
    DriveMapAdd("N:", $remoteShare)
    If @error Then
        Switch @error
            Case 1
                $message = "Undefined / Other error"
            Case 2
                $message = "Access to the remote share was denied"
            Case 3
                $message = "The device is already assigned"
            Case 4
                $message = "Invalid device name"
            Case 5
                $message = "Invalid remote share"
            Case 6
                $message = "Invalid password"
        EndSwitch
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Drive Map Error: " & $message & @CRLF)
        Return False
    EndIf
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Drive Map Complete" & @CRLF)
    Exit;Abruptly stop script to test drive mapping
    Return True
EndFunc

 

Now, if I run a simple script, such as below, it always successfully maps and shows the mapped drive everytime.

DriveMapDel("N:")
DriveMapAdd("N:", "\\10.0.0.16\RNAPGM")
If @error Then MsgBox(0, "ERROR", @error)

 

Is there something I'm doing wrong or missing to make this work in my function? If needed, I can post the rest of the source code.

Thanks for the help!

Share this post


Link to post
Share on other sites



#2 ·  Posted

When you run your installation script, are you running it as the local user, or as System or another account?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

20 minutes ago, JLogan3o13 said:

When you run your installation script, are you running it as the local user, or as System or another account?

I am running it logged in under a domain admin.

Share this post


Link to post
Share on other sites

#4 ·  Posted

If you place a consoleswrite or msgbox just before the "DriveMapDel", do you get the expected output from the msgbox?

Like this:

 

$remoteShare = "\\" & GUICtrlRead($serverName) & "\RNAPGM"
    $remoteShare = String($remoteShare)
    
   MsgBox(0,"",$remoteShare)
    
    DriveMapDel("N:")
    DriveMapAdd("N:", $remoteShare)

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

6 minutes ago, david1337 said:

If you place a consoleswrite or msgbox just before the "DriveMapDel", do you get the expected output from the msgbox?

Like this:

 

$remoteShare = "\\" & GUICtrlRead($serverName) & "\RNAPGM"
    $remoteShare = String($remoteShare)
    
   MsgBox(0,"",$remoteShare)
    
    DriveMapDel("N:")
    DriveMapAdd("N:", $remoteShare)

 

Yes, I do get it to display what I'm expecting. If I reboot my computer, it works the first time, after I disconnect the drive to test for 2nd time is when it starts to act funny and not display... but later in the installation it calls executables from the mapped drive and they execute successfully even though I can't see the drive visibly mapped.

Share this post


Link to post
Share on other sites

#6 ·  Posted

Okay, very weird that it is able to call executables directly from the mapped drive, when the drive is not visible.

When the script has run, and the drive is not visible, are you still able to call the same executables manually from "run" ?

Share this post


Link to post
Share on other sites

#7 ·  Posted

6 minutes ago, david1337 said:

Okay, very weird that it is able to call executables directly from the mapped drive, when the drive is not visible.

When the script has run, and the drive is not visible, are you still able to call the same executables manually from "run" ?

Good idea, just tested that. I am unable to run anything by trying to access the N:\ drive via windows explorer and also tried through the Run prompt and Command Prompt. This time the script reported this drive map error, 'The device is already assigned', and still executed both msi and exe files from N:\. The files aren't located elsewhere unless it's somehow calling from a temp folder I'm not aware of. I feel that I'm reaching some limit and thinking of trying the other route of just calling cmd to run a batch command instead. I forgot to mention, I don't know if it's related with running on Windows 10 or not.

Share this post


Link to post
Share on other sites

#8 ·  Posted

Okay, I think we need more of the source code to tell what is going on.

You can post it if you don't find another solution.

Share this post


Link to post
Share on other sites

#9 ·  Posted

On 4/4/2017 at 7:25 AM, david1337 said:

Okay, I think we need more of the source code to tell what is going on.

You can post it if you don't find another solution.

Well, I tried using the other method of just calling command prompt and executing the NET USE commands. This is really weird to me because they do the EXACT same thing as the Autoit functions. I setup Stdoutread for both commands:

NET USE N: /Delete - Actually comes back saying "N: was deleted successfully." when the share doesnt event exist in the first place. Manually testing in Command Prompt gives me the expected results saying "The network connection could not be found."

NET USE N: \\10.0.0.16\RNAPGM /P:Yes - Always says "The command completed successfully.", but checking Command Prompt manually will show "New connections will be remembered." because it's not actually mapped. Manually doing this works perfectly fine though and I'm able to access the mapped drive just fine.

Here's the code, the function I'm trying to fix is _StepSeven(), I have a while loop to pause it right after it runs the step for testing.
 

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Control.ico
#AutoIt3Wrapper_Outfile=AutoHelix.Exe
#AutoIt3Wrapper_Outfile_x64=AutoHelix_x64.Exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <StringConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Date.au3>

Global $stepArray[] = ["PC Name", "PC Serial", "Enable RDP", "Disable ACL", "Disable Firewall", "Environment Variables", "Regional Format", "Map N Drive", "Create Shortcuts", "Install Crystal Reports", "Install MS Components", "Install Oracle", "Net Manager", "Get Colors ID"]
Global $installStep[UBound($stepArray)]
Global $x, $sID, $stepStatus = Null
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error","ErrorHandle")

#Region ### START Koda GUI section ### Form=C:\Users\Admin\Desktop\AutoHelix\Helix Auto-Installer.kxf
$Form = GUICreate("AutoHelix", 459, 500, -1, -1)

GUICtrlCreateGroup("Setup Information", 8, 0, 441, 113)
GUICtrlCreateLabel("Pharmacy", 24, 26, 51, 17)
$pharmacyName = GUICtrlCreateInput("", 80, 24, 137, 21)
GUICtrlCreateLabel("PC Name/IP", 24, 58, 64, 17)
$pcNameIP = GUICtrlCreateInput("", 96, 56, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
GUICtrlCreateLabel("Server Name", 248, 26, 66, 17)
$serverName = GUICtrlCreateInput("", 317, 24, 121, 21)
GUICtrlCreateLabel("Serial Number", 248, 58, 70, 17)
$serialNumber = GUICtrlCreateInput("", 320, 56, 118, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
GUICtrlCreateLabel("OnTime Ticket #", 16, 86, 84, 17)
$ticketNumber = GUICtrlCreateInput("", 104, 84, 113, 21)
$newInstall = GUICtrlCreateRadio("New Install", 248, 86, 81, 17)
$newReplacement = GUICtrlCreateRadio("Replacement", 352, 86, 89, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Installation Steps", 8, 120, 233, 377)
Local $fromTop = 135
For $x = 0 To UBound($stepArray) - 1
    $installStep[$x] = GUICtrlCreateLabel("O", 24, $fromTop, 16, 20)
    GUICtrlSetFont(-1, 12, 800, 0, "Symbol")
    GUICtrlSetColor(-1, 0xFF8C00);Red FF0000 | Green 008000 | Orange FF8C00
    GUICtrlCreateLabel($stepArray[$x], 48, $fromTop, 175, 20)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $fromTop += 26
Next
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Control", 248, 120, 201, 137)
$startButton = GUICtrlCreateButton("Start", 264, 144, 75, 25)
$pauseButton = GUICtrlCreateButton("Pause", 264, 176, 75, 25)
$stopButton = GUICtrlCreateButton("Stop", 264, 208, 75, 25)
$helpButton = GUICtrlCreateButton("Help", 352, 160, 75, 25)
$exitButton = GUICtrlCreateButton("Exit", 352, 192, 75, 25)
GUICtrlSetState($pauseButton, $GUI_DISABLE)
GUICtrlSetState($stopButton, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Console", 248, 264, 201, 233)
$Console = GUICtrlCreateEdit("", 256, 280, 185, 210, BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exitButton
            Exit
        Case $startButton
            ;Check for filled input boxes before running
            $getPharmacy = GUICtrlRead($pharmacyName)
            $getServer = GUICtrlRead($serverName)
            $getTicket = GUICtrlRead($ticketNumber)
            $getNewInstall = GUICtrlRead($newInstall) ;$GUI_CHECKED or $GUI_UNCHECKED
            $getReplacement = GUICtrlRead($newReplacement) ;$GUI_CHECKED or $GUI_UNCHECKED
            If $getPharmacy = "" Then
                MsgBox(16, "Error!", "Pharmacy name is empty!")
                ContinueCase
            EndIf
            If $getServer = "" Then
                MsgBox(16, "Error!", "Server name or IP is empty!")
                ContinueCase
            EndIf
            If $getTicket = "" Then
                MsgBox(16, "Error!", "A ticket number is required to run!")
                ContinueCase
            EndIf
            If $getNewInstall = $GUI_UNCHECKED And $getReplacement = $GUI_UNCHECKED Then
                MsgBox(16, "Error!", "Must choose if this workstation is a Replacement or New Install!")
                ContinueCase
            EndIf
            If $getNewInstall = $GUI_CHECKED Then
                $installType = "New Install"
            ElseIf $getReplacement = $GUI_CHECKED Then
                $installType = "Replacement"
            EndIf

            ;Disable/Enable GUI buttons
            GUICtrlSetState($startButton, $GUI_DISABLE)
            GUICtrlSetState($pauseButton, $GUI_ENABLE)
            GUICtrlSetState($stopButton, $GUI_ENABLE)
            GUICtrlSetState($pharmacyName, $GUI_DISABLE)
            GUICtrlSetState($serverName, $GUI_DISABLE)
            GUICtrlSetState($ticketNumber, $GUI_DISABLE)
            GUICtrlSetState($newInstall, $GUI_DISABLE)
            GUICtrlSetState($newReplacement, $GUI_DISABLE)

            ;Get information from Requested By and Completed By
            $getRequestedBy = InputBox("AutoHelix", "Requested By?", GUICtrlRead($pharmacyName))
            If @error Or $getRequestedBy = "" Then
                MsgBox(16, "Error!", "This cannot be blank! Please fill in who requested the workstation install.")
                ContinueCase
            EndIf
            $getCompletedBy = InputBox("AutoHelix", "Completed By?", "")
            If @error Or $getCompletedBy = "" Then
                MsgBox(16, "Error!", "This cannot be blank! Please fill in who is completing the install.")
                ContinueCase
            EndIf

            ;Start log file
            $logFile = FileOpen("Log.txt", 2)

            ;Start timer
            $iTimer = TimerInit()

            $stepCounter = 0;Start first step
            GUICtrlSetData($Console, GUICtrlRead($Console) & "Running AutoHelix..." & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] Running AutoHelix..." & @CRLF)
            For $x = 0 To 13 ;Run installer
                $nMsg = GUIGetMsg()
                If $nMsg = $pauseButton Then
                    _PauseScript()
                ElseIf $nMsg = $stopButton Then
                    GUICtrlSetData($Console, GUICtrlRead($Console) & "AutoHelix Stopped by User!" & @CRLF)
                    FileWrite($logFile, "[" & _TimeStamp() & "] AutoHelix Stopped by User!" & @CRLF)
                    FileClose($logFile)
                    ExitLoop
                EndIf
                Switch $x
                    Case 0
                        $stepStatus = _StepZero() ;Get PC Name
                    Case 1
                        $stepStatus = _StepOne() ;Get PC Serial
                    Case 2
                        $stepStatus = _StepTwo() ;Enable RDP
                    Case 3
                        $stepStatus = _StepThree() ;Disable UAC/ACL
                    Case 4
                        $stepStatus = _StepFour() ;Disable Firewall
                    Case 5
                        $stepStatus = _StepFive() ;Set Environment Variables
                    Case 6
                        $stepStatus = _StepSix() ;Set Regional Format
                    Case 7
                        $stepStatus = _StepSeven() ;Map N Drive
                    Case 8
                        $stepStatus = _StepEight() ;Create Shortcuts
                    Case 9
                        $stepStatus = _StepNine() ;Install Crystal Reports
                    Case 10
                        $stepStatus = _StepTen() ;Install MS Components
                    Case 11
                        $stepStatus = _StepEleven() ;Install Oracle
                    Case 12
                        $stepStatus = _StepTwelve() ;Configure Net Manager
                    Case 13
                        $stepStatus = _StepThirteen() ;Create Colors File
                EndSwitch
                If $stepStatus = True Then
                    GUICtrlSetData($installStep[$x], Chr(214));Check Symbol
                    GUICtrlSetColor($installStep[$x], 0x008000);Green
                ElseIf $stepStatus = False Then
                    GUICtrlSetData($installStep[$x], Chr(67));X Symbol
                    GUICtrlSetColor($installStep[$x], 0xFF0000);Red
                EndIf
                Sleep(150)
            Next
            ;Finish installation and calculate timer difference
            GUICtrlSetData($Console, GUICtrlRead($Console) & "AutoHelix Install Complete" & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] AutoHelix Install Complete" & @CRLF)
            $iDiff = TimerDiff($iTimer)
            $timeSpent = _Diff2Time($iDiff)
            If $timeSpent[0] = 0 And $timeSpent[1] < 30 Then
                $finalTime = "30 Minutes"
            ElseIf $timeSpent[0] = 0 And $timeSpent[1] > 30 Then
                $finalTime = $timeSpent[1] & " Minutes"
            ElseIf $timeSpent[0] > 0 Then
                $finalTime = $timeSpent[0] & " Hours and " & $timeSpent[1] & " Minutes"
            EndIf

            ;Reset GUI controls
            GUICtrlSetState($startButton, $GUI_ENABLE)
            GUICtrlSetState($pauseButton, $GUI_DISABLE)
            GUICtrlSetState($stopButton, $GUI_DISABLE)
            GUICtrlSetState($pharmacyName, $GUI_ENABLE)
            GUICtrlSetState($serverName, $GUI_ENABLE)
            GUICtrlSetState($ticketNumber, $GUI_ENABLE)
            GUICtrlSetState($newInstall, $GUI_ENABLE)
            GUICtrlSetState($newReplacement, $GUI_ENABLE)

            ;Write completed form
            $Workstation = FileOpen("Workstation.txt", 2)
            FileWrite($Workstation, "Pharmacy: " & $getPharmacy & @CRLF)
            FileWrite($Workstation, "----------------------" & @CRLF)
            FileWrite($Workstation, "Server: " & $getServer & @CRLF)
            FileWrite($Workstation, "Workstation: " & GUICtrlRead($pcNameIP) & @CRLF)
            FileWrite($Workstation, "Serial: " & GUICtrlRead($serialNumber) & @CRLF)
            FileWrite($Workstation, "Ticket: " & $getTicket & @CRLF)
            FileWrite($Workstation, "Type: " & $installType & @CRLF)
            FileWrite($Workstation, "" & @CRLF)
            FileWrite($Workstation, "Requested By: " & $getRequestedBy & @CRLF)
            FileWrite($Workstation, "Completed By: " & $getCompletedBy & @CRLF)
            FileWrite($Workstation, "Time Spent: " & $finalTime & @CRLF)
            FileWrite($Workstation, "Station ID: " & $sID & @CRLF)
            FileWrite($Workstation, "----------------------" & @CRLF)
            FileClose($Workstation)

            ;Email completed form to helixinstaller@rnahealth.com
            ;_INetSmtpMailCom("smtp.gmail.com", "helixinstaller@gmail.com", "helixinstaller@gmail.com", "helixinstaller@rnahealth.com", "Workstation Install", "File attached.", "Workstation.txt", "", "", "High", "helixinstaller@gmail.com", "RN@@dmin", 465, 1)

            ;Close out log file
            FileClose($logFile)

        Case $pauseButton
            ContinueLoop
        Case $stopButton
            ContinueLoop
        Case $helpButton
            MsgBox(64, "About", "AutoHelix v1.0" & @CRLF & _
                                "By Dale Stewart" & @CRLF & _
                                "Mobile Medsoft LLC" & @CRLF & _
                                "" & @CRLF & _
                                "How to Use:" & @CRLF & _
                                "1. Input Pharmacy Name, Server IP or Name, and Ticket Number" & @CRLF & _
                                "2. Input if New Install or Replacement" & @CRLF & _
                                "3. Click Start button to run")
    EndSwitch
WEnd

Func _StepZero()
    GUICtrlSetData($pcNameIP, @ComputerName)
    Return True
EndFunc

Func _StepOne()
    $getSerial = Run(@ComSpec & " /c " & 'wmic bios get serialnumber', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($getSerial)
    $readSerial = StdoutRead($getSerial)
    $writeSerial = StringSplit(StringStripWS(StringStripCR($readSerial), 8), "SerialNumber")
    GUICtrlSetData($serialNumber, $writeSerial[13])
    Return True
EndFunc

Func _StepTwo()
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server", "fDenyTSConnections", "REG_DWORD", 0)
    If @error Then
        Switch @error
            Case 1
                $message = "unable to open requested key"
            Case 2
                $message = "unable to open requested main key"
            Case 3
                $message = "unable to remote connect to the registry"
            Case -1
                $message = "unable to open requested value"
            Case -2
                $message = "value type not supported"
        EndSwitch
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Enable RDP Error: " & $message & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Enable RDP Error: " & $message & @CRLF)
        Return False
    Else
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Enable RDP Complete" & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Enable RDP Complete" & @CRLF)
        Return True
    EndIf
EndFunc

Func _StepThree()
    _Toggle_UAC(0)
    Switch @error
        Case 0
            GUICtrlSetData($Console, GUICtrlRead($Console) & "Disable UAC Complete" & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] Disable UAC Complete" & @CRLF)
            Return True
        Case 1
            $message = "Current user is not Admin"
        Case 2
            $message = "OS is not Vista or Win 7"
        Case 3
            $message = "Reading the the registry key failed"
        Case 4
            $message = "Writing the registry keyname value failed"
        Case 5
            $message = "$iValue parameter not valid"
    EndSwitch
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Enable UAC Error: " & $message & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] Enable UAC Error: " & $message & @CRLF)
    Return False
EndFunc

Func _StepFour()
    Local $aReg[] = ["DomainProfile", "StandardProfile", "PublicProfile"]
    For $z = 0 to 2
        $Key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\" & $aReg[$z]
        RegWrite($Key, "EnableFirewall", "REG_DWORD", 0)
        If @error Then
            Switch @error
                Case 1
                    $message = "unable to open requested key"
                Case 2
                    $message = "unable to open requested main key"
                Case 3
                    $message = "unable to remote connect to the registry"
                Case -1
                    $message = "unable to open requested value"
                Case -2
                    $message = "value type not supported"
            EndSwitch
            GUICtrlSetData($Console, GUICtrlRead($Console) & "Firewall Error: " & $message & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] Firewall Error: " & $message & @CRLF)
            Return False
        EndIf
    Next
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Disable Firewall Complete" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] Disable Firewall Complete" & @CRLF)
    Return True
EndFunc

Func _StepFive()
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "RNAPGM", "REG_SZ", "N:\")
    If @error Then
        Switch @error
            Case 1
                $message = "unable to open requested key"
            Case 2
                $message = "unable to open requested main key"
            Case 3
                $message = "unable to remote connect to the registry"
            Case -1
                $message = "unable to open requested value"
            Case -2
                $message = "value type not supported"
        EndSwitch
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Set EnvVar Error: " & $message & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Set EnvVar Error: " & $message & @CRLF)
        Return False
    Else
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Set EnvVar Complete" & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Set EnvVar Complete" & @CRLF)
        Return True
    EndIf
EndFunc

Func _StepSix()
    Local $aReg[] = ["HKEY_CURRENT_USER\Control Panel\International", "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\CommonGlobUserSettings\Control Panel\International"]
    For $z = 0 to 1
        RegWrite($aReg[$z], "sShortDate", "REG_SZ", "MM\dd\yyyy")
        If @error Then
            Switch @error
                Case 1
                    $message = "unable to open requested key"
                Case 2
                    $message = "unable to open requested main key"
                Case 3
                    $message = "unable to remote connect to the registry"
                Case -1
                    $message = "unable to open requested value"
                Case -2
                    $message = "value type not supported"
            EndSwitch
            GUICtrlSetData($Console, GUICtrlRead($Console) & "Set Regional Error: " & $message & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] Set Regional Error: " & $message & @CRLF)
            Return False
        EndIf
    Next
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Set Regional Complete" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] Set Regional Complete" & @CRLF)
    Return True
EndFunc

Func _StepSeven()
    $remoteShare = "\\" & GUICtrlRead($serverName) & "\RNAPGM"
    $remoteShare = String($remoteShare)
    $Map = Run(@ComSpec & " /c " & "NET USE N: /Delete", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($Map)
    $read = StdoutRead($Map)
    ConsoleWrite($read & @CRLF)
    ;ConsoleWrite(String("NET USE N: " & $remoteShare & " /P:Yes") & @CRLF)

    ;$Map = Run(@ComSpec & " /c " & String("NET USE N: " & $remoteShare & " /P:Yes"), "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    $Map = Run(@ComSpec & " /c " & String("NET USE N: \\10.0.0.16\RNAPGM /P:Yes"), "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($Map)
    $read = StdoutRead($Map)
    ConsoleWrite($read & @CRLF)
    While 1
        ;
    WEnd
    Exit






    If @error Then
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Drive Map Error: Unable to map drive" & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Drive Map Error: Unable to map drive" & @CRLF)
        Return False
    EndIf
    ;DriveMapDel("N:")
    ;DriveMapAdd("N:", $remoteShare, 8)
    ;If @error Then
    ;   Switch @error
    ;       Case 1
    ;           $message = "Undefined / Other error"
    ;       Case 2
    ;           $message = "Access to the remote share was denied"
    ;       Case 3
    ;           $message = "The device is already assigned"
    ;       Case 4
    ;           $message = "Invalid device name"
    ;       Case 5
    ;           $message = "Invalid remote share"
    ;       Case 6
    ;           $message = "Invalid password"
    ;   EndSwitch
    ;   GUICtrlSetData($Console, GUICtrlRead($Console) & "Drive Map Error: " & $message & @CRLF)
    ;   FileWrite($logFile, "[" & _TimeStamp() & "] Drive Map Error: " & $message & @CRLF)
    ;   Return False
    ;EndIf
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Drive Map Complete" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] Drive Map Complete" & @CRLF)
    Return True
EndFunc

Func _StepEight()
    $shortcut1Status = FileCreateShortcut("N:\RNA\Helix.exe", @DesktopDir & "\Helix.lnk");Success 1 | Failure 0
    $shortcut2Status = FileCreateShortcut("N:\RNA\HelixImaging.exe", @DesktopDir & "\Helix Imaging.lnk")
    If $shortcut1Status = 0 Then
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Shortcut Error: Helix Denied" & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Shortcut Error: Helix Denied" & @CRLF)
        Return False
    EndIf
    If $shortcut2Status = 0 Then
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Shortcut Error: Imaging Denied" & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Shortcut Error: Imaging Denied" & @CRLF)
        Return False
    EndIf
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Shortcuts Complete" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] Shortcuts Complete" & @CRLF)
    Return True
EndFunc

Func _StepNine()
    Local $pID = RunWait(@ScriptDir & "\CRXIRuntimesetup.msi")
    ProcessWaitClose($pID)
    GUICtrlSetData($Console, GUICtrlRead($Console) & "Crystal Reports Complete" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] Crystal Reports Complete" & @CRLF)
    Return True
EndFunc

Func _StepTen()
    Local $pID = RunWait(@ScriptDir & "\vcredist_x86.exe")
    ProcessWaitClose($pID)
    GUICtrlSetData($Console, GUICtrlRead($Console) & "MS VisualCom Complete" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] MS VisualCom Complete" & @CRLF)
    Return True
EndFunc

Func _StepEleven()
    Run(@ScriptDir & "\Disk1\setup.exe")
    While 1
        $Handle = WinWaitActive("Oracle Universal Installer: End of Installation", "", 600)
        If $Handle > 0 Then
            $pID = WinGetProcess($Handle)
            ProcessClose($pID)
            GUICtrlSetData($Console, GUICtrlRead($Console) & "Oracle 10g Complete" & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] Oracle 10g Complete" & @CRLF)
            Return True
        Else
            GUICtrlSetData($Console, GUICtrlRead($Console) & "Oracle 10g Error: Timeout" & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] Oracle 10g Error: Timeout" & @CRLF)
            Return False
        EndIf
    WEnd
EndFunc

Func _StepTwelve()
    $oFile = _FileCreate("C:\oracle\product\10.2.0\client_1\network\ADMIN\tnsnames.ora")
    If @error Then
        Switch  @error
            Case 1
                $message = "Error opening specified file"
            Case 2
                $message = "File could not be written to"
        EndSwitch
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Net Manager Error: " & $message & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Net Manager Error: " & $message & @CRLF)
        Return False
    Else
        $tnsNames = FileOpen("C:\oracle\product\10.2.0\client_1\network\ADMIN\tnsnames.ora", 2)
        FileWrite($tnsNames, "RNA1 =" & @CRLF)
        FileWrite($tnsNames, "  (DESCRIPTION =" & @CRLF)
        FileWrite($tnsNames, "    (ADDRESS_LIST =" & @CRLF)
        FileWrite($tnsNames, "      (ADDRESS = (PROTOCOL = TCP)(HOST = " & GUICtrlRead($serverName) & ")(PORT = 1521))" & @CRLF)
        FileWrite($tnsNames, "    )" & @CRLF)
        FileWrite($tnsNames, "    (CONNECT_DATA =" & @CRLF)
        FileWrite($tnsNames, "      (SERVICE_NAME = RNA1)" & @CRLF)
        FileWrite($tnsNames, "    )" & @CRLF)
        FileWrite($tnsNames, "  )" & @CRLF)
        FileWrite($tnsNames, "" & @CRLF)
        FileClose($tnsNames)
        GUICtrlSetData($Console, GUICtrlRead($Console) & "Net Manager Complete" & @CRLF)
        FileWrite($logFile, "[" & _TimeStamp() & "] Net Manager Complete" & @CRLF)
        Return True
    EndIf
EndFunc

Func _StepThirteen()
    Local $pID= Run(@ComSpec & " /c " & 'echo exit | sqlplus -s RNAPGM/RNA_RNA_202@RNA1 "@' & @ScriptDir & '\IDS.sql"', "", @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($pID)
    $Output = StdoutRead($pID)
    $aString = StringSplit($Output, @CRLF, $STR_ENTIRESPLIT) ;Create array with sql output for station ids/dateused/lastuser
    For $x = UBound($aString) - 1 To 0 Step -1 ;Find array string with 'selected' and calculate next available ID
        $Check = StringInStr($aString[$x], "selected")
        If $Check > 0 Then
            $LastID = $aString[$x - 2]
            ExitLoop
        EndIf
    Next
    $Result = Int($LastID + 1)
    MsgBox(0, "Station ID", $Result)
    $sID = $Result
    Return True
EndFunc

Func _PauseScript()
    GUICtrlSetData($Console, GUICtrlRead($Console) & "*Paused*" & @CRLF)
    FileWrite($logFile, "[" & _TimeStamp() & "] *Paused*" & @CRLF)
    GUICtrlSetState($startButton, $GUI_ENABLE)
    GUICtrlSetState($pauseButton, $GUI_DISABLE)
    While 1
        $pMsg = GUIGetMsg()
        If $pMsg = $startButton Then
            GUICtrlSetState($startButton, $GUI_DISABLE)
            GUICtrlSetState($pauseButton, $GUI_ENABLE)
            GUICtrlSetData($Console, GUICtrlRead($Console) & "*Resumed*" & @CRLF)
            FileWrite($logFile, "[" & _TimeStamp() & "] *Resumed*" & @CRLF)
            ExitLoop
        EndIf
    WEnd
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _Toggle_UAC
; Description ...: Toggle or Force UAC Off or On or Query UAC current setting without changing.
; Syntax.........: _Toggle_UAC([$iValue = -2])
; Parameters ....: $iValue - [Optional] Default is -2, see below for explanations and other values.
;                           -1 = Toggle the current UAC to the oposite of what it is currently.
;                                If UAC is curently disabled then It will be enabled using 1,
;                                Prompt the Consent Admin to enter his or her user name and password
;                                (or another valid admin) when an operation requires elevation of privilege.
;                           -2 = Toggle the current UAC to the oposite of what it is currently.
;                                If UAC is curently disabled then It will be enabled using 2,
;                                Admin Approval Mode to select either "Permit" or "Deny" an operation that requires elevation of privilege.
;                           -3 = Return the current UAC value found in the registry, don't change anything.
;                           0  = Set UAC to 0 Allow the Consent Admin to perform an operation that requires elevation without consent or credentials.
;                           1  = Set UAC to 1 Prompt the Consent Admin to enter his or her user name and password
;                                (or another valid admin) when an operation requires elevation of privilege.
;                           2  = Set UAC to 2 Admin Approval Mode to select either "Permit" or "Deny" an operation that requires elevation of privilege.
; Return values .: Success - Value that was found in the registry before changinging and @error 0, Return could be as follows:
;                           0 = UAC was disabled
;                           1 = UAC was Prompt the Consent Admin to enter his or her user name and password
;                           2 = UAC was Admin Approval Mode to select either "Permit" or "Deny"
;                 Failure - -1 and @error
;                           @error 1 = Current user is not Admin
;                           @error 2 = OS is not Vista or Win 7
;                           @error 3 = Reading the the registry key failed, check @extended for the returned error from RegRead() as to why it failed.
;                           @error 4 = Writing the registry keyname value failed, check @extended for the returned error from RegWrite() as to why it failed.
;                           @error 5 = $iValue parameter not valid
; Author ........: AlienStar
; Modified.......: smashly
; Remarks .......:
; Related .......:
; Link ..........: http://msdn.microsoft.com/en-us/library/cc232761%28v=prot.10%29.aspx
; Example .......:
; ===============================================================================================================================
#cs
Returns one of the following: "WIN_10", "WIN_81", "WIN_8", "WIN_7", "WIN_VISTA", "WIN_XP", "WIN_XPe",
    for Windows servers: "WIN_2016", "WIN_2012R2", "WIN_2012", "WIN_2008R2", "WIN_2008", "WIN_2003"".
#ce
Func _Toggle_UAC($iValue = -2)

    If Not IsAdmin() Then Return SetError(1, 0, -1)
    If Not StringInStr("WIN_VISTA|WIN_7|WIN_8|WIN_81|WIN_10", @OSVersion) Then Return SetError(2, 0, -1)

    Local $sHKLM, $sName, $iReadValue, $iNewValue
    $sHKLM = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
    $sName = "ConsentPromptBehaviorAdmin"
    $iReadValue = RegRead($sHKLM, $sName)
    If @error Then Return SetError(3, @error, -1)

    Switch $iValue
        Case -1, -2
            Switch $iReadValue
                Case 0
                    $iNewValue = Abs($iValue)
                Case Else
                    $iNewValue = 0
            EndSwitch
        Case -3
            Return SetError(0, 0, $iReadValue)
        Case 0, 1, 2
            $iNewValue = $iValue
        Case Else
            Return SetError(5, 0, -1)
    EndSwitch

    RegWrite($sHKLM, $sName, "REG_DWORD", $iNewValue)
    If @error Then Return SetError(4, @error, -1)
    Return SetError(0, 0, $iReadValue)
EndFunc   ;==>_Toggle_UAC

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF);### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    $objEmail.Configuration.Fields.Update
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom

Func ErrorHandle()
    Local $HexNumber
    Local $strMsg
    $HexNumber = Hex($oMyError.Number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    $strMsg = "Error Number: " & $HexNumber & @CRLF
    $strMsg &= "WinDescription: " & $oMyError.WinDescription & @CRLF
    $strMsg &= "Script Line: " & $oMyError.ScriptLine & @CRLF
    MsgBox(48, "### COM Error !", "Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1])
    SetError(1)
    Exit
Endfunc   ;==>ErrorHandle

Func _Diff2Time($TimerDiff)
    Dim $HMS[3]
    $HMS[2] = Int($TimerDiff / 1000)
    $HMS[1] = $HMS[2] - Mod($HMS[2], 60)
    $HMS[2] -= $HMS[1]
    $HMS[1] /= 60
    $HMS[0] = $HMS[1] - Mod($HMS[1], 60)
    $HMS[1] -= $HMS[0]
    $HMS[0] /= 60
    Return $HMS
EndFunc; _Diff2Time

Func _TimeStamp()
    $tCur = _Date_Time_GetLocalTime()
    $tSplit = StringSplit(_Date_Time_SystemTimeToDateTimeStr($tCur), " ", 2)
    Return $tSplit[1]
EndFunc

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

For those who are curious, I found my solution from this article:

http://woshub.com/how-to-access-mapped-network-drives-from-the-elevated-apps/

I discovered from testing that the script would not map the network drive with #RequireAdmin line in the code. Using the article above I added the missing registry key and rebooted. All testing after that worked 100% with and without #RequireAdmin.

2 people like this

Share this post


Link to post
Share on other sites

#11 ·  Posted

Good find.  I've always worked around this issue, but it is useful to know that Windows has a "feature" to address it.  My computer security mindset is a little twitchy, but I think I'd be mostly concerned about mapping a drive with elevated perms and accessing it with a non-elevated account versus the other way around.   Thanks for sharing.

1 person likes this

Share this post


Link to post
Share on other sites
On 4/6/2017 at 7:42 AM, Echbiahn said:

For those who are curious, I found my solution from this article:

http://woshub.com/how-to-access-mapped-network-drives-from-the-elevated-apps/

I discovered from testing that the script would not map the network drive with #RequireAdmin line in the code. Using the article above I added the missing registry key and rebooted. All testing after that worked 100% with and without #RequireAdmin.

Great find. I had basically the same issue for the last 2 weeks, drove me nuts. After finding this post my problem was resolved. Thanks for the post.

~GD

Share this post


Link to post
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