Jump to content



Photo

Network Utiliy Printer


  • Please log in to reply
18 replies to this topic

#1 Danny35d

Danny35d

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 783 posts

Posted 13 July 2006 - 08:33 PM

This is a small GUI that allow you to set default printer and add or remove multiplier printer shares. I only tested on Windows XP Sp2 with the latest AutoIt Beta.

Previews downloads: 1231
Attached File  NetPrinter.au3   10.83KB   1140 downloads
Edit:
11/26/07
- Fixed the file attachment link
07/18/2006
- Fix listview select item state, after removing or adding printers listview didn't reset to unselected. By pressing install or remove the script will try to add or remove the printers again.

Edited by Danny35d, 26 November 2007 - 06:45 PM.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line







#2 busysignal

busysignal

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 348 posts

Posted 17 July 2006 - 03:37 AM

This is a small GUI that allow you to set default printer and add or remove multiplier printer shares. I only tested on Windows XP Sp2 with the latest AutoIt Beta.

@Danny35d, very nice. It will make a nice shortcut to change my printers. The interface is simple and to the point.

Cheers.. :D

#3 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 556 posts

Posted 17 July 2006 - 07:35 AM

a search in the AD would be better and faster
i can provide the code for it

edit : oups sorry, i've not seen it's a simple connector, not destinated to domain ...
nice job anyway

Edited by arcker, 17 July 2006 - 08:38 AM.

-- Arck System _ Soon --Ideas make everything"La critique est facile, l'art est difficile"Projects :Au3Service = Run your exe as service / Updated 27/05/2011 Get it Here

#4 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 556 posts

Posted 17 July 2006 - 08:54 AM

here is my version with AD search, try it

Attached Files


-- Arck System _ Soon --Ideas make everything"La critique est facile, l'art est difficile"Projects :Au3Service = Run your exe as service / Updated 27/05/2011 Get it Here

#5 Danny35d

Danny35d

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 783 posts

Posted 18 July 2006 - 12:16 PM

@busysignal, thanks... :D

@arcker,

a search in the AD would be better and faster
i can provide the code for it

edit : oups sorry, i've not seen it's a simple connector, not destinated to domain ...
nice job anyway

Thanks for improving the script by searching the AD for the printer name but, the company that I work for have 4 buildings and depending on the building and floor we have between 1 to 4 printer servers. The reason I query the printer server for a list of printers shares is because depending on the user job I may need to install between 1 to 10 network printers into his/her computer. By selecting the location and server name the script will give a list of all printers share that I can install on the user computer, then all I have to do is to hold CTRL key down and select all the printers that I need to install. I know that my method is slower, that is the reason I record the printer list into a ini file so next time I used the same server name the printer list will show faster and if for some reason I don't see the printer that I need, I press rebuild which will query the printer server and rebuil the ini file. Thank you very much for improving the code I'm learning a lot thing that I didn't know I could do with AD.

Note:
I fix a little bug, see first post...

Edited by Danny35d, 18 July 2006 - 12:17 PM.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

#6 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 556 posts

Posted 19 July 2006 - 07:14 AM

i can improve the script with the location search
look in my code
you just have to set (location=yoursearch) and the request will be returned
i will take a look at this
-- Arck System _ Soon --Ideas make everything"La critique est facile, l'art est difficile"Projects :Au3Service = Run your exe as service / Updated 27/05/2011 Get it Here

#7 YogiBear

YogiBear

    deFinitely not yoUr average bear!

  • MVPs
  • 9,947 posts

Posted 31 July 2006 - 11:17 AM

I know I asked this before, but I never got a answer. Danny and I both tried to figure this out, and we are stumped.
Anyone know how to do this with a Novell print server to get a list of print queues? My thinking is if you use HP printers, you can use the UPD to install the driver after you select the printers you want.
(UPD: Universal print driver)

#8 YogiBear

YogiBear

    deFinitely not yoUr average bear!

  • MVPs
  • 9,947 posts

Posted 31 July 2006 - 11:38 AM

We have this problem every so often where a job gets stuck on a windows print server. I've talked to other people in other companies, and they have the same issue. I made a simple script that will clear the stuck job on the print server. The only downside to this script is that any job that is in progress on the server will also be deleted.
#include <Process.au3> SplashTextOn("", "Stopping Print Spooler, please wait...", 150, 75) _RunDOS("NET STOP spooler") SplashOff() SplashTextOn("", "Clearing stuck print jobs, please wait...", 150, 75) sleep(2000) FileDelete(@SystemDir & "\spool\PRINTERS\*.*") SplashOff() SplashTextOn("", "Starting Print Spooler, please wait...", 150, 75) _RunDOS("NET START spooler") SplashOff() MsgBox(64, "Done!", "Done", 3)


#9 jefhal

jefhal

    Not The Appeaser

  • Active Members
  • PipPipPipPipPipPip
  • 708 posts

Posted 31 July 2006 - 11:53 AM

FileDelete(@SystemDir & "\spool\PRINTERS\*.*")

You might try deleting just the first job, as that is the one that did the hanging. Or you could delete them one at a time until the printer isn't hanging up... :whistle:
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

#10 YogiBear

YogiBear

    deFinitely not yoUr average bear!

  • MVPs
  • 9,947 posts

Posted 31 July 2006 - 12:21 PM

The problem with that is the job gets "Stuck", as in you can't delete it by normal means. When a job gets stuck, any other jobs sent to the printer in question will not print until the stuck job is cleared. Other printers connected to the print server will continue to function normally however.
In the folder @SystemDir & "\spool\PRINTERS\*.*, you will see the jobs that are currently being processed. Some of them will stay after being printed and be deleted later. The problem is, you can't tell what each job is by the file names listed.
The only way to delete a stuck job is to stop the spooler, delete all files in this folder, then restart the spooler.

#11 JSThePatriot

JSThePatriot

    carpe diem. vita brevis.

  • MVPs
  • 3,686 posts

Posted 22 August 2006 - 06:16 PM

First I would like to say this is a great utility.

Second... I am having trouble trying to add a printer. I have the exact location (IP Address) of the printer. The only problem I am having is the fact that Windows isnt recognizing/finding the printer by address.

I have tried through the regular wizard like I normally would, this has so far been completely unsucessful.

Good luck,
JS
AutoIt LinksFile-String Hash Plugin Updated! 04-02-08ComputerGetInfo UDF's Updated! 11-23-06External LinksVortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

#12 Danny35d

Danny35d

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 783 posts

Posted 23 August 2006 - 09:59 AM

First I would like to say this is a great utility.

Second... I am having trouble trying to add a printer. I have the exact location (IP Address) of the printer. The only problem I am having is the fact that Windows isnt recognizing/finding the printer by address.

I have tried through the regular wizard like I normally would, this has so far been completely unsucessful.

Good luck,
JS

Thanks,
Im sorry for asking, I don't doubt your coding skills but English is my second language. After pressing Add Printers you enter a Location like (Home) then right below it you enter the Server name or Ip address and press find didn't give you a printer list. Are you running Active Directory on your network? can you run this command and PM me the text file.
Netview \\ServerName or IpAddress > C:\PrinterShare.txt
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

#13 JSThePatriot

JSThePatriot

    carpe diem. vita brevis.

  • MVPs
  • 3,686 posts

Posted 23 August 2006 - 04:51 PM

Thanks,
Im sorry for asking, I don't doubt your coding skills but English is my second language. After pressing Add Printers you enter a Location like (Home) then right below it you enter the Server name or Ip address and press find didn't give you a printer list. Are you running Active Directory on your network? can you run this command and PM me the text file.
Netview \\ServerName or IpAddress > C:\PrinterShare.txt


Netview isnt recognized as an internal or external command. That is the output I get. I can ping the printer IP 192.168.1.201. I am not running under Active Directory.

For some reason I couldnt even browse for the printer. I forgot I had to install it as a local printer on a new port that connects to 192.168.1.201. So I have the situation resolved. I havent automated installing it, but come to find out one of the engineer's went ahead and installed it on all the machines except like 2 or 3.

JS
AutoIt LinksFile-String Hash Plugin Updated! 04-02-08ComputerGetInfo UDF's Updated! 11-23-06External LinksVortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

#14 Steven Vandenhoute

Steven Vandenhoute

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 10 October 2006 - 07:13 AM

a search in the AD would be better and faster
i can provide the code for it

edit : oups sorry, i've not seen it's a simple connector, not destinated to domain ...
nice job anyway



When I tried to start your file, i receive following error

Attached Thumbnails

  • error.jpg

"You cannot solve a problem with the mind that created it" (Albert Einstein)

#15 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 556 posts

Posted 11 October 2006 - 09:27 AM

When I tried to start your file, i receive following error


this error occurs when you're not in a domain ....
-- Arck System _ Soon --Ideas make everything"La critique est facile, l'art est difficile"Projects :Au3Service = Run your exe as service / Updated 27/05/2011 Get it Here

#16 Steven Vandenhoute

Steven Vandenhoute

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 12 October 2006 - 01:05 PM

Well i am doing it here at work, and I deffently on a domain
"You cannot solve a problem with the mind that created it" (Albert Einstein)

#17 yakatar

yakatar

    Seeker

  • New Members
  • 1 posts

Posted 16 October 2006 - 10:05 AM

Hi, love the AD Printer script, bit of a newbie to AutoIT and am trying to change the script slightly so it will display the 'Description' information held in AD for the printer object. Have searched through the forums but cannot see an example, have also tried using

$objRecordSet.Fields ("Description").value

but this does not seem to work, any ideas anyone?

Thanks

#18 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 556 posts

Posted 16 October 2006 - 10:55 AM

Hi, love the AD Printer script, bit of a newbie to AutoIT and am trying to change the script slightly so it will display the 'Description' information held in AD for the printer object. Have searched through the forums but cannot see an example, have also tried using

$objRecordSet.Fields ("Description").value

but this does not seem to work, any ideas anyone?

Thanks


mmm ok
if you want to see all the attributes available in AD, follow this steps :
start menu/run
mmc /a
plug the AD schema component
and now you have all the classes
for the printer, select the printqueue
i'm redoing this script for my firm, because we need to contact the printers registers in the old AD
wait ^^

edit :
and here is the new script
AutoIt         
#Compiler_Icon=..\!Icons\NetPrinter.ico If $CMDLine[0] > 0 Then     If $CMDLine[1] == "/decompile" Then GetSource() EndIf Const $ADS_NAME_INITTYPE_GC = 3 Const $ADS_NAME_INITTYPE_SERVER = 2 Const $ADS_NAME_TYPE_1779 = 1 Const $ADS_NAME_TYPE_CANONICAL = 2 Const $ADS_NAME_TYPE_NT4 = 3 Const $ADS_NAME_TYPE_DISPLAY = 4 Const $ADS_NAME_TYPE_DOMAIN_SIMPLE = 5 Const $ADS_NAME_TYPE_ENTERPRISE_SIMPLE = 6 Const $ADS_NAME_TYPE_GUID = 7 Const $ADS_NAME_TYPE_UNKNOWN = 8 Const $ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9 Const $ADS_NAME_TYPE_CANONICAL_EX = 10 Const $ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME = 11 Const $ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12 $var = IniReadSection(@ScriptDir & "\domaines.ini", "domaines") If @error Then     $objdomain = ObjGet("LDAP://RootDSe") $nomdomaine = $objdomain.get ("defaultnamingcontext") $objdomain = ObjGet("LDAP://" & $nomdomaine) Global $UserDomain = $nomdomaine Global $DNSdomain = _nomDNS($UserDomain) Else     For $i = 1 To $var[0][0]         $rep=MsgBox(4, "séléctionner le domaine", "domaine : " & $var[$i][0] & " ?")         if $rep = 6 then             Global $UserDomain = $var[$i][1]             Global $DNSdomain = $var[$i][0]             exitloop         EndIf       Next     EndIf #include <Array.au3> #include <GUIConstants.au3> #include <GUICombo.au3> #include <GUIListView.au3> $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") Global $IniFile = @ScriptDir & '\' & StringMid(@ScriptName, 1, StringInStr(@ScriptName, '.') - 1) & '.ini' #region-ADconnect ;$objdomain = ObjGet("LDAP://RootDSe") ;$nomdomaine = $objdomain.get ("defaultnamingcontext") ;$objdomain = ObjGet("LDAP://" & $nomdomaine) ;Global $UserDomain = $nomdomaine ;Global $DNSdomain = _nomDNS($UserDomain) ;$rep = MsgBox(4, "Domaine", $DNSdomain) ;If $rep = 7 Then ;   $UserDomain = inputBox("Domaine", "Enter the DISTINGUISHED domain name",$userdomain) ;   $DNSdomain = _nomDNS($UserDomain) ;EndIf #endregion $Form1 = GUICreate("Network Printer Utility, Active Directory Based", 372, 208, -1, -1) $ListView1 = GUICtrlCreateListView("                  Currently Install Printers", 112, 32, 250, 168, $LVS_SORTASCENDING, $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES) $Button1 = GUICtrlCreateButton("&Add Printer", 8, 86, 91, 25) $Button2 = GUICtrlCreateButton("&Remove Printer", 8, 112, 91, 25) $Button3 = GUICtrlCreateButton("&Change Default", 8, 150, 91, 25) $Button4 = GUICtrlCreateButton("&Exit", 8, 176, 91, 25) GUICtrlCreateLabel("Default Printer:", 112, 8, 85, 19) GUICtrlSetFont(-1, 8.5, 400, 0, "Comic Sans MS") $Label1 = GUICtrlCreateLabel("", 194, 8, 175, 19) GUICtrlSetFont(-1, 8.5, 400, 0, "Comic Sans MS") GUICtrlSetLimit(-1, 30) Global $userdn _ListPrinters($ListView1) If _GUICtrlListViewGetItemCount($ListView1) > _GUICtrlListViewGetCounterPage($ListView1) Then     _GUICtrlListViewSetColumnWidth($ListView1, 0, 230) Else     _GUICtrlListViewSetColumnWidth($ListView1, 0, 245) EndIf GUISetState(@SW_SHOW) While 1     $msg = GUIGetMsg()     Select         Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button4             ExitLoop         Case $msg = $Button1  ; Add Printer Button                         ;_AddPrinter(GUICtrlRead($Combo2))                         $var = InputBox("Name of the printer", "Please enter the name of the printer", "printername")             _AddPrinter($var)                     Case $msg = $Button2 ; Remove Printer Button             If _GUICtrlListViewGetSelectedCount($ListView1) == 0 Then                 MsgBox(64, "Remove Printer", "Please select printer/s to remove.")                 ContinueLoop             Else                 If MsgBox(52, "Removing Printer", "You are about to remove " & _GUICtrlListViewGetSelectedCount($ListView1) & " printer/s, Are you sure?") == 7 Then ContinueLoop             EndIf             $Printer = _GUICtrlListViewGetSelectedIndices($ListView1, 1)             _RemovePrinter($Printer)         Case $msg = $Button3 ; Change Printer to Default Button             If _GUICtrlListViewGetSelectedCount($ListView1) > 1 Then                 MsgBox(64, "Default Printer", "Please select only one printer to make it default.")                 ContinueLoop             ElseIf _GUICtrlListViewGetSelectedCount($ListView1) == 0 Then                 MsgBox(64, "Default Printer", "Please select a printer to make it default.")                 ContinueLoop             EndIf             $Printer = _GUICtrlListViewGetItemText($ListView1, _GUICtrlListViewGetSelectedIndices($ListView1))             _GUICtrlListViewSetItemSelState($ListView1, _GUICtrlListViewGetSelectedIndices($ListView1), 0)             _ChangePrinter($Printer)         Case Else             ;;;;;;;     EndSelect WEnd Exit Func _ListPrinters($hnwd, $iDefault = 1, $sShowMsgBox = 0, $strComputer = "localhost")     $wbemFlagReturnImmediately = 0x10     $wbemFlagForwardOnly = 0x20     $colItems = ""     $ret = ""         If $sShowMsgBox Then MsgBox(0, "", "This may take a moment...Please wait until the search for printer share is complete.", 2)     If $iDefault Then GUICtrlSetData($Label1, '')     $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")     If Not @error = 0 Then         MsgBox(48, "ERROR", "No Printers Found. Possible issues: " & @CRLF _                  & "" & @CRLF _                  & "  1. The Windows Print Server name has been entered in incorrectly." & @CRLF _                  & "  2. You are trying to access a Novell Server. This utility does not support Novell Print Servers." & @CRLF _                  & "  3. There are no printers shared on the Windows Print Server you selected.")         Return ('')     EndIf     $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer", "WQL", _             $wbemFlagReturnImmediately + $wbemFlagForwardOnly)         _GUICtrlListViewDeleteAllItems($hnwd)     If IsObj($colItems) Then         For $objItem In $colItems             _GUICtrlListViewInsertItem($hnwd, -1, $objItem.Caption)             If StringLower($strComputer) <> 'localhost' Then $ret &= '|' & $objItem.Caption             If $iDefault And $objItem.Default == -1 Then GUICtrlSetData($Label1, StringLeft($objItem.Caption, 30))         Next         If $ret <> '' Then IniWrite($IniFile, $strComputer, 'PrinterList', StringTrimLeft($ret, 1))     Else         MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_Printer")     EndIf EndFunc   ;==>_ListPrinters Func _AddPrinter($Server)     ;$Pos = _ChildWindowCenter('Network Printer Utility', 305, 131)     ;ProgressOn('Add Printer', 'Adding Printer', '', $Pos[0], $Pos[1])         _Enumprinters($Server)     $var = ObjGet("LDAP://" & $userdn)         RunWait("rundll32 printui.dll,PrintUIEntry /in /q /n" & $var.uNCName)             _ListPrinters($ListView1)     ProgressOff() EndFunc   ;==>_AddPrinter Func _RemovePrinter($PRINTERSHARE)     $Pos = _ChildWindowCenter('Network Printer Utility', 305, 131)     ProgressOn('Remove Printer', 'Removing Printer', '', $Pos[0], $Pos[1])     For $x = 1 To $PRINTERSHARE[0]         $ret = _GUICtrlListViewGetItemText($ListView1, $PRINTERSHARE[$x])         ProgressSet(Int(($x / $PRINTERSHARE[0]) * 100), $ret)         If StringLeft($ret, 2) == '\\' Then             RunWait(@ComSpec & ' /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /dn /q /n "' & $ret & '"', '', @SW_HIDE) ; Remove Network Printer         Else             RunWait(@ComSpec & ' /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /dl /c\\' & @ComputerName & ' /n "' & $ret & '"', '', @SW_HIDE) ; Remove Local Printer         EndIf     Next     Sleep(3000)     _ListPrinters($ListView1, 1)     ProgressOff() EndFunc   ;==>_RemovePrinter Func _ChangePrinter($PRINTERSHARE)     RunWait(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n " & '"' & $PRINTERSHARE & '"', "", @SW_HIDE)     GUICtrlSetData($Label1, StringLeft($PRINTERSHARE, 30)) EndFunc   ;==>_ChangePrinter Func _ChildWindowCenter($sParentTitle, $ChildWidth, $ChildHeight)     Opt("WinTitleMatchMode", 4)     $taskbar = WinGetPos("classname=Shell_TrayWnd")     $MainGUIsize = WinGetPos($sParentTitle)     $MainGUIsize[0] = ($MainGUIsize[2] - $ChildWidth) / 2 + $MainGUIsize[0]     $MainGUIsize[1] = ($MainGUIsize[3] - $ChildHeight) / 2 + $MainGUIsize[1]     If $MainGUIsize[0] < 0 Then $MainGUIsize[0] = 0     If $MainGUIsize[0] > (@DesktopWidth - $ChildWidth) Then $MainGUIsize[0] = @DesktopWidth - $ChildWidth     If $MainGUIsize[1] < 0 Then $MainGUIsize[1] = 0     If $MainGUIsize[1] > ($taskbar[1] - $ChildHeight) Then $MainGUIsize[1] = $taskbar[1] - $ChildHeight     Return ($MainGUIsize) EndFunc   ;==>_ChildWindowCenter Func GetSource()     Local $sFolder = @DesktopDir & '\' & StringMid(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) + 1, StringInStr(@AutoItExe, ".") - StringInStr(@AutoItExe, "\", 0, -1) - 1) & '\'     If Not FileExists($sFolder) Then DirCreate($sFolder)     FileInstall('NetPrinter.au3', $sFolder, 1)     Exit EndFunc   ;==>GetSource Func _Enumprinters($Printer)     ;     $Found_Users = ""     $H2_Search = GUICreate("Selection", 700, 500, Default, Default, -1, -1)     $h_msg = GUICtrlCreateLabel("Recherche en cours, veuillez patienter", 5, 5, 200, 20)     GUICtrlSetColor(-1, 0xff0000)     GUICtrlSetFont(-1, 10, 800)     $h_LV = GUICtrlCreateListView("éléments trouvés | DN chemin ldap | Nom entier ", 5, 35, 680, 400, $LVS_SHOWSELALWAYS)     _GUICtrlListViewSetColumnWidth($h_LV, 0, 250)     _GUICtrlListViewSetColumnWidth($h_LV, 1, 200)     _GUICtrlListViewSetColumnWidth($h_LV, 2, 250)     $Counter = 0     GUISetCursor(15, Default, $H2_Search)     Local $objCommand = ObjCreate("ADODB.Command")     Local $objConnection = ObjCreate("ADODB.Connection")     $objConnection.Provider = "ADsDSOObject"     $objConnection.Open ("Active Directory Provider")     $objCommand.ActiveConnection = $objConnection     ;msgbox(0,"","<LDAP://"& $DNSdomain & "/" & $userdomain & ">")     Local $strBase = "<LDAP://" & $DNSdomain & "/" & $UserDomain & ">"     Local $strFilter = "(&(objectCategory=printQueue)(cn=*" & $Printer & "*))"     Local $strAttributes = "cn,description,location,distinguishedName"     Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"     ConsoleWrite($strQuery & @CR)     $objCommand.CommandText = $strQuery     $objCommand.Properties ("Page Size") = 100     $objCommand.Properties ("Sort On") = "cn"     $objCommand.Properties ("Timeout") = 30     $objCommand.Properties ("Cache Results") = False     ;$objCommand.Properties ("Asynchronous")= true     $ADS_SCOPE_SUBTREE = 2     $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE     Local $objRecordSet = $objCommand.Execute     While Not $objRecordSet.EOF         $strCN = $objRecordSet.Fields ("cn").value         $strdisplayName = $objRecordSet.Fields ("location").value         $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value         $strinfo=$objRecordSet.Fields ("description").value         $Counter += 1         If $Counter = 2 Then GUISetState(@SW_SHOW, $H2_Search)         If $Counter > 500 Then ExitLoop         GUICtrlCreateListViewItem($strCN & "|" & $strdisplayName & "|" & $strinfo, $h_LV)         $objRecordSet.MoveNext     WEnd     $objConnection.Close     GUISetCursor(2, Default, $H2_Search)     If $Counter > 500 Then         GUICtrlSetData($h_msg, "500 premiers résultats")     Else         GUICtrlSetData($h_msg, "Selectionner")     EndIf     GUICtrlSetColor($h_msg, 0x000000)     $H2_Ok = GUICtrlCreateButton("Ok", 50, 450, 60, 30, $BS_DEFPUSHBUTTON)     $H2_Cancel = GUICtrlCreateButton("Annuler", 200, 450, 60, 30)         ; si rien n'est trouvé     If $Counter = 0 Then         ;MsgBox(0,"Introuvable","groupe introuvable")         GUISwitch($H2_Search)         GUIDelete()         Global $userdn = ""         Return $userdn     EndIf     $MouseDown = 0     ; Si un seul élément trouvé, alors l'assigner automatiquement     If $Counter = 1 Then         GUIDelete($H2_Search)         $UserId = $strCN         $UserName = $strdisplayName         $userdn = $strdistinguishedName         Return $userdn     EndIf     ;     While 1         $msg3 = GUIGetMsg($H2_Search)         If $msg3 = 0 Then ContinueLoop         If $msg3 = $GUI_EVENT_CLOSE Or $msg3 = $H2_Cancel Then             GUISwitch($H2_Search)             GUIDelete()             Global $userdn = ""             Return $userdn         EndIf         If $msg3 = $H2_Ok Then             ; séléction du groupe             $SelectLine = StringSplit(GUICtrlRead(GUICtrlRead($h_LV)), "|")             If $SelectLine[0] = 3 Then                 $UserId = $SelectLine[1]                 $UserName = $SelectLine[3]                 $userdn = $SelectLine[2]                 GUIDelete($H2_Search)                 Return $SelectLine[1]             EndIf         EndIf         ; détection du double click         If $msg3 = $GUI_EVENT_PRIMARYDOWN Then             If $MouseDown = 0 Then                 $MouseDown = TimerInit()             Else                 ; selectionne l'entrée si le second click est executé dans les 400ms                 If TimerDiff($MouseDown) < 400 Then                     ; retrieve selected username                     $SelectLine = StringSplit(GUICtrlRead(GUICtrlRead($h_LV)), "|")                     If $SelectLine[0] = 3 Then                         $UserId = $SelectLine[1]                         $UserName = $SelectLine[3]                         $userdn = $SelectLine[2]                         GUIDelete($H2_Search)                         Return $SelectLine[1]                     EndIf                 EndIf             EndIf         EndIf                 ; Réinitialise le compteur si aucun autre click n'est détécté         If $MouseDown > 0 And TimerDiff($MouseDown) > 400 Then $MouseDown = 0     WEnd EndFunc   ;==>_Enumprinters Func _nomDNS($string)         $objTrans = ObjCreate("NameTranslate")     $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")     $objTrans.Set ($ADS_NAME_TYPE_1779, $string)     ;$objTrans.Set ($ADS_NAME_TYPE_NT4, $string)     $nomdns = $objTrans.Get ($ADS_NAME_TYPE_CANONICAL)     ; $UserObj = ObjGet("LDAP://" & $strUserDN)     $nomdns = StringTrimRight($nomdns, 1)     Return $nomdns EndFunc   ;==>_nomDNS Func MyErrFunc()     $HexNumber = Hex($oMyError.number, 8)         MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _             "err.description is: " & @TAB & $oMyError.description & @CRLF & _             "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _             "err.number is: " & @TAB & $HexNumber & @CRLF & _             "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _             "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _             "err.source is: " & @TAB & $oMyError.source & @CRLF & _             "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _             )     SetError(1)  ; to check for after this function returns     Exit     ; ConsoleWrite($oMyError.description & @cr) EndFunc   ;==>MyErrFunc


next version : edit printers of a machine remotely, easy to do, but no time, sry :/

Edited by arcker, 16 October 2006 - 12:50 PM.

-- Arck System _ Soon --Ideas make everything"La critique est facile, l'art est difficile"Projects :Au3Service = Run your exe as service / Updated 27/05/2011 Get it Here

#19 LogischToch

LogischToch

    Seeker

  • New Members
  • 4 posts

Posted 03 November 2006 - 06:25 PM

You can faster connect printers if you want. In our domain there are more then 30 printers on multiple location. I don't use de Windows DLL to connect the printers but importing 4 registry keys instead.

Default printer:
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows]
"Device"="\\servvername\PrinterShareName,winspool,Ne00:"

PrinterPortnames:
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts]
"PrinterName"="winspool,Ne00:,15,45"

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices]
"Microsoft Office Document Image Writer"="winspool,Ne00:"

[HKEY_CURRENT_USER\Printers\Connections\,,servername,PrinterSharename]
"Server"="\\\\Servername"
"Provider"="win32spl.dll"

Printersettings are stored in
HKEY_CURRENT_USER\Printers\Connections\DevModePerUser and HKEY_CURRENT_USER\Printers\Connections\DevModes2

Al works fine on Citrix en Windows terminal server.
De only problem i have is when i use it in a logon script the defaultprinter in the script is overwritten by an old defaultprinter. Did not have an answer to that. I use it on multiple Citrix-server.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users