Jump to content

List Connections To Shared Printers


ioliver
 Share

Recommended Posts

I didn't know what category this fell into, so I thought I'd post it here.

Does anyone have a script that will list current printer connections for a remote PC?

Let me know if you need more info.

Thanks,

Ian

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

Link to comment
Share on other sites

Do you mean normal printer-connections that has a user?

Is the key:

HKEY_CURRENT_USER\Printers\Connections

not what you want?

In the subkeys you find the printer-connections which you could readout with "RegEnumKey".

Edited by Holger
Link to comment
Share on other sites

The code might be mickey mouse as I am just starting myself, but this will create a batch file on the user's desktop so that the user can re-install printers whenever they need to..

Hope this helps

_ITCH

$PRINTER_FILE = @UserProfileDir & "\desktop\" & @Username & "_printers.bat"

FileDelete ( $PRINTER_FILE )

$PRINTER = "default blank entry"

$I = 1

$READ_PRINTER = "test"

FileDelete("c:\temp.txt")

DO

$READ_PRINTER = RegEnumKey("HKEY_CURRENT_USER\Printers\Connections", $i)

$TEMP_VAR = StringReplace($READ_PRINTER, ",", "\")

IF $TEMP_VAR = "" THEN

$TEMP_VAR = "CLS"

ELSE

FileWriteLine ($PRINTER_FILE, "Start " & $TEMP_VAR)

FileWriteLine ("c:\temp.txt", $TEMP_VAR)

$i = $i + 1

ENDIF

Until $READ_PRINTER = ""

Link to comment
Share on other sites

Thanks Holger,

HKEY_CURRENT_USER\Printers\Connections

I think that Reg Key is what I was looking for. Now I just need to have AutoIT read a Remote Registy.

Thanks again,

Ian

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

Link to comment
Share on other sites

Hi ioliver,

I am wondering you did not find this with a formum search. I asked this question some days ago myself here: http://www.autoitscript.com/forum/index.ph...wtopic=3913&hl=

So you might find this interessting.

Here are the functions I wrote after receiving the info:

; ----------------------------------------------------------------------------
; Function setdefaultprinter
; currently gives not feedback if function was successfull or not.
; ----------------------------------------------------------------------------

Func setdefaultprinter ($PRINTERSHARE)
   RunWait(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n " & '"' & $PRINTERSHARE & '"', "", @SW_HIDE)
EndFunc

; ----------------------------------------------------------------------------
; Function delprinterconnection 
; Deletes a printershare connection
; currently gives not feedback if function was successfull or not.
; ----------------------------------------------------------------------------

Func delprinterconnection ($PRINTERSHARE)
   $printerconnectioncount = 0
   while 1
      $printerconnectioncount = $printerconnectioncount +1
      $printerconnectionname= StringSplit ( RegEnumKey ("HKEY_CURRENT_USER\Printers\Connections",$printerconnectioncount), "," ); examine if exists.
      if (@error = 1) Then
         ExitLoop
      EndIf
      $printername = StringSplit ( $printershare, "\" )
      if $printername[$printername[0]] = $printerconnectionname[$printerconnectionname[0]] Then;only delete printer connnection if it
         RunWait(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /dn /n " & '"' & $PRINTERSHARE & '"', "", @SW_HIDE);exist (this makes login script much faster)
      EndIf
   wend
EndFunc


; ----------------------------------------------------------------------------
; Function delprinterconnection 
; Connect to a printershare
; currently gives not feedback if function was successfull or not.
; ----------------------------------------------------------------------------

Func addprinterconnection ($PRINTERSHARE)
   RunWait(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /in /n " & '"' & $PRINTERSHARE & '"', "", @SW_HIDE)
EndFunc

Note: Functions are tested only with german versions of Win2000 and WinXP.

A function to list all connections, I don´t have at the moment, but it can easily be done, so if you don´t get a function for this scripted yourself, just ask again.

commenti

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