Jump to content
ModemJunki

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

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!

Share this post


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


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

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

  • Similar Content

    • By kingjacob90
      Hay guys
      Just had an idea and wanted to know where to start. I want to download a screenshot of a website automatically into a .png .jpg ect format so I can then set it as my desktop background.
      This might be for for news: When the latest news is added to a website a screenshot of that website is saved and added to my desktop background.
      I have tried using website that already do the screenshot but you have to open the website and click the button for it to generate one and thus InetGet does not help.
      Any Ideas?
    • By mdwerne
      I'm attempting to cobble together a replacement for the 64bit version of BGInfo that will run within WinPE 10/64. I've located a couple useful threads:
       Between the two, they get me close (see code below), but for some reason GDI+ is not working the same within WinPE as it does in Windows 10. Bottomline is that the "Text" never get's written to WallPaper.
      Here is what I have thus far. Any thoughts if any of the GDI commands might not work within WinPE? Any other way to achieve the same result (system information on the wallpaper in WinPE 10)?
      #include <GDIPlus.au3> #include <Date.au3> _GDIPlus_Startup() $image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\WallPaper.bmp") $imagegraphics = _GDIPlus_ImageGetGraphicsContext($image) $w = _GDIPlus_ImageGetWidth($image) $h = _GDIPlus_ImageGetHeight($image) $whitebrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $fontfamily = _GDIPlus_FontFamilyCreate("Arial") $font = _GDIPlus_FontCreate($fontfamily, 16) $stringformat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($stringformat, 2) $rect = _GDIPlus_RectFCreate(0, $h - $h + 100, $w - 25, $h) ;$rect = _GDIPlus_RectFCreate(100, 100, 200, 200) _GDIPlus_GraphicsDrawStringEx($imagegraphics, _Now() & @CRLF & @UserName & @CRLF & @ComputerName & @CRLF & @IPAddress1, $font, $rect, $stringformat, $whitebrush) _GDIPlus_ImageSaveToFile($image, @ScriptDir & "\NewWallPaper.bmp") _GDIPlus_ImageDispose($image) _GDIPlus_GraphicsDispose($imagegraphics) _GDIPlus_BrushDispose($whitebrush) _GDIPlus_FontFamilyDispose($fontfamily) _GDIPlus_FontDispose($font) _GDIPlus_StringFormatDispose($stringformat) _GDIPlus_Shutdown() _ChangeDesktopWallpaper(@ScriptDir & "\NewWallPaper.bmp", 2) Func _ChangeDesktopWallpaper($bmp, $style = 0) ;=============================================================================== ; ; Function Name: _ChangeDesktopWallPaper ; Description: Update WallPaper Settings ; Usage: _ChangeDesktopWallPaper(@WindowsDir & '\' & 'zapotec.bmp',1) ; Parameter(s): $bmp - Full Path to BitMap File (*.bmp) ; [$style] - 0 = Centered, 1 = Tiled, 2 = Stretched ; Requirement(s): None. ; Return Value(s): On Success - Returns 0 ; On Failure - -1 ; Author(s): FlyingBoz ; Thanks: Larry - DllCall Example - Tested and Working under XPHome and W2K Pro ; Excalibur - Reawakening my interest in Getting This done. ; ;=============================================================================== If Not FileExists($bmp) Then Return -1 ;The $SPI* values could be defined elsewhere via #include - if you conflict, ; remove these, or add if Not IsDeclared "SPI_SETDESKWALLPAPER" Logic Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 Local $REG_DESKTOP = "HKEY_CURRENT_USER\Control Panel\Desktop" If $style = 1 Then RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 1) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0) Else RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 0) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", $style) EndIf DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", $bmp, _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) Return 0 EndFunc ;==>_ChangeDesktopWallpaper Thanks for your time,
      -Mike
    • By Rizonetech
      I've learned so much from the AutoIt community and figured it is about time I start giving something back. I am open sourcing all my software and Complete Internet Repair is the first program I am releasing.
      Complete Internet Repair will give you a free option to attempt to repair everything internet related.
      With any repair utility, you will need to remember only two golden rules. Firstly; don't try to repair something that is not broken, you might break it. Secondly; Comnplete Internet Repair cannot repair it all, we are not like the all-seeing and all-knowing Oracle, we cannot anticipate each and every situation, but this all said; it should be able to help with most internet issues. Complete Internet Repair could help if you are experiencing any of the following problems:
      Internet or network problem after removing adware, spyware, virus, worm, Trojan horse, etc. Loss network connection after installing/uninstalling adware, spyware, antispam, vpn, firewall or other networking programs. Unable to access any website or can only access some websites. Pop-up error window with network related problem description. No network connectivity due to registry errors. DNS lookup problem. Fail to renew the network adapter’s IP address or other DHCP errors. Network connectivity issue with limited or no connections message. Windows update does not work. You are having problems connecting to secured websites (ex. Banking). Internet Explorer stopped working or crashes all the time. A few other internet errors, but we will not discuss all here. Update 22 October 2016
      Exes are now signed. New installation utility. Now built on the ReBar Framework. New Update Notification System. Resources moved to external Dll files. Added support for Windows 10. New Interface. New Logging System. New Reset Rroxy Server Configuration. New Registry based Method for configuring Services. Cleaner Optimized Code. You can download Complete Internet Repair 3 and Source Code at: http://www.rizonesoft.com/downloads/complete-internet-repair/ The source code can be viewed on GitHub here. Please while you're there, give it a Star!

      Please let me know what you think and if you have any suggestions, I would love to hear about it.
    • By pupitetris
      Hi. I just released this software, we need it to override the DHCP server at work. Our DHCP server does not allow per-mac-address configuration, so I coded this utility to allow our developers to use our area's custom DNS server, regardless of what DHCP provides, and let them have the possibiity to quickly shift to automatic configuration when they take their laptops home.

      https://github.com/pupitetris/DNS-Updater
      An afternoon's worth of coding, and another half day for polish and release. Pretty old-school simplicity; it was a good excercise to finally code some UI using AutoIt.
      Hope it's useful to someone.
    • By doestergaard
      In one of my scripts, I needed to know, where Windows was installed at. I know there is several ways to this already, but I was thinking that I would share how I do it using WMI.
      If anyone has any suggestions or comment on the code, feel free to do so.
       
      Code:
      #include <File.au3> Local $STR_DRIVE = GetWindowsDrive() If @error Then MsgBox(@extended, "Result", "Unable to locate Windows", 0) Else MsgBox(@extended, "Result", "Windows is located at: " & $STR_DRIVE, 0) EndIf Exit Func GetWindowsDrive() Local $WMI_GET = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") If Not IsObj($WMI_GET) Then Return SetError(1, 16, 0) Local $WMI_COL_DRIVES = $WMI_GET.ExecQuery("SELECT DeviceID FROM Win32_DiskDrive WHERE MediaType='Fixed hard disk media'") For $WMI_DRIVE In $WMI_COL_DRIVES Local $WMI_COL_PARTITIONS = $WMI_GET.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $WMI_DRIVE.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition") For $WMI_PARTITION In $WMI_COL_PARTITIONS Local $WMI_COL_LOGICALDISKS = $WMI_GET.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $WMI_PARTITION.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") For $WMI_LOGICALDISK In $WMI_COL_LOGICALDISKS If FileExists($WMI_LOGICALDISK.DeviceID & "\Windows\explorer.exe") Then Local $STR_RESULT = $WMI_LOGICALDISK.DeviceID EndIf Next Next Next $WMI_GET = 0 $WMI_COL_DRIVES = 0 $WMI_DRIVE = 0 $WMI_COL_PARTITIONS = 0 $WMI_PARTITION = 0 $WMI_LOGICALDISKS = 0 $WMI_LOGICALDISK = 0 Return SetError(0, 64, $STR_RESULT) EndFunc ; ==>GetWindowsDrive()  
×
×
  • Create New...