Jump to content
Sign in to follow this  
bigbangnet

creating a file with printer names

Recommended Posts

bigbangnet

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

Share this post


Link to post
Share on other sites
JLogan3o13

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
bigbangnet

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

Share this post


Link to post
Share on other sites
JLogan3o13

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
bigbangnet

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

Share this post


Link to post
Share on other sites
JLogan3o13

Line 5 says that if $printerkey is not a blank value, then write the line to the file. Otherwise that entry would be skipped.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
bigbangnet

check...and thanks for the great info


** Warning **Noobie ahead. handle with caution

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.