Sign in to follow this  
Followers 0
ioliver

List Connections To Shared Printers

10 posts in this topic

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

Share this post


Link to post
Share on other sites



Does "net view \\computername" do what you need?


Who else would I be?

Share this post


Link to post
Share on other sites

No, 'net view \\computername' show what shares are available on a computer, not what shares the computer is connected to.

Thanks,

Ian


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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 = ""

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Is the HKEY_CURRENT_USER Key available remotely?

Ian


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

Share this post


Link to post
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

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  
Followers 0