Jump to content

Need Help with registry


Recommended Posts

good day to all. i am trying to make a script which will delete Microsoft Office Document Image Writer and Microsoft XPS Document Writer printer installed to all PC's in our network. i will initiate a registry delete of the entry of the printers. my test script works fine on the first registry part but the second case, it will fail to delete. can someone help me why the script don't work as what i need to. thanks...

below is my script

For $i= 1 to 10
    $var = RegEnumKey("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers", $i)
    If @error <> 0 then ExitLoop
    ;MsgBox(4096, "SubKey #" & $i & " under HKLM\Software: ", $var)

    Select
        Case $var = "Microsoft Office Document Image Writer"
            ;$read = RegRead("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer", "Name")         
            RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer")
        Case $var = "Microsoft XPS Document Writer"
            ; $read = RegRead("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer", "Name")         
            RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer")
    EndSelect
    
Next

ShellExecute("sc.exe", "\\12.110.1.12 stop SPOOLER", @SystemDir)
ShellExecute("sc.exe", "\\12.110.1.12 start SPOOLER", @SystemDir)
Link to comment
Share on other sites

You could start by helping yourself a little.

Take a look at the Regdelete() function in the helpfile, and its return values and @error values, and add a little error checking.

Hi JohnOne,

I've done that.

This line of script will list if PC has Microsoft Document Writer and Microsoft XPS installed in PC....

$var = RegEnumKey("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers", $i)

Then on the Select Case, If the script match the registry name of the printer, it will delete the value...

The first select case works fine...

Select
        Case $var = "Microsoft Office Document Image Writer"
            ;$read = RegRead("\\10.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer", "Name")         
            RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft Office Document Image Writer")

but the second select case, it failed to delete

Case $var = "Microsoft XPS Document Writer"                     
            RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer")

I wonder why the second case is not being executed....

Link to comment
Share on other sites

This is why you must add some error checking, to indicate to you whay it is failing.

RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer")

ConsoleWrite("RegDelete @error " & @error & @CRLF)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

This is why you must add some error checking, to indicate to you whay it is failing.

RegDelete("\\12.110.1.12\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer")

ConsoleWrite("RegDelete @error " & @error & @CRLF)

Hi JohnOne. I managed to make it working without this error checking you advise. Thanks anyway... :unsure:

Cheers...

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