Sign in to follow this  
Followers 0
surreal

array coding question

10 posts in this topic

#1 ·  Posted (edited)

im very new to creating array's. below is the code i have, my attempt to create a txt file to list current mapped drivers. it is not working, any help would be greatly appreciated.

#include <array.au3>

$strComputer = "."

$arrDriveType = _ArrayCreate("Unknown",_
             "No Root Directory",_
             "Removable Disk",_
             "Local Disk",_
             "Network Drive",_
             "Compact Disk",_
             "RAM Disk")

 $WMI = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
 $colDisks = $WMI.ExecQuery("Select * from Win32_LogicalDisk")

For $Disk in $colDisks
    $strType = $arrDriveType($Disk.DriveType)
    $strID = $Disk.DeviceID
    $strSys = $Disk.SystemName

    If $strType = "Network Drive" then
        $strPath = $Disk.ProviderName
        $List = $List & "   " & $strID & @TAB & @TAB & $strPath & @CRLF
    EndIf
Next

$strHeader = "A $List of Mapped Drives" & @CRLF & @CRLF &  _
    "Drive Letter" & @TAB & "Share Path" & @CRLF & _
    "------------------------------------" & @CRLF

Global $List = $strHeader & $List

func_CreateDoc($List)

Func func_CreateDoc($List)
 DirCreate ("C:\Temp\Migrate\Drives")
     $FSO = ObjCreate("Scripting.FileSystemObject")

    $strFolder = "C:\Temp\Migrate\Drives"

    If $FSO.FolderExists($strFolder) = 0 then
        $CLog = $FSO.CreateFolder($strFolder)
    EndIf

    $ShareFile =  $strFolder & "\Drives.txt"

     $LogFile = $FSO.OpenTextFile($ShareFile, 2, 1)
        $LogFile.Write ($List)
    $LogFile.Close()

EndFunc

d@ve

update: thanks you GEOSoft, i dont think DriveGetDrive() will work for me, i need to grab this info from a remote system.

Edited by surreal

Share this post


Link to post
Share on other sites



First off, you don't need that COM object code. See FileWriteLine() and FileWrite()

Now, have you even looked at DriveGetDrive() and DriveMapGet()?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

so i now have mapped drives working thanks to gcue pointing me in the right direction. now using:

http://www.autoitscript.com/forum/index.php?showtopic=75250&st=0&p=545798&#entry545798 to take control of the hkcu hive.

i would like to do the same thing to my get printers array but for some reason cannot get my code working. can someone please help on this one, thank you...

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <HKCUReg.au3>

;===Checks Local OSVersion Create Var User Friendly================================================
$OS = @OSVersion
$OS = StringReplace($OS, "WIN_VISTA", "Windows Vista")
$OS = StringReplace($OS, "WIN_XP", "Windows XP")
$OS = StringReplace($OS, "WIN_2000", "Windows 2000")
;===Determines Documents Location According To OS++================================================
$OSDOC = @OSVersion
If $OSDOC = "WIN_VISTA" Then $DOC = "\Users\"
If $OSDOC = "WIN_XP" Then
    $DOC = "\Documents and Settings\"
EndIf
$OSDF = @OSVersion
If $OSDF = "WIN_VISTA" Then $DF = "Documents"
If $OSDF = "WIN_XP" Then
    $DF = "My Documents"
EndIf
GUICreate("", 330, 145, -1, -1)
;===GUI Network Computer To Tranfer From===========================================================
GUICtrlCreateGroup("System", 10, 10, 190, 75)
GUICtrlCreateLabel("Computer Name:", 20, 25)
$cnTarget = GUICtrlCreateInput(@ComputerName, 20, 40, 120, 20)
$cnMessage = GUICtrlCreateLabel("Enter computer name or ip address", 20, 64, 175, 15)
$cnButton = GUICtrlCreateButton("Connect", 145, 35, 50, 25, $WS_GROUP)
;===GUI Network User Profile=======================================================================
GUICtrlCreateGroup("Profile:", 10, 90, 190, 45)
$prCombo = GUICtrlCreateCombo("", 20, 105, 175, 20)
;===GUI Group What To Migrate======================================================================
GUICtrlCreateGroup("Tranfer", 210, 10, 110, 80)
$BoxMap = GUICtrlCreateCheckbox("Mapped Drives", 220, 25)
$BoxPrinter = GUICtrlCreateCheckbox("Printers", 220, 45)
$BoxWireless = GUICtrlCreateCheckbox("Wireless", 220, 65)
;===GUI Start Function=============================================================================
$StartButton = GUICtrlCreateButton("Start", 230, 100, 65, 30, $WS_GROUP)
GUISetState(@SW_SHOW)
;===Start Of GUIGetMsg=============================================================================
While 1
    $msg = GUIGetMsg()
    Select
;===Case For Exit GUI==============================================================================
        Case $msg = $GUI_EVENT_CLOSE
            $Close = MsgBox(4, "", "Are you sure you want to exit?")
            If $Close = 6 Then
            GUIDelete()
            Exit
        EndIf
;===Case For Connect===============================================================================
        Case $msg = $cnButton
            If GUICtrlRead($cnTarget) = '' Then
                GUICtrlSetData($cnMessage, 'Target machine must be entered')
                GUICtrlSetColor($cnMessage, 0xFF0000)
            ContinueLoop
            EndIf
            Connect()

        Case $msg = $StartButton
            StartButton()
EndSelect
WEnd
;===Function For Remote System InfoBox=============================================================
Func Connect()
        Local $Separator = "------------------------------"
        SplashTextOn("", "Querying Network", 165, 40, -1, -1, 2, "", 9)
        Sleep(1000)
        If Ping(GUICtrlRead($cnTarget)) Then
        $strComputer = GUICtrlRead($cnTarget)
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        SplashOff()
        If Not IsObj($objWMIService) Then
            GUICtrlSetData($cnMessage, 'Failed to connect to system')
            GUICtrlSetColor($cnMessage, 0xFF0000)
            Return
        EndIf
        ;===WMI BIOS
        $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_Bios")
        $message = "System Info for " & $strComputer & @CRLF & $Separator & @CRLF & @CRLF
        For $objItem In $colItems1
            $message &= "Dell Asset Number: " & $objItem.SerialNumber & @CRLF & _
                    "Manufacturer: " & $objItem.Manufacturer & @CRLF & @CRLF
                    Global $surreal = $objItem.SerialNumber
                    Global $RemoteName = $strComputer
        Next
        ;===WMI NETWORK
        $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        For $objItem In $colItems2
            $message &= "IP Address: " & $objItem.IPAddress(0) & @CRLF & _
                    "IP Subnet: " & $objItem.IPSubnet(0) & @CRLF & @CRLF
        Next
        ;===WMI SYSTEM
        $colItems3 = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For $objItem In $colItems3
            $message &= "Model: " & $objItem.Model & @CRLF & _
                    "Computer Name: " & $objItem.Name & @CRLF & _
                    "Last User: " & $objItem.UserName & @CRLF
                    Global $RemoteUser = $objItem.UserName
        Next
        GUICtrlSetData($cnMessage, 'Connected, select user profile')
        GUICtrlSetColor($cnMessage, 0x008000)
        MsgBox(64, "System Information", $message)
    Else
        GUICtrlSetData($cnMessage, 'Target system could not be contacted')
        GUICtrlSetColor($cnMessage, 0xFF0000)
        Return
    EndIf
    Profile()
EndFunc   ;==>Connect
;===Function For Remote Profile Load===============================================================
Func Profile()
    Local $combo_string = ""
    $FolderList = _FileListToArray("\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC, "*", 2)
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users", "Default User", "LocalService", "NetworkService"
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]
                Else
                    $combo_string &= $FolderList[$i] & "|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($prCombo, $combo_string)
EndFunc   ;==>Profile
;===Function For Checkbox Actions==================================================================
Func StartButton()
    ;===Mapped Drives
    If GUICtrlRead($BoxMap) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Drives")
        Mapped()
    EndIf
    ;===Printers
    If GUICtrlRead($BoxPrinter) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Printers")
        SavePrinter()
    EndIf
    ;===Wireless Settings
    If GUICtrlRead($BoxWireless) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Wireless")
    EndIf
    SoundPlay(@WindowsDir & "\media\tada.wav",1)
    $Success = MsgBox(4, "", "Migration Was Successful. Do You Want To Exit?")
    If $Success = 6 Then Exit
EndFunc   ;==>StartButton
;===Function For Save Printer Info File============================================================
Func SavePrinter()
    Local $strSaveLocation
    Local $ptrFile
    Local $arrPrinters = GetPrinters("NETWORK")
    Local $strSaveLocation = 'c:\Temp\Migrate\Printers\Printers.txt'
    If Not @error Then
        $ptrFile = FileOpen($strSaveLocation, 10)
        FileWriteLine($ptrFile, @MON & "/" & @MDAY & "/" & @YEAR & " at " & @HOUR & ":" & @MIN & ":" & @SEC)
        For $i = 1 To $arrPrinters[0]
            FileWriteLine($ptrFile, $arrPrinters[$i])
        Next
        FileClose($ptrFile)
    EndIf
EndFunc   ;==>SavePrinter

;===Function For Get Printers======================================================================
Func GetPrinters($strType)
    Local $intPrinterLimit = 20
    Local $intPrinterCount = 0
    Local $arrPrinters[$intPrinterLimit + 1]
    Local $name = GUICtrlRead($cnTarget)
    Local $strReg

    If @OSType = "WIN32_NT" Then
        Switch $strType
            Case "NETWORK"
                For $i = 1 To $intPrinterLimit
                        $p = _HKCU_EnumKey("\\\" & $name & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
                        $strRegKey = _HKCU_Read("\\\" & $name & "\\" & $p & "Devices")
                        $strReg = RegEnumVal($strRegKey, $i)
                    If @error = -1 Then ExitLoop
                    If StringInStr($strReg, "\\") <> 0 Then
                        $arrPrinters[$intPrinterCount + 1] = $strReg
                        $intPrinterCount += 1
                    EndIf
                Next
        EndSwitch
    EndIf
    $arrPrinters[0] = $intPrinterCount
    Return $arrPrinters
EndFunc   ;==>GetPrinters

;===Function For Mapped Drives=====================================================================
Func Mapped()
    Local $asset = GUICtrlRead($cnTarget)
    Local $mapLocation = 'c:\Temp\Migrate\Drives\Drives.txt'
    $mapFile = FileOpen($mapLocation, 10)
For $i = 1 To 26
            $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
            $iProd = 1
            For $j = 1 To $b[0][0]
                $iProd *= $b[$j][2]
                If $b[$j][2] = 0 Then
                    $path = _HKCU_Read("\\\" & $asset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                    FileWriteLine($mapFile, $b[$j][1] & "," & $path[1][1])
                    EndIf
            Next
            If $iProd <> 0 Then ExitLoop
        Next
    EndFunc
Edited by surreal

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

so i now have mapped drives working thanks to gcue pointing me in the right direction. now using:

http://www.autoitscript.com/forum/index....p?showtopic=75250&view=findpost&p=545798 to take control of the hkcu hive.

i would like to do the same thing to my get printers array but for some reason cannot get my code working. can someone please help on this one, thank you...

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <HKCUReg.au3>

;===Checks Local OSVersion Create Var User Friendly================================================
$OS = @OSVersion
$OS = StringReplace($OS, "WIN_VISTA", "Windows Vista")
$OS = StringReplace($OS, "WIN_XP", "Windows XP")
$OS = StringReplace($OS, "WIN_2000", "Windows 2000")
;===Determines Documents Location According To OS++================================================
$OSDOC = @OSVersion
If $OSDOC = "WIN_VISTA" Then $DOC = "\Users\"
If $OSDOC = "WIN_XP" Then
    $DOC = "\Documents and Settings\"
EndIf
$OSDF = @OSVersion
If $OSDF = "WIN_VISTA" Then $DF = "Documents"
If $OSDF = "WIN_XP" Then
    $DF = "My Documents"
EndIf
GUICreate("", 330, 145, -1, -1)
;===GUI Network Computer To Tranfer From===========================================================
GUICtrlCreateGroup("System", 10, 10, 190, 75)
GUICtrlCreateLabel("Computer Name:", 20, 25)
$cnTarget = GUICtrlCreateInput(@ComputerName, 20, 40, 120, 20)
$cnMessage = GUICtrlCreateLabel("Enter computer name or ip address", 20, 64, 175, 15)
$cnButton = GUICtrlCreateButton("Connect", 145, 35, 50, 25, $WS_GROUP)
;===GUI Network User Profile=======================================================================
GUICtrlCreateGroup("Profile:", 10, 90, 190, 45)
$prCombo = GUICtrlCreateCombo("", 20, 105, 175, 20)
;===GUI Group What To Migrate======================================================================
GUICtrlCreateGroup("Tranfer", 210, 10, 110, 80)
$BoxMap = GUICtrlCreateCheckbox("Mapped Drives", 220, 25)
$BoxPrinter = GUICtrlCreateCheckbox("Printers", 220, 45)
$BoxWireless = GUICtrlCreateCheckbox("Wireless", 220, 65)
;===GUI Start Function=============================================================================
$StartButton = GUICtrlCreateButton("Start", 230, 100, 65, 30, $WS_GROUP)
GUISetState(@SW_SHOW)
;===Start Of GUIGetMsg=============================================================================
While 1
    $msg = GUIGetMsg()
    Select
;===Case For Exit GUI==============================================================================
        Case $msg = $GUI_EVENT_CLOSE
            $Close = MsgBox(4, "", "Are you sure you want to exit?")
            If $Close = 6 Then
            GUIDelete()
            Exit
        EndIf
;===Case For Connect===============================================================================
        Case $msg = $cnButton
            If GUICtrlRead($cnTarget) = '' Then
                GUICtrlSetData($cnMessage, 'Target machine must be entered')
                GUICtrlSetColor($cnMessage, 0xFF0000)
            ContinueLoop
            EndIf
            Connect()

        Case $msg = $StartButton
            StartButton()
EndSelect
WEnd
;===Function For Remote System InfoBox=============================================================
Func Connect()
        Local $Separator = "------------------------------"
        SplashTextOn("", "Querying Network", 165, 40, -1, -1, 2, "", 9)
        Sleep(1000)
        If Ping(GUICtrlRead($cnTarget)) Then
        $strComputer = GUICtrlRead($cnTarget)
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        SplashOff()
        If Not IsObj($objWMIService) Then
            GUICtrlSetData($cnMessage, 'Failed to connect to system')
            GUICtrlSetColor($cnMessage, 0xFF0000)
            Return
        EndIf
        ;===WMI BIOS
        $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_Bios")
        $message = "System Info for " & $strComputer & @CRLF & $Separator & @CRLF & @CRLF
        For $objItem In $colItems1
            $message &= "Dell Asset Number: " & $objItem.SerialNumber & @CRLF & _
                    "Manufacturer: " & $objItem.Manufacturer & @CRLF & @CRLF
                    Global $surreal = $objItem.SerialNumber
                    Global $RemoteName = $strComputer
        Next
        ;===WMI NETWORK
        $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        For $objItem In $colItems2
            $message &= "IP Address: " & $objItem.IPAddress(0) & @CRLF & _
                    "IP Subnet: " & $objItem.IPSubnet(0) & @CRLF & @CRLF
        Next
        ;===WMI SYSTEM
        $colItems3 = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For $objItem In $colItems3
            $message &= "Model: " & $objItem.Model & @CRLF & _
                    "Computer Name: " & $objItem.Name & @CRLF & _
                    "Last User: " & $objItem.UserName & @CRLF
                    Global $RemoteUser = $objItem.UserName
        Next
        GUICtrlSetData($cnMessage, 'Connected, select user profile')
        GUICtrlSetColor($cnMessage, 0x008000)
        MsgBox(64, "System Information", $message)
    Else
        GUICtrlSetData($cnMessage, 'Target system could not be contacted')
        GUICtrlSetColor($cnMessage, 0xFF0000)
        Return
    EndIf
    Profile()
EndFunc   ;==>Connect
;===Function For Remote Profile Load===============================================================
Func Profile()
    Local $combo_string = ""
    $FolderList = _FileListToArray("\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC, "*", 2)
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users", "Default User", "LocalService", "NetworkService"
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]
                Else
                    $combo_string &= $FolderList[$i] & "|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($prCombo, $combo_string)
EndFunc   ;==>Profile
;===Function For Checkbox Actions==================================================================
Func StartButton()
    ;===Mapped Drives
    If GUICtrlRead($BoxMap) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Drives")
        Mapped()
    EndIf
    ;===Printers
    If GUICtrlRead($BoxPrinter) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Printers")
        SavePrinter()
    EndIf
    ;===Wireless Settings
    If GUICtrlRead($BoxWireless) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Wireless")
    EndIf
    SoundPlay(@WindowsDir & "\media\tada.wav",1)
    $Success = MsgBox(4, "", "Migration Was Successful. Do You Want To Exit?")
    If $Success = 6 Then Exit
EndFunc   ;==>StartButton
;===Function For Save Printer Info File============================================================
Func SavePrinter()
    Local $strSaveLocation
    Local $ptrFile
    Local $arrPrinters = GetPrinters("NETWORK")
    Local $strSaveLocation = 'c:\Temp\Migrate\Printers\Printers.txt'
    If Not @error Then
        $ptrFile = FileOpen($strSaveLocation, 10)
        FileWriteLine($ptrFile, @MON & "/" & @MDAY & "/" & @YEAR & " at " & @HOUR & ":" & @MIN & ":" & @SEC)
        For $i = 1 To $arrPrinters[0]
            FileWriteLine($ptrFile, $arrPrinters[$i])
        Next
        FileClose($ptrFile)
    EndIf
EndFunc   ;==>SavePrinter

;===Function For Get Printers======================================================================
Func GetPrinters($strType)
    Local $intPrinterLimit = 20
    Local $intPrinterCount = 0
    Local $arrPrinters[$intPrinterLimit + 1]
    Local $name = GUICtrlRead($cnTarget)
    Local $strReg

    If @OSType = "WIN32_NT" Then
        Switch $strType
            Case "NETWORK"
                For $i = 1 To $intPrinterLimit
                        $p = _HKCU_EnumKey("\\\" & $name & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
                        $strRegKey = _HKCU_Read("\\\" & $name & "\\" & $p & "Devices")
                        $strReg = RegEnumVal($strRegKey, $i)
                    If @error = -1 Then ExitLoop
                    If StringInStr($strReg, "\\") <> 0 Then
                        $arrPrinters[$intPrinterCount + 1] = $strReg
                        $intPrinterCount += 1
                    EndIf
                Next
        EndSwitch
    EndIf
    $arrPrinters[0] = $intPrinterCount
    Return $arrPrinters
EndFunc   ;==>GetPrinters

;===Function For Mapped Drives=====================================================================
Func Mapped()
    Local $asset = GUICtrlRead($cnTarget)
    Local $mapLocation = 'c:\Temp\Migrate\Drives\Drives.txt'
    $mapFile = FileOpen($mapLocation, 10)
For $i = 1 To 26
            $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
            $iProd = 1
            For $j = 1 To $b[0][0]
                $iProd *= $b[$j][2]
                If $b[$j][2] = 0 Then
                    $path = _HKCU_Read("\\\" & $asset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                    FileWriteLine($mapFile, $b[$j][1] & "," & $path[1][1])
                    EndIf
            Next
            If $iProd <> 0 Then ExitLoop
        Next
    EndFunc

Hi,

i don't know your function _HKCU_Read. But if you want to read out remote registry keys, it should be \\remote_machine\HKCU\Software....

So your code, e.g. $p = _HKCU_EnumKey("\\\" & $name & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i) is maybe not correct.

See helpfile RegRead:

It is possible to access remote registries by using a keyname in the form "\\computername\keyname". To use this feature you must have the correct access rights.

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

thanks 99ojo. i updated the link above to give you more info on the function _HKCU_EnumKey. it is used to be able and access HKCU. would anyone be able to help and let me know if im getting closer on my below code?

thanks

Func network_printers()
    Local $prsComputer = GUICtrlRead($cnTarget)
    Local $prLocation = 'c:\Temp\printers.txt'
    $prFile = FileOpen($prLocation, 10)
;
For $i = 1 To 100
$b = _HKCU_EnumKey("\\\" & $prsComputer & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
$iProd = 1
For $j = 1 To $b[0][0]
$iProd *= $b[$j][2]
Next
If $iProd <> 0 Then ExitLoop
_ArrayDisplay($b, $i)
Next
                    FileWriteLine($prLocation, $b[$j][1])
                    FileClose($prLocation)
EndFunc
Edited by surreal

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i now can get a list of all printers in the key remotely! can someone please help me add the needed code to only list strings that start with "\\"

Func Printers()
    Local $passet = GUICtrlRead($cnTarget)
    Local $pLocation = 'c:\Temp\Migrate\Printers\Printers.txt'
    $pFile = FileOpen($pLocation, 10)
For $i = 1 To 25
            $p = _HKCU_EnumVal("\\\" & $passet & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
            $iProdp = 1
            For $n = 1 To $p[0][0]
                $iProdp *= $p[$n][2]
                If $p[$n][2] = 0 Then
                    $ppath = _HKCU_Read("\\\" & $passet & "\\" & $p[$n][1], "Devices")
        FileWriteLine($pFile, $p[$n][1] & "," & $ppath[1][1])
        EndIf
            Next
            If $iProdp <> 0 Then ExitLoop
        Next
EndFunc

i tried adding something like the below code but that did not work.

$strReg = RegEnumVal($p, $i)
        If @error = -1 Then ExitLoop
        If StringInStr($strReg, "\\") <> 0 Then

thanks for all your help

d@ve

Edited by surreal

Share this post


Link to post
Share on other sites

If StringInStr($strReg, "\\") = 1 Then

..will match "\\123\123" or "\\\\\\\\\more\\\\" but not "\a\" or "qwe\\"

If you want to match only things that start with double backslashes and only two, you can do:

If StringRegExp($strReg, "^\\\\(?!\\)") Then ; OK

Share this post


Link to post
Share on other sites

Thanks for the reply Authenticity i added your change into the main code showen below but now the txt file is blank. if i remove the new code all printers are listed again.

the reason i only want the network printers is once i grab this info i then want to add code to install them on the system that is running the script.

thanks again for everyones help.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <HKCUReg.au3>

;===Checks Local OSVersion Create Var User Friendly================================================
$OS = @OSVersion
$OS = StringReplace($OS, "WIN_VISTA", "Windows Vista")
$OS = StringReplace($OS, "WIN_XP", "Windows XP")
$OS = StringReplace($OS, "WIN_2000", "Windows 2000")
;===Determines Documents Location According To OS++================================================
$OSDOC = @OSVersion
If $OSDOC = "WIN_VISTA" Then $DOC = "\Users\"
If $OSDOC = "WIN_XP" Then
    $DOC = "\Documents and Settings\"
EndIf
$OSDF = @OSVersion
If $OSDF = "WIN_VISTA" Then $DF = "Documents"
If $OSDF = "WIN_XP" Then
    $DF = "My Documents"
EndIf
GUICreate("", 330, 145, -1, -1)
;===GUI Network Computer To Tranfer From===========================================================
GUICtrlCreateGroup("System", 10, 10, 190, 75)
GUICtrlCreateLabel("Computer Name:", 20, 25)
$cnTarget = GUICtrlCreateInput(@ComputerName, 20, 40, 120, 20)
$cnMessage = GUICtrlCreateLabel("Enter computer name or ip address", 20, 64, 175, 15)
$cnButton = GUICtrlCreateButton("Connect", 145, 35, 50, 25, $WS_GROUP)
;===GUI Network User Profile=======================================================================
GUICtrlCreateGroup("Profile:", 10, 90, 190, 45)
$prCombo = GUICtrlCreateCombo("", 20, 105, 175, 20)
;===GUI Group What To Migrate======================================================================
GUICtrlCreateGroup("Tranfer", 210, 10, 110, 80)
$BoxMap = GUICtrlCreateCheckbox("Mapped Drives", 220, 25)
$BoxPrinter = GUICtrlCreateCheckbox("Printers", 220, 45)
$BoxWireless = GUICtrlCreateCheckbox("Wireless", 220, 65)
;===GUI Start Function=============================================================================
$StartButton = GUICtrlCreateButton("Start", 230, 100, 65, 30, $WS_GROUP)
GUISetState(@SW_SHOW)
;===Start Of GUIGetMsg=============================================================================
While 1
    $msg = GUIGetMsg()
    Select
;===Case For Exit GUI==============================================================================
        Case $msg = $GUI_EVENT_CLOSE
            $Close = MsgBox(4, "", "Are you sure you want to exit?")
            If $Close = 6 Then
            GUIDelete()
            Exit
        EndIf
;===Case For Connect===============================================================================
        Case $msg = $cnButton
            If GUICtrlRead($cnTarget) = '' Then
                GUICtrlSetData($cnMessage, 'Target machine must be entered')
                GUICtrlSetColor($cnMessage, 0xFF0000)
            ContinueLoop
            EndIf
            Connect()

        Case $msg = $StartButton
            StartButton()
EndSelect
WEnd
;===Function For Remote System InfoBox=============================================================
Func Connect()
        Local $Separator = "------------------------------"
        SplashTextOn("", "Querying Network", 165, 40, -1, -1, 2, "", 9)
        Sleep(1000)
        If Ping(GUICtrlRead($cnTarget)) Then
        $strComputer = GUICtrlRead($cnTarget)
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        SplashOff()
        If Not IsObj($objWMIService) Then
            GUICtrlSetData($cnMessage, 'Failed to connect to system')
            GUICtrlSetColor($cnMessage, 0xFF0000)
            Return
        EndIf
        ;===WMI BIOS
        $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_Bios")
        $message = "System Info for " & $strComputer & @CRLF & $Separator & @CRLF & @CRLF
        For $objItem In $colItems1
            $message &= "Dell Asset Number: " & $objItem.SerialNumber & @CRLF & _
                    "Manufacturer: " & $objItem.Manufacturer & @CRLF & @CRLF
                    Global $surreal = $objItem.SerialNumber
                    Global $RemoteName = $strComputer
        Next
        ;===WMI NETWORK
        $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        For $objItem In $colItems2
            $message &= "IP Address: " & $objItem.IPAddress(0) & @CRLF & _
                    "IP Subnet: " & $objItem.IPSubnet(0) & @CRLF & @CRLF
        Next
        ;===WMI SYSTEM
        $colItems3 = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For $objItem In $colItems3
            $message &= "Model: " & $objItem.Model & @CRLF & _
                    "Computer Name: " & $objItem.Name & @CRLF & _
                    "Last User: " & $objItem.UserName & @CRLF
                    Global $RemoteUser = $objItem.UserName
        Next
        GUICtrlSetData($cnMessage, 'Connected, select user profile')
        GUICtrlSetColor($cnMessage, 0x008000)
        MsgBox(64, "System Information", $message)
    Else
        GUICtrlSetData($cnMessage, 'Target system could not be contacted')
        GUICtrlSetColor($cnMessage, 0xFF0000)
        Return
    EndIf
    Profile()
EndFunc   ;==>Connect
;===Function For Remote Profile Load===============================================================
Func Profile()
    Local $combo_string = ""
    $FolderList = _FileListToArray("\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC, "*", 2)
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users", "Default User", "LocalService", "NetworkService"
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]
                Else
                    $combo_string &= $FolderList[$i] & "|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($prCombo, $combo_string)
EndFunc   ;==>Profile
;===Function For Checkbox Actions==================================================================
Func StartButton()
    ;===Mapped Drives
    If GUICtrlRead($BoxMap) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Drives")
        Mapped()
    EndIf
    ;===Printers
    If GUICtrlRead($BoxPrinter) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Printers")
        Printers()
    EndIf
    ;===Wireless Settings
    If GUICtrlRead($BoxWireless) = $GUI_CHECKED Then
        DirCreate("c:\Temp\Migrate\Wireless")
    EndIf
    SoundPlay(@WindowsDir & "\media\tada.wav",1)
    $Success = MsgBox(4, "", "Migration Was Successful. Do You Want To Exit?")
    If $Success = 6 Then Exit
EndFunc   ;==>StartButton
;===Function For Save Printer Info File============================================================
Func Printers()
    Local $passet = GUICtrlRead($cnTarget)
    Local $pLocation = 'c:\Temp\Migrate\Printers\Printers.txt'
    $pFile = FileOpen($pLocation, 10)
For $i = 1 To 25
            $p = _HKCU_EnumVal("\\\" & $passet & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
            $iProdp = 1
            For $n = 1 To $p[0][0]
                $iProdp *= $p[$n][2]
                If $p[$n][2] = 0 Then
                    $ppath = _HKCU_Read("\\\" & $passet & "\\" & $p[$n][1], "Devices")
                EndIf
                If StringRegExp($p, "^\\\\(?!\\)") Then
                    FileWriteLine($pFile, $p[$n][1] & "," & $ppath[1][1])
                    EndIf
            Next
            If $iProdp <> 0 Then ExitLoop
        Next
EndFunc   ;==>SavePrinter

;===Function For Mapped Drives=====================================================================
Func Mapped()
    Local $asset = GUICtrlRead($cnTarget)
    Local $mapLocation = 'c:\Temp\Migrate\Drives\Drives.txt'
    $mapFile = FileOpen($mapLocation, 10)
For $i = 1 To 25
            $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
            $iProd = 1
            For $j = 1 To $b[0][0]
                $iProd *= $b[$j][2]
                If $b[$j][2] = 0 Then
                    $path = _HKCU_Read("\\\" & $asset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                    FileWriteLine($mapFile, $b[$j][1] & "," & $path[1][1])
                    EndIf
            Next
            If $iProd <> 0 Then ExitLoop
        Next
    EndFunc

Share this post


Link to post
Share on other sites

So $p should be an array type or evaluated within string context? StringRegExp($p, "^\\\\(?!\\)"), should it be StringRegExp($p[$n][1], "^\\\\(?!\\)") or something?

Share this post


Link to post
Share on other sites

thank you so much Authenticity, thank you, thank you. that did the trick, im pretty new to arrays, learning as i go.

not sure if i should start a new post but i now need to be able to use this array data from printers and mapped drivers to now install on the local machine.

not sure if i need to create an ini or if i can use the array itself to do stuff like DriveMapAdd. any help in the right direction would be great.

d@ve

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
Sign in to follow this  
Followers 0