Jump to content

IniRead from a UNC Path


Recommended Posts

I'm working on a script to get some information from all the computers on my network. I need to know, can I use IniRead() with a UNC Path?

Here's my code:

$csvADComputers = FileOpen("C:\ADComputers.csv", 0); Opens C:\ADComputers.csv for Reading
$csvOutput = FileOpen("C:\Focus WS Numbers.csv", 2); Opens C:\Focus WS Numbers.csv for Writing and erases any data in the file
FileWriteLine($csvOutput, "Host,WS#")

While 1
    $objComputer = FileReadLine($csvADComputers)
    If @error = -1 Then ExitLoop
        MsgBox(0, "objComputer", $objComputer); Used for Debugging      
        $focusxpini = FileOpen("\\" & $objComputer & "\C$\Winnt\focusxp.ini", 0)
        MsgBox(0, "focusxpini", "\\" & $objComputer & "\C$\Winnt\focusxp.ini"); Used for Debugging
        If $focusxpini = -1 Then
            $focusxpini = FileOpen("\\" & $objComputer & "\C$\Windows\focusxp.ini", 0)
            MsgBox(0, "focusxpini", "\\" & $objComputer & "\C$\Windows\focusxp.ini"); Used for Debugging
            If $focusxpini = -1 Then
                FileWriteLine($csvOutput, $objComputer & ",Can't Connect"
            Else
                $ws = IniRead("\\" & $objComputer & "\C$\Windows\focusxp.ini", "xpwnav", "WS", "Unable to read WS#")
                FileWriteLine($csvOutput, $objComputer & "," $ws)
                FileClose($focusxpini)
            EndIf
        Else
            $ws = IniRead("\\" & $objComputer & "\C$\Windows\focusxp.ini", "xpwnav", "WS", "Unable to read WS#")
            FileWriteLine($csvOutput, $objComputer & "," $ws)
            FileClose($focusxpini)
        EndIf
WEnd

FileClose($csvOutput)
FileClose($csvADComputers)

Here's the error message I get when I run it:

FileWriteLine($csvOutput, $objComputer & "," $ws)

FileWriteLine($csvOutput, ^ ERROR

>Exit code: 0    Time: 1.842

Thanks for taking the time to look at my problem. All suggests for fixing the problem, or how to make the script faster are welcome. Let me know if you have any questions.

Thanks again,

Ian

* It's been a while since I've use AutoIt...

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

Just use drivemapadd and then use the mapped drive letter.

<{POST_SNAPBACK}>

Thanks...

Here's what I've done...

$csvADComputers = FileOpen("C:\ADComputers.csv", 0); Opens C:\ADComputers.csv for Reading
$csvOutput = FileOpen("C:\Focus WS Numbers.csv", 2); Opens C:\Focus WS Numbers.csv for Writing and erases any data in the file
FileWriteLine($csvOutput, "Host,WS#")

While 1
    $objComputer = FileReadLine($csvADComputers)
    If @error = -1 Then ExitLoop
        MsgBox(0, "objComputer", $objComputer); Used for Debugging      
        DriveMapAdd("Z:", "\\" & $objComputer & "\C$"); Connects to the computers administrative share
        
        If FileExists("Z:\Winnt\focusxp.ini") Then
            $ws = IniRead("Z:\Winnt\focusxp.ini", "xpwnav", "ws", "Unable to read WS#")
            MsgBox(0, "ws", "WS# = " & $ws); Used for Debugging
            FileWriteLine($csvOutput, "" & $objComputer & "," $ws & "")
        ElseIf FileExists("Z:\Windows\focusxp.ini") Then
            $ws = IniRead("Z:\Windows\focusxp.ini", "xpwnav", "WS", "Unable to read WS#")
            MsgBox(0, "ws", "WS# = " & $ws); Used for Debugging
            FileWriteLine($csvOutput, "" & $objComputer & "," $ws & "")
        EndIf
        
        DriveMapDel("Z:"); Disconnects the mapped drive
WEnd

FileClose($csvOutput)
FileClose($csvADComputers)

Now it works and reads in the first computer name, and runs the script on it, and reports the WS# that I need, but then the script exits... It never reads in the 2nd PC Name. Any Idea?

Thanks again,

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

You need to close all files on the remote system before the drivemapdel will work. I have a feeling that if you look in my computer, z: will still be mapped to the first computer.

Edited by this-is-me
Who else would I be?
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...