Jump to content

Help please: AutoIT mapping network drive in WinPE 10 does not work, but a batch file or command line does!


ModemJunki
 Share

Recommended Posts

Hello,

I solved it - only had to add a sleep for 10 seconds or so to make sure the shell could see the I.P. address change.

I'm working in Windows PE environment (10.0.10586). I think I have some permissions issue related to AutoIT

I've tried with Net Share and with DriveMapAdd - neither work.

So finally I made the script output a batch file with a pause and what I found is that in WinPE, the batch file behaves differently if it's run at the command prompt or if it is spawned by AutoIT.

If spawned by AutoIT, the net use command gives error 1231 "The network location cannot be reached". I assume this is the same problem that DriveMapAdd is having.

But if I run the same batch file under the command shell in the Windows PE instance, it works.

I also made a simple test with Ping() and it always returns 1 (host is offline) but I can ping it from the command line in the same PE session.

Are there service dependencies for this to work? What is preventing AutoIT from accessing the network?

Below sample is kind of dirty but illustrates what I'm doing. Could use a lot more refinement for error checking etc.

;~ #RequireAdmin
#include <Array.au3>
#include <AutoItConstants.au3>

_SetUpPEIP()

Func _SetUpPEIP()
    Local $s_user = "USER"
    Local $s_pass = "PASS"
    Local $s_RMTIP = "10.1.1.4"
    Local $s_RMTSHR = "SHARED_FOLDER"
    Local $s_IPPrefix = "10.1.1."
    Local $s_netMask = "255.255.255.0"
    Local $s_StartIP = 20
    Local $a_NICs[1]
    Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL")

    If IsObj($colItems) Then ; gather network card names
        For $objItem In $colItems
            If $objItem.NetConnectionStatus == "2" Or $objItem.NetConnectionStatus == "9" Then
                _ArrayAdd($a_NICs, $objItem.NetConnectionID)
            EndIf
        Next
    EndIf

    If IsArray($a_NICs) Then ; assign them I.P. addresses
        For $i = 1 To UBound($a_NICs) - 1
            $s_setIP = "netsh interface IP set address name=""" & $a_NICs[$i] & """ static " & $s_IPPrefix & $i + $s_StartIP - 1 & " " & $s_netMask
            $s_ipRes = RunWait(@ComSpec & " /c " & $s_setIP, @ScriptDir, @SW_HIDE) ; expect 0
            Sleep(100)
            ConsoleWrite($s_setIP & " result is:  " & $s_ipRes & @CRLF)
         Next

         Sleep(10000) ; wait for  the shell to catch up and enum the I.P.

        $sres = DriveMapAdd("Z:", "\\" & $s_RMTIP & "\" & $s_RMTSHR, $DMA_PERSISTENT, $s_user, $s_pass)  ; now map a drive
    Else
        ; error! No cards found!
    EndIf
EndFunc   ;==>_SetUpPEIP

 

Edited by ModemJunki
I solved it!

Always carry a towel.

Link to comment
Share on other sites

My prediction:

This is an x64 Winpe and you just need to turn off WOW64fs redirection.

 you can call the dll directly or use the WinAPI udf.

https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_Wow64EnableWow64FsRedirection.htm

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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...