Jump to content

Recommended Posts

Posted

I'm working in a domain environment and I got some computers to do backups so i thought of doing a script that could take the name of the printers on a file so it would save me some time especially when theres over a 100 computers that I have to do. I want to start small since I'm pretty new to autoit so I thought of this code to start with

Local $printerkey = ""


For $i = 1 To 10
$printerkey = RegEnumKey("HKEY_CURRENT_USER\Printers\Connections", $i)
If @error Then ExitLoop
Next


$file = FileOpen("printer.txt", 1)


FileWrite($file, $printerkey)


FileClose($file)

It does create a file printer.txt but it writes nothing in it. All I want it to do first is read the regkeys mentionned which should be the printers I go on my pc, then write those which are suppose to be stored in a variable then write them in printers.txt. I know I made a mistake but I don't know where... I guess its the filewrite that doesn't take variables I guess.

Sorry for my noobiness

 

** Warning **Noobie ahead. handle with caution

  • Moderators
Posted

You need to put your write operation inside the for loop, so every printer is added to the file. Try this:

Local $printerkey = ""

For $i = 1 To 10
$printerkey = RegEnumKey("HKEY_CURRENT_USER\Printers\Connections", $i)
FileWriteLine(@ScriptDir & "\printer.txt", $printerkey)
If @error Then ExitLoop
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Nice it works but now I've added @computername

Local $printerkey = ""
Local $pcname = ""
For $i = 1 To 10
$printerkey = RegEnumKey("HKEY_CURRENT_USER\Printers\Connections", $i)
FileWriteLine(@ScriptDir & "\printer.txt", @ComputerName & $printerkey )
If @error Then ExitLoop
Next

Obviously it displays it 10 times. Is there a way to prevent display it 10 times. Only the number of times it gives me a printer name ? I would think of adding a variable to the "FOR" and if the value gives nothing then it would exit the loop..I guess ?

** Warning **Noobie ahead. handle with caution

  • Moderators
Posted

You could do something like this:

Local $printerkey = ""
Local $pcname = ""
For $i = 1 To 10
   $printerkey = RegEnumKey("HKEY_CURRENT_USER\Printers\Connections", $i)
      If $printerkey <> "" Then
         FileWriteLine(@ScriptDir & "\printer.txt", @ComputerName & $printerkey )
      EndIf
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

So if I understand line 5 says if theres a value in that variable then write something ? I'm trying to understrand so sorry if its sounds stupid. I just looked in the help file and that <> sounds like related to the comparison operators "Tests if two values are not equal." but I can guess it could be "Tests if the first value is less than the second".

** Warning **Noobie ahead. handle with caution

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
  • Recently Browsing   0 members

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