Jump to content

Script does not work on all XP OS PC's


Recommended Posts

Hey there. Here is a wierd situation. I have a script (actually a portion of a larger one) that takes the printer information from the registry and creates a folder within the C:\Program files directory, then put the printer info into an .ini file. Works 9 times outta 10. For some reason it works on most XP OS PC's but not on all. Can't figure it out. Any ideas?

Here's the code:

Global $Folder = @ProgramFilesDir & '\PMS Mappings'

_GetPrinterList()

Func _GetPrinterList()

Local $Count = 0

Local $PrinterCount = 0

Local $RegKey = "HKEY_CURRENT_USER\Printers\Connections"

While 1

$Count += 1

$var2 = RegEnumKey($RegKey, $Count)

If @error <> 0 Then ExitLoop

$var2 = StringReplace($var2, ',', '\')

$Type = DriveGetType($var2)

If $Type = 'Network' Then

$PrinterCount += 1

IniWrite(@ProgramFilesDir & "PMS Mappings\printers.ini", 'Printer Shares', $PrinterCount, $var2)

ConsoleWrite('Ret: ' & @error & $PrinterCount & $var2 &@crlf)

MsgBox(1, "Printers", $PrinterCount & $var2)

EndIf

WEnd

EndFunc

Thanks!

Link to comment
Share on other sites

Hey there. Here is a wierd situation. I have a script (actually a portion of a larger one) that takes the printer information from the registry and creates a folder within the C:\Program files directory, then put the printer info into an .ini file. Works 9 times outta 10. For some reason it works on most XP OS PC's but not on all. Can't figure it out. Any ideas?

Here's the code:

Thanks!

What are the symptoms when it fails? Does it fail consistently on particular machines, or sometimes fail on machines it worked on before?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

What are the symptoms when it fails? Does it fail consistently on particular machines, or sometimes fail on machines it worked on before?

:)

Fails consistantly on the same pc's. When the script fails, the folder and .ini doesn't get created. I also threw message box in there. If it doesn't pop up, it fails.

Link to comment
Share on other sites

Fails consistantly on the same pc's. When the script fails, the folder and .ini doesn't get created. I also threw message box in there. If it doesn't pop up, it fails.

Run it this way on one of the failing machines (produces a log file):

#include <file.au3>

Global $Folder = @ProgramFilesDir & '\PMS Mappings'
Global $INI = $Folder & "\printers.ini"
Global $LogFile = $Folder & "\GetPrinterList.log"
If Not _FileWriteLog($LogFile, "Initialized script: " & @ScriptFullPath & @CRLF & _
        @TAB & "$Folder = " & $Folder & @CRLF & _
        @TAB & "$INI = " & $INI & @CRLF & _
        @TAB & "$LogFile = " & $LogFile) Then
    MsgBox(16, "Error!", "Could not create log file: " & $LogFile)
    Exit
EndIf

_GetPrinterList()

Func _GetPrinterList()
    Local $Count = 0
    Local $PrinterCount = 0
    Local $RegKey = "HKEY_CURRENT_USER\Printers\Connections"

    While 1
        $Count += 1
        
        $var2 = RegEnumKey($RegKey, $Count)
        If @error = 0 Then
            _FileWriteLog($LogFile, "RegEnumKey " & $Count & ": " & $var2)
        Else
            _FileWriteLog($LogFile, "RegEnumKey returned @error = " & @error & ", exiting loop")
            ExitLoop
        EndIf
        
        $var2 = StringReplace($var2, ',', '\')
        $Type = DriveGetType($var2)
        _FileWriteLog($LogFile, "Drive type returned for " & $var2 & " = " & $Type)
        If $Type = 'Network' Then
            $PrinterCount += 1
            If IniWrite($INI, 'Printer Shares', $PrinterCount, $var2) Then
                _FileWriteLog($LogFile, "Wrote to ini file section [Printer Shares]: " & $PrinterCount & " = " & $var2)
            Else
                _FileWriteLog($LogFile, "Error!  Failed to write to ini file section [Printer Shares]: " & $PrinterCount & " = " & $var2)
                MsgBox(16, "Error!", "Failed to write to ini file section [Printer Shares]: " & $PrinterCount & " = " & $var2)
            EndIf
        EndIf
    WEnd
EndFunc   ;==>_GetPrinterList

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The log file looks ok:

2007-08-23 15:53:16 : Initialized script: C:\Documents and Settings\test\Desktop\logfilejustprint.au3

$Folder = C:\Program Files\PMS Mappings

$INI = C:\Program Files\PMS Mappings\printers.ini

$LogFile = C:\Program Files\PMS Mappings\GetPrinterList.log

2007-08-23 15:53:16 : RegEnumKey 1: ,,server01,lp1

2007-08-23 15:53:23 : Drive type returned for \\server01\lp1 =

2007-08-23 15:53:23 : RegEnumKey returned @error = -1, exiting loop

No Msgbox pop up...

Funky, huh?

Link to comment
Share on other sites

The log file looks ok:

2007-08-23 15:53:16 : Initialized script: C:\Documents and Settings\test\Desktop\logfilejustprint.au3

$Folder = C:\Program Files\PMS Mappings

$INI = C:\Program Files\PMS Mappings\printers.ini

$LogFile = C:\Program Files\PMS Mappings\GetPrinterList.log

2007-08-23 15:53:16 : RegEnumKey 1: ,,server01,lp1

2007-08-23 15:53:23 : Drive type returned for \\server01\lp1 =

2007-08-23 15:53:23 : RegEnumKey returned @error = -1, exiting loop

No Msgbox pop up...

Funky, huh?

No, the log file does NOT look OK... The "Drive type" returned at 15:53:23 is blank, and no entry is made in the .ini file. Is that really what you wanted?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The log file looks ok:

2007-08-23 15:53:16 : Initialized script: C:\Documents and Settings\test\Desktop\logfilejustprint.au3

$Folder = C:\Program Files\PMS Mappings

$INI = C:\Program Files\PMS Mappings\printers.ini

$LogFile = C:\Program Files\PMS Mappings\GetPrinterList.log

2007-08-23 15:53:16 : RegEnumKey 1: ,,server01,lp1

2007-08-23 15:53:23 : Drive type returned for \\server01\lp1 =

2007-08-23 15:53:23 : RegEnumKey returned @error = -1, exiting loop

No Msgbox pop up...

Funky, huh?

I was wrong:

2007-08-23 15:53:23 : Drive type returned for \\server01\lp1 =

is missing (thanks to my bad eyes and Danny's help)

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