Jump to content

Search the Community

Showing results for tags 'Printer'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 13 results

  1. Version 3.1.0

    651 downloads

    Here is an UDF for managing printers. Features are : - add, remove or rename a printer - add or remove a driver - add or remove a TCP/IP printer port - add or remove a LPR printer port - connect to a remote printer - enum printers and there configuration and properties - pause resume or cancel all jobs of a printer - checks if a printer exists - print a test page - set the default printer
  2. This is a very simple sample about checking printer status and set its online/offline status.may help those who in need of this issue. $StrComputer="." $obj=ObjGet("winmgmts:\\"&$StrComputer&"\root\CIMV2") $colitems=$obj.ExecQuery("Select * from Win32_Printer") For $objitem In $colitems If $objitem.Caption=="SHARP AR-1808S" Then $a=Int($objitem.Attributes / 1024) If Mod($a, 2)=0 Then MsgBox(0,0,"Printer is online",8) ElseIf Mod($a, 2)=1 Then MsgBox(0,0,"Printer is offline,press 'OK'button To make the printer online ",8) ;core code $objitem.WorkOffline = False $objitem.Put_ ;~~~~~~~~~~~~~~~~~~~~~~ MsgBox(0,'','Printer is online now.') Else MsgBox(0,0,"unknown status",8) EndIf EndIf next
  3. I am trying to print using a small font, but no mater how I try it, the printed font remains unchanged. I have created a sample script that sets the font to 8. Here are the functions I use to create, then set the font: Func _Printer_SetFont($hDC) Local $hFont If ($a__Printer_Font == 0) Then _Printer_MakeFont() EndIf $hFont = $a__Printer_Font _LogMsg("+++: $hDC & " & $hDC & ", $hFont = " & $hFont) _WinAPI_SetFont($hDC, $hFont) ; <===================== EndFunc ;==>_Printer_SetFont Func _Printer_MakeFont() Local $hFontDC, $err, $errm, $str, $flag, $iHeight $flag = $FW_BOLD $iHeight = 8 $hFontDC = _WinAPI_CreateFont( _ $iHeight, _ 0, _ ; average character width 0, _ ; angle of escape 0, _ ; base-line orientation $flag, _ ; font weight - $FW_NORMAL, $FW_BOLD, etc. False, _ ; italic False, _ ; underline False, _ ; strikeout $DEFAULT_CHARSET, _ ; the character set $OUT_DEFAULT_PRECIS, _ ; the output precision $CLIP_DEFAULT_PRECIS, _ ; the clipping precision $DEFAULT_QUALITY, _ ; the output quality 0, _ ; the pitch and family of the font "courier new") ; typeface name _LogMsg("+++: $hFontDC = 0x" & Hex($hFontDC)) If ($hFontDC <= 0) Then $str = "_WinAPI_CreateFont() failed." & @CRLF $err = _WinAPI_GetLastError() $errm = _WinAPI_GetLastErrorMessage() _LogMsg("+++: " & $err & ", 0) - '" & $errm & "'" & @CRLF & $str) Exit (9) EndIf $a__Printer_Font = $hFontDC EndFunc ;==>_Printer_MakeFont Here is the complete script: #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Opt('MustDeclareVars', 1) #include <APIDlgConstants.au3> #include <FontConstants.au3> #include <WinAPI.au3> ; #VARIABLES# ================================================================ Global $i__LastLineNum = -1, $i__NextLineNum = -1, $i__ThisLineNum = -1 Global $i__LeftMargin_X, $i__TopMargin_Y, $i__PageWidth, $i__PageHeight Global $i__CurrentPos_X, $i__CurrentPos_Y Global $i__Printer_Char_H = -1, $i__Printer_Char_W = -1 Global $a__Printer_Font = 0 Global $i__x_start, $i__x_end, $i__y_start, $i__y_end ; ============================================================================ ; #CONSTANTS# ================================================================ Global $PHYSICALWIDTH = 110, $PHYSICALHEIGHT = 111 Global $PHYSICALOFFSETX = 112, $PHYSICALOFFSETY = 113 Const $VLINESPACE = 20 ; Number of pixels between lines Global Const $tagPD = "align 1;DWORD lStructSize;" & "HWND hwndOwner;" & "handle hDevMode;" & "handle hDevNames;" & _ "handle hDC;" & "DWORD Flags;" & _ "WORD nFromPage;" & "WORD nToPage;" & "WORD nMinPage;" & "WORD nMaxPage;" & "WORD nCopies;" & _ "handle hInstance;" & "LPARAM lCustData;" & "ptr lpfnPrintHook;" & "ptr lpfnSetupHook;" & _ "ptr lpPrintTemplateName;" & "ptr lpSetupTemplateName;" & "handle hPrintTemplate;" & "handle hSetupTemplate" Global Const $tagDOCINFO = "int Size;" & "ptr DocName;" & "ptr Output;" & "ptr Datatype;" & "dword Type" ; ============================================================================ _Main() Func _Main() Local $hDC, $str, $str2 = "", $linenum $hDC = _Printer_Open(0, Default, "DOCNAME: ++++") _LogMsg("+++: $hPrintDc = 0x" & Hex($hDC)) If (Not $hDC) Then Exit (1) _Printer_SetFont($hDC) For $y = 1 To 10 $str2 &= "123456789." Next $linenum = 30 ; Start in the middle of the page For $x = 1 To 15 $str = "[" & $x & " " & $str2 _LogMsg("+++: $str ==>" & $str & "<==") _Printer_PrintTextLine($hDC, $str, $linenum) $linenum += 1 Next _Printer_Close($hDC) EndFunc ;==>_Main Func _Printer_SetFont($hDC) Local $hFont If ($a__Printer_Font == 0) Then _Printer_MakeFont() EndIf $hFont = $a__Printer_Font _LogMsg("+++: $hDC & " & $hDC & ", $hFont = " & $hFont) _WinAPI_SetFont($hDC, $hFont) ; <===================== EndFunc ;==>_Printer_SetFont Func _Printer_MakeFont() Local $hFontDC, $err, $errm, $str, $flag, $iHeight $flag = $FW_BOLD $iHeight = 8 $hFontDC = _WinAPI_CreateFont( _ $iHeight, _ 0, _ ; average character width 0, _ ; angle of escape 0, _ ; base-line orientation $flag, _ ; font weight - $FW_NORMAL, $FW_BOLD, etc. False, _ ; italic False, _ ; underline False, _ ; strikeout $DEFAULT_CHARSET, _ ; the character set $OUT_DEFAULT_PRECIS, _ ; the output precision $CLIP_DEFAULT_PRECIS, _ ; the clipping precision $DEFAULT_QUALITY, _ ; the output quality 0, _ ; the pitch and family of the font "courier new") ; typeface name _LogMsg("+++: $hFontDC = 0x" & Hex($hFontDC)) If ($hFontDC <= 0) Then $str = "_WinAPI_CreateFont() failed." & @CRLF $err = _WinAPI_GetLastError() $errm = _WinAPI_GetLastErrorMessage() _LogMsg("+++: " & $err & ", 0) - '" & $errm & "'" & @CRLF & $str) Exit (9) EndIf $a__Printer_Font = $hFontDC EndFunc ;==>_Printer_MakeFont Func _Printer_Open($hGUI = 0, $iFlags = Default, $sDocName = "") Local $hDC, $tPD, $err If $iFlags = Default Then $iFlags = 0 $iFlags = BitOR($iFlags, $PD_RETURNDC) $iFlags = BitOR($iFlags, $PD_USEDEVMODECOPIESANDCOLLATE) EndIf $tPD = DllStructCreate($tagPD) DllStructSetData($tPD, "lStructSize", DllStructGetSize($tPD)) DllStructSetData($tPD, "hwndOwner", $hGUI) ; If $hGUI <> 0 Then DllStructGetData($tPD, "hInstance", _WinAPI_GetModuleHandle("")) EndIf DllStructSetData($tPD, "Flags", $iFlags) DllStructSetData($tPD, "nCopies", 2) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($tPD)) $err = @error If $err Then $err = _WinAPI_GetLastError() Local $errm = _WinAPI_GetLastErrorMessage() _LogMsg("+++: _Printer_Open() returns: (1, " & $err & ", 0) - '" & $errm & "'") $tPD = 0 Return SetError(1, $err, 0) EndIf If $bRet[0] = True Then $hDC = DllStructGetData($tPD, "hDC") Else Return SetError(2, $err, 0) EndIf $tPD = 0 __Printer_SetupCharWH($hDC) _Printer_GetMetrics($hDC) _Printer_Startup($hDC, $sDocName) Return (SetError(0, 0, $hDC)) EndFunc ;==>_Printer_Open Func _Printer_Startup($hDC, $sDocName) Local $oDocNameStruct, $DOCINFO, $printJobID, $errstr __Printer_SetupCharWH($hDC) ; Get the height and width of a printer character $oDocNameStruct = DllStructCreate("char DocName[" & StringLen($sDocName & Chr(0)) & "]") DllStructSetData($oDocNameStruct, "DocName", $sDocName & Chr(0)) ; Size of DOCINFO structure $DOCINFO = DllStructCreate($tagDOCINFO) ; Structure for Print Document info DllStructSetData($DOCINFO, "Size", 20) ; Size of DOCINFO structure DllStructSetData($DOCINFO, "DocName", DllStructGetPtr($oDocNameStruct)) ; Set name of print job (Optional) _Printer_GetMetrics($hDC) $printJobID = _Printer_StartDoc($hDC, $DOCINFO) ; start new print doc If ($printJobID <= 0) Then $errstr = "_Printer_StartDoc() failed" _LogMsg("+++: _Printer_Startup() returns: @error = 1 - " & $errstr) Return (SetError(1, 0, $errstr)) EndIf Return (SetError(0, 0, $printJobID)) ; print job ID EndFunc ;==>_Printer_Startup Func _Printer_Close($hDC) _Printer_EndPage($hDC) ; End the currend page _Printer_EndDoc($hDC) ; End the print job _WinAPI_DeleteDC($hDC) ; Delete the printer device context EndFunc ;==>_Printer_Close Func _Printer_EndPage($hDC) Local $aResult If ($i__ThisLineNum > 1) Then $aResult = DllCall("GDI32.dll", "long", "EndPage", "hwnd", $hDC) EndIf _Printer_SetInitial_XY() $i__ThisLineNum = -1 Return ($aResult[0]) EndFunc ;==>_Printer_EndPage Func _Printer_EndDoc($hDC) Local $aResult $aResult = DllCall("GDI32.dll", "long", "EndDoc", "hwnd", $hDC) Return ($aResult[0]) EndFunc ;==>_Printer_EndDoc Func _Printer_TextOut($hDC, $iXStart, $iYStart, $sString) Local $aResult $aResult = DllCall("GDI32.dll", _ "long", "TextOut", _ "hwnd", $hDC, _ "long", $iXStart, _ "long", $iYStart, _ "str", $sString, _ "long", StringLen($sString)) Return $aResult[0] ; 0 = fail, 1 = OK EndFunc ;==>_Printer_TextOut Func _Printer_PrintTextLine($hDC, $sText, $iLineNumber = -1) Local $ret, $lines, $ndx If ($iLineNumber <= 0) Then $iLineNumber = $i__ThisLineNum EndIf $sText = StringStripWS($sText, 2) ; Clear trailing whitespace ; Break text into an array of lines, based on any of the ; usual line endings (@CR, @LF, etc.) found in the string. $sText = StringRegExpReplace($sText, "[\\][n]", @CR) $sText = StringReplace($sText, @CRLF, @LF) $sText = StringReplace($sText, @CR, @LF) While (StringRight($sText, 1) == @LF) StringTrimRight($sText, 1) ; remove trailing LF's WEnd $lines = StringSplit($sText, @LF, 2) ; Now print each line in the array of lines, advancing the ; printer line position each time For $ndx = 0 To UBound($lines) - 1 $i__CurrentPos_X = $i__x_start ; $i__LeftMargin_X $i__CurrentPos_Y = (($i__Printer_Char_H + $VLINESPACE) * $iLineNumber) + $i__y_start $ret = _Printer_TextOut($hDC, $i__CurrentPos_X, $i__CurrentPos_Y, $lines[$ndx]) $iLineNumber += 1 $i__ThisLineNum += 1 If ($ret == 0) Then ExitLoop If ($iLineNumber > $i__LastLineNum) Then _Printer_EndPage($hDC) $iLineNumber = 1 $i__ThisLineNum = 1 EndIf Next ; Calculate next x/y position $i__CurrentPos_Y = (($i__Printer_Char_H + $VLINESPACE) * $iLineNumber) Return (SetError(0, 0, $iLineNumber)) EndFunc ;==>_Printer_PrintTextLine Func _Printer_StartDoc($hDC, $tDocInfo) Local $aResult $aResult = DllCall("GDI32.dll", "long", "StartDoc", "hwnd", $hDC, "ptr", DllStructGetPtr($tDocInfo)) _Printer_SetInitial_XY() Return ($aResult[0]) ; >0 = OK, <=0 = Fail EndFunc ;==>_Printer_StartDoc Func _Printer_GetMetrics($hDC) $i__LeftMargin_X = _WinAPI_GetDeviceCaps($hDC, $PHYSICALOFFSETX) $i__TopMargin_Y = _WinAPI_GetDeviceCaps($hDC, $PHYSICALOFFSETY) $i__PageWidth = _WinAPI_GetDeviceCaps($hDC, $PHYSICALWIDTH) $i__PageHeight = _WinAPI_GetDeviceCaps($hDC, $PHYSICALHEIGHT) #Tidy_Off _LogMsg("+++:" & @CRLF _ & "$PHYSICALOFFSETX [" & $PHYSICALOFFSETX & "] $i__LeftMargin_X = " & $i__LeftMargin_X & @CRLF _ & "$PHYSICALOFFSETY [" & $PHYSICALOFFSETY & "] $i__TopMargin_Y = " & $i__TopMargin_Y & @CRLF _ & "$PHYSICALWIDTH [" & $PHYSICALWIDTH & "] $i__PageWidth = " & $i__PageWidth & @CRLF _ & "$PHYSICALHEIGHT [" & $PHYSICALHEIGHT & "] $i__PageHeight = " & $i__PageHeight & @CRLF _ ) #Tidy_On $i__x_start = $i__LeftMargin_X - 75 $i__y_start = $i__TopMargin_Y - 75 $i__x_end = $i__PageWidth - 250 $i__y_end = $i__PageHeight - 200 _Printer_SetInitial_XY() $i__LastLineNum = _Printer_GetLastLineNum() EndFunc ;==>_Printer_GetMetrics Func _Printer_SetInitial_XY() $i__CurrentPos_X = $i__LeftMargin_X $i__CurrentPos_Y = $i__TopMargin_Y * 22 EndFunc ;==>_Printer_SetInitial_XY Func _Printer_GetLastLineNum() Local $x1, $y, $linenumber $linenumber = -1 If ($i__Printer_Char_H > 0) Then For $x1 = 1 To 999 $y = (($i__Printer_Char_H + $VLINESPACE) * ($x1 + 1)) If ($y >= $i__y_end) Then $linenumber = $x1 ExitLoop EndIf Next EndIf If ($linenumber == -1) Then MsgBox(0, "Internal Error", "ERROR: Could not calculate the last line number") Exit (1) EndIf $linenumber -= 1 Return ($linenumber) EndFunc ;==>_Printer_GetLastLineNum Func __Printer_SetupCharWH($hDC) Local $vExtents $vExtents = _WinAPI_GetTextExtentPoint32($hDC, "x") $i__Printer_Char_W = DllStructGetData($vExtents, "X") ; Get the width of a character $i__Printer_Char_H = DllStructGetData($vExtents, "Y") ; Get the height of a character EndFunc ;==>__Printer_SetupCharWH Func _LogMsg($msg, $lnum = @ScriptLineNumber) If (StringLeft($msg, 4) = "+++:") Then $msg = StringTrimLeft($msg, 5) $msg = StringStripWS($msg, 3) ConsoleWrite("+++:" & $lnum & "] " & $msg & @CRLF) EndFunc ;==>_LogMsg Func _Printer_SetFont($hDC) Local $hFont If ($a__Printer_Font == 0) Then _Printer_MakeFont() EndIf $hFont = $a__Printer_Font _LogMsg("+++: $hDC & " & $hDC & ", $hFont = " & $hFont) _WinAPI_SetFont($hDC, $hFont) ; <===================== EndFunc ;==>_Printer_SetFont Func _Printer_MakeFont() Local $hFontDC, $err, $errm, $str, $flag, $iHeight $flag = $FW_BOLD $iHeight = 8 $hFontDC = _WinAPI_CreateFont( _ $iHeight, _ 0, _ ; average character width 0, _ ; angle of escape 0, _ ; base-line orientation $flag, _ ; font weight - $FW_NORMAL, $FW_BOLD, etc. False, _ ; italic False, _ ; underline False, _ ; strikeout $DEFAULT_CHARSET, _ ; the character set $OUT_DEFAULT_PRECIS, _ ; the output precision $CLIP_DEFAULT_PRECIS, _ ; the clipping precision $DEFAULT_QUALITY, _ ; the output quality 0, _ ; the pitch and family of the font "courier new") ; typeface name _LogMsg("+++: $hFontDC = 0x" & Hex($hFontDC)) If ($hFontDC <= 0) Then $str = "_WinAPI_CreateFont() failed." & @CRLF $err = _WinAPI_GetLastError() $errm = _WinAPI_GetLastErrorMessage() _LogMsg("+++: " & $err & ", 0) - '" & $errm & "'" & @CRLF & $str) Exit (9) EndIf $a__Printer_Font = $hFontDC EndFunc ;==>_Printer_MakeFont Here is the full script. Run it to see the problem:
  4. So instead of reinventing the wheel. I was trying to find a way auto launch this window to search for printers on the network. we are moving to a more universal naming convention based on printer location so I wanted to give users the easiest way I know of to find and map to a printer. Is there a way to auto launch this window. is it contained somewhere I can access on the computer? thank you for the assistance
  5. Hello everyone, here is my little contribution to AutoIt community. I was looking for a way to print tables from my scripts. None of the solutions was exactly working for me as there were always some limitations. If you need to be able to print table, while making sure that header is printed on each page (if large table), rows won't split up(across several pages) and you want to be able to adjust table size on page or each column size, you in the right place. Also you can choose between landscape and portrait mode It uses a browser to print table out. Simply, it generates a html file which is then open within browser and it initialize print. This version is tested with Chrome browser... Please be aware that there is a bug. When you try to disable row numbers, it will also remove table borders(lines). If anybody can figure out why, it would be appreciated by me and I am sure by others as well. Enjoy Jan UPDATE: found today that geniuses from Google stopped following standards and it no longer prints correctly with Chrome. It also ignores the portrait/landscape settings. However, I tested it with latest IE on Win 7 and it works fine!!! so I suggest you use IE to print... In case you don't have IE as main browser and you do have issues with your current browser then replace shellexecute and winwaitactive at the end of function with: local $hIE=run('"C:\Program Files\Internet Explorer\iexplore.exe" "' & $sFile & '"') ProcessWait($hIE) ; AutoIt Version: 3.3.10 ; Language: English ; Platform: Win ; Author: Jan Zoudlik ; NOTE: big thanks to DoctorDestructo from http://stackoverflow.com/ for main script with css styling etc ; and guinness, tproli, Lupo73 from https://www.autoitscript.com/forum/ for inspiration with their listview to html function ; Script Function: ; table print - example + _table_print function #include <File.au3> Local $aTestArray[4][4] = [[20, 50, 20, 7], ["head", "heading<br/>accross two lines", "heading", "X"],["data row 1",5,"data",6],["data row 2",5&"<br/>"&6,"data",6]] _table_print("test title",100,$aTestArray,True) Func _table_print($Title,$Table_Size,ByRef $2D_array, $Landscape=True, $Row_Numbers=True) ;table that will print as table should (tested with chrome and ie browsers)> header on each page, table cell won't be printed across two pages > so even multi line row will always stay on one page or will be as whole pushed to next page ;to break the line within the cell or heading use "<br/>" not @LF or @CRLF as it is html... if word within cell is wider then column width it will adjust columnm width so word will fit, it will auto(line)break sentance if wider than column ;the allingment withing table is : vertical middle - horizontal left(header is vertical down - horizontal middle) and row numbers are vertical middle - horizontal right... sufficient for me... ;file name automatically generated and saved in temp folder ;Title - self explaining - displayed on the top of the table on first page only ;Table_Size - in percent - how big table(width) should be compare to the paper size so 100 - table will spread accross whole paper printable area, 50 - table size will be approx half of the paper size ;2D_array - row 0, number in percent per each column (width of column) - all together it should add up 100%(97% if row_numbers are used as 3% is used as size for row count column) ;2D_array - row 1, column header - will repeat on each page ;2D_array - row 2-n, data ;$Row_Numbers - first column will contain row number(so there will be one extra column in table) ;$Landscape - to print in landscape or portrait mode... ;paper size is as per printer settings ;font size is set to 10; if adjustment needed for blind people, then search for font-size: 10px; and don't forget to also adjust line-height: 13px accordingly(so it is bigger than font) ;_table_print function CREATED BY Jan Zoudlik ;big thanks to DoctorDestructo from http://stackoverflow.com/ for main script with css styling etc and guinness, tproli, Lupo73 from https://www.autoitscript.com/forum/ for inspiration with their listview to html function $sHTMLTable='<!DOCTYPE html>' & @CRLF & _ '<html>' & @CRLF & _ ' <body>' & @CRLF & _ ' <table ' if $Row_Numbers then $sHTMLTable=$sHTMLTable & 'class="print t1" ' $sHTMLTable=$sHTMLTable & 'width="' & $Table_Size & '%"> <!-- Delete "t1" class to remove row numbers. -->' & @CRLF & _ ' <caption>' & $Title & '</caption>' & @CRLF if $Row_Numbers then $sHTMLTable=$sHTMLTable & ' <col width="3%">' & @CRLF for $column=0 to ubound($2D_array,2)-1 $sHTMLTable=$sHTMLTable & ' <col width="' & $2D_array[0][$column] & '%">' & @CRLF Next $sHTMLTable=$sHTMLTable & ' <thead>' & @CRLF & _ ' <tr>' & @CRLF if $Row_Numbers then $sHTMLTable=$sHTMLTable & ' <th>#</th>' & @CRLF for $column=0 to ubound($2D_array,2)-1 $sHTMLTable=$sHTMLTable & ' <th>' & $2D_array[1][$column] & '</th>' & @CRLF Next $sHTMLTable=$sHTMLTable & ' </tr>' & @CRLF & _ ' </thead>' & @CRLF & _ ' <tbody>' & @CRLF for $row=2 to ubound($2D_array)-1 $sHTMLTable=$sHTMLTable & ' <tr>' & @CRLF if $Row_Numbers then $sHTMLTable=$sHTMLTable & ' <td></td>' & @CRLF for $column=0 to ubound($2D_array,2)-1 $sHTMLTable=$sHTMLTable & ' <td>' & $2D_array[$row][$column] & '</td>' & @CRLF Next $sHTMLTable=$sHTMLTable & ' </tr>' & @CRLF Next $sHTMLTable=$sHTMLTable & ' </tbody>' & @CRLF & _ ' </table>' & @CRLF & _ ' </body>' & @CRLF & _ '</html>' & @CRLF $sCSSstyle='<style>' & @CRLF & _ ' /* THE FOLLOWING CSS IS REQUIRED AND SHOULD NOT BE MODIFIED. */' & @CRLF & _ ' div.fauxRow {' & @CRLF & _ ' display: inline-block;' & @CRLF & _ ' vertical-align: top;' & @CRLF & _ ' width: 100%;' & @CRLF & _ ' page-break-inside: avoid;' & @CRLF & _ ' }' & @CRLF & _ ' table.fauxRow {border-spacing: 0;}' & @CRLF & _ ' table.fauxRow > tbody > tr > td {' & @CRLF & _ ' padding: 0;' & @CRLF & _ ' overflow: hidden;' & @CRLF & _ ' }' & @CRLF & _ ' table.fauxRow > tbody > tr > td > table.print {' & @CRLF & _ ' display: inline-table;' & @CRLF & _ ' vertical-align: top;' & @CRLF & _ ' }' & @CRLF & _ ' table.fauxRow > tbody > tr > td > table.print > caption {caption-side: top;}' & @CRLF & _ ' .noBreak {' & @CRLF & _ ' float: right;' & @CRLF & _ ' width: 100%;' & @CRLF & _ ' visibility: hidden;' & @CRLF & _ ' }' & @CRLF & _ ' .noBreak:before, .noBreak:after {' & @CRLF & _ ' display: block;' & @CRLF & _ ' content: "";' & @CRLF & _ ' }' & @CRLF & _ ' .noBreak:after {margin-top: -594mm;}' & @CRLF & _ ' .noBreak > div {' & @CRLF & _ ' display: inline-block;' & @CRLF & _ ' vertical-align: top;' & @CRLF & _ ' width:100%;' & @CRLF & _ ' page-break-inside: avoid;' & @CRLF & _ ' }' & @CRLF & _ ' /*table.print > thead {white-space: nowrap;}*/ /* Uncomment if line-wrapping causes problems. */' & @CRLF & _ ' table.print > tbody > tr {page-break-inside: avoid;}' & @CRLF & _ ' table.print > tbody > .metricsRow > td {border-top: none !important;}' & @CRLF & _ '' & @CRLF & _ ' /* THE FOLLOWING CSS IS REQUIRED, but the values may be adjusted. */' & @CRLF & _ ' /* NOTE: All size values that can affect an elements height should use the px unit! */' & @CRLF & _ ' table.fauxRow, table.print {' & @CRLF & _ ' font-size: 10px;' & @CRLF & _ ' line-height: 13px;' & @CRLF & _ ' }' & @CRLF & _ '' & @CRLF & _ ' /* THE FOLLvOWING CSS IS OPTIONAL. */' & @CRLF if $Landscape then $sCSSstyle=$sCSSstyle & ' @page {size: landscape;} /* Delete to print in portrait mode*/' & @CRLF if $Row_Numbers then $sCSSstyle=$sCSSstyle & ' body {counter-reset: t1;} /* Delete to remove row numbers. */' & @CRLF & _ ' .noBreak .t1 > tbody > tr > :first-child:before {counter-increment: none;} /* Delete to remove row numbers. */' & @CRLF & _ ' .t1 > tbody > tr > :first-child:before { /* Delete to remove row numbers. */' & @CRLF & _ ' display: block;' & @CRLF & _ ' text-align: right;' & @CRLF & _ ' counter-increment: t1 1;' & @CRLF & _ ' content: counter(t1);' & @CRLF & _ ' }' & @CRLF $sCSSstyle=$sCSSstyle & ' table.fauxRow, table.print {' & @CRLF & _ ' font-family: Tahoma, Verdana, Georgia; /* Try to use fonts that dont get bigger when printed. */' & @CRLF & _ ' margin: 0 auto 0 auto; /* Delete if you dont want table to be centered. */' & @CRLF & _ ' }' & @CRLF & _ ' table.print {border-spacing: 0;}' & @CRLF & _ ' table.print > * > tr > * {' & @CRLF & _ ' border-right: 1px solid black;' & @CRLF & _ ' border-bottom: 1px solid black;' & @CRLF & _ ' padding: 0 3px 0 3px;' & @CRLF & _ ' }' & @CRLF & _ ' table.print > * > :first-child > * {border-top: 1px solid black;}' & @CRLF & _ ' table.print > thead ~ * > :first-child > *, table.print > tbody ~ * > :first-child > * {border-top: none;} ' & @CRLF & _ ' table.print > * > tr > :first-child {border-left: 1px solid black;}' & @CRLF & _ ' table.print > thead {vertical-align: bottom;}' & @CRLF & _ ' table.print > thead > .borderRow > th {border-bottom: none;}' & @CRLF & _ ' table.print > tbody {vertical-align:middle;}' & @CRLF & _ ' table.print > caption {font-weight: bold;}' & @CRLF & _ '</style>' & @CRLF & _ '' & @CRLF & _ '<script>' & @CRLF & _ '' & @CRLF & _ ' (function() { // THIS FUNCTION IS REQUIRED.' & @CRLF & _ ' if(/Firefox|MSIE |Trident/i.test(navigator.userAgent))' & @CRLF & _ ' var formatForPrint = function(table) {' & @CRLF & _ ' var noBreak = document.createElement("div")' & @CRLF & _ ' , noBreakTable = noBreak.appendChild(document.createElement("div")).appendChild(table.cloneNode())' & @CRLF & _ ' , tableParent = table.parentNode' & @CRLF & _ ' , tableParts = table.children' & @CRLF & _ ' , partCount = tableParts.length' & @CRLF & _ ' , partNum = 0' & @CRLF & _ ' , cell = table.querySelector("tbody > tr > td");' & @CRLF & _ ' noBreak.className = "noBreak";' & @CRLF & _ ' for(; partNum < partCount; partNum++) {' & @CRLF & _ ' if(!/tbody/i.test(tableParts[partNum].tagName))' & @CRLF & _ ' noBreakTable.appendChild(tableParts[partNum].cloneNode(true));' & @CRLF & _ ' }' & @CRLF & _ ' if(cell) {' & @CRLF & _ ' noBreakTable.appendChild(cell.parentNode.parentNode.cloneNode()).appendChild(cell.parentNode.cloneNode(true));' & @CRLF & _ ' if(!table.tHead) {' & @CRLF & _ ' var borderRow = document.createElement("tr");' & @CRLF & _ ' borderRow.appendChild(document.createElement("th")).colSpan="1000";' & @CRLF & _ ' borderRow.className = "borderRow";' & @CRLF & _ ' table.insertBefore(document.createElement("thead"), table.tBodies[0]).appendChild(borderRow);' & @CRLF & _ ' }' & @CRLF & _ ' }' & @CRLF & _ ' tableParent.insertBefore(document.createElement("div"), table).style.paddingTop = ".009px";' & @CRLF & _ ' tableParent.insertBefore(noBreak, table);' & @CRLF & _ ' };' & @CRLF & _ ' else' & @CRLF & _ ' var formatForPrint = function(table) {' & @CRLF & _ ' var tableParent = table.parentNode' & @CRLF & _ ' , cell = table.querySelector("tbody > tr > td");' & @CRLF & _ ' if(cell) {' & @CRLF & _ ' var topFauxRow = document.createElement("table")' & @CRLF & _ ' , fauxRowTable = topFauxRow.insertRow(0).insertCell(0).appendChild(table.cloneNode())' & @CRLF & _ ' , colgroup = fauxRowTable.appendChild(document.createElement("colgroup"))' & @CRLF & _ ' , headerHider = document.createElement("div")' & @CRLF & _ ' , metricsRow = document.createElement("tr")' & @CRLF & _ ' , cells = cell.parentNode.cells' & @CRLF & _ ' , cellNum = cells.length' & @CRLF & _ ' , colCount = 0' & @CRLF & _ ' , tbods = table.tBodies' & @CRLF & _ ' , tbodCount = tbods.length' & @CRLF & _ ' , tbodNum = 0' & @CRLF & _ ' , tbod = tbods[0];' & @CRLF & _ ' for(; cellNum--; colCount += cells[cellNum].colSpan);' & @CRLF & _ ' for(cellNum = colCount; cellNum--; metricsRow.appendChild(document.createElement("td")).style.padding = 0);' & @CRLF & _ ' cells = metricsRow.cells;' & @CRLF & _ ' tbod.insertBefore(metricsRow, tbod.firstChild);' & @CRLF & _ ' for(; ++cellNum < colCount; colgroup.appendChild(document.createElement("col")).style.width = cells[cellNum].offsetWidth + "px");' & @CRLF & _ ' var borderWidth = metricsRow.offsetHeight;' & @CRLF & _ ' metricsRow.className = "metricsRow";' & @CRLF & _ ' borderWidth -= metricsRow.offsetHeight;' & @CRLF & _ ' tbod.removeChild(metricsRow);' & @CRLF & _ ' tableParent.insertBefore(topFauxRow, table).className = "fauxRow";' & @CRLF & _ ' if(table.tHead)' & @CRLF & _ ' fauxRowTable.appendChild(table.tHead);' & @CRLF & _ ' var fauxRow = topFauxRow.cloneNode(true)' & @CRLF & _ ' , fauxRowCell = fauxRow.rows[0].cells[0];' & @CRLF & _ ' fauxRowCell.insertBefore(headerHider, fauxRowCell.firstChild).style.marginBottom = -fauxRowTable.offsetHeight - borderWidth + "px";' & @CRLF & _ ' if(table.caption)' & @CRLF & _ ' fauxRowTable.insertBefore(table.caption, fauxRowTable.firstChild);' & @CRLF & _ ' if(tbod.rows[0])' & @CRLF & _ ' fauxRowTable.appendChild(tbod.cloneNode()).appendChild(tbod.rows[0]);' & @CRLF & _ ' for(; tbodNum < tbodCount; tbodNum++) {' & @CRLF & _ ' tbod = tbods[tbodNum];' & @CRLF & _ ' rows = tbod.rows;' & @CRLF & _ ' for(; rows[0]; tableParent.insertBefore(fauxRow.cloneNode(true), table).rows[0].cells[0].children[1].appendChild(tbod.cloneNode()).appendChild(rows[0]));' & @CRLF & _ ' }' & @CRLF & _ ' tableParent.removeChild(table);' & @CRLF & _ ' }' & @CRLF & _ ' else' & @CRLF & _ ' tableParent.insertBefore(document.createElement("div"), table).appendChild(table).parentNode.className="fauxRow";' & @CRLF & _ ' };' & @CRLF & _ ' var tables = document.body.querySelectorAll("table.print")' & @CRLF & _ ' , tableNum = tables.length;' & @CRLF & _ ' for(; tableNum--; formatForPrint(tables[tableNum]));' & @CRLF & _ ' })();' & @CRLF & _ '</script>' $sFile=_TempFile ( @TempDir , "~", ".html" ) ;~ $sFile= @ScriptDir & "\Export.html" $hFile= FileOpen($sFile, 2 + 8) FileWrite($hFile,$sHTMLTable & $sCSSstyle) FileClose($hFile) If @error Then msgbox(0,"Print Error","Failed to close the file!") EndIf ShellExecute($sFile) WinWaitActive(StringTrimLeft($sFile,StringInStr($sFile,"\","",-1))) send("^p") EndFunc ;==>_table_print
  6. This function parser printing-like intervals (like "1,2,3-5") and returns an array with every page number as item. Ex.: "1,2,3-5" will return an array which 0th element is "5" (page count) and the items are 1, 2, 3, 4 and 5. The array is given in the order the $interval parameter is set, and reverse intervals are also supported (e.g.: "8,4,7-5" will return items 8, 4, 7, 6, 5 and 0th element is 5). If it fails, it will return False and set error to non-zero (invalid string). #cs Range parser This function parser printing-like intervals (like "1,2,3-5") and returns an array with every page number as item. @author Jefrey S. Santos <jefrey[at]jefrey.ml> #ce Func rangeparser($interval) $interval = StringReplace($interval, " ", "") If Not StringRegExp($interval, "([0-9\-\,])") Then Return SetError(1, 0, False) $interval = StringSplit($interval, ",") Dim $return[1] For $i = 1 To $interval[0] If StringInStr($interval[$i], "-") Then $split = StringSplit($interval[$i], "-") If $split[0] <> 2 Then Return SetError(1, 0, False) If $split[1] = $split[2] Then ReDim $return[UBound($return)+1] $return[UBound($return)-1] = $split[1] Else If $split[1] < $split[2] Then $step = +1 Else $step = -1 EndIf For $j = $split[1] To $split[2] Step $step ReDim $return[UBound($return)+1] $return[UBound($return)-1] = $j Next EndIf Else ReDim $return[UBound($return)+1] $return[UBound($return)-1] = $interval[$i] EndIf Next $return[0] = UBound($return)-1 Return $return EndFunc
  7. I have searched and searched but cannot find where these are stored. I have scripts to install printers and can even set on as a default. I have it running silent as well. What I need to be able to do is to set the printer to not print out 2 sided and when it is a color printer have it set to print black and white by default. Currently I have tried rewriting the driver with manufacture utilities but this causes the driver to no longer be signed. Also, it is acting up in the 32bit OSs. If I can just use the standard drivers from the manufacturer and set the defaults as noted above I would be set. Anyone know where these settings are in the registry/file/limbo/morodoor? If not, anyone know what is needed to make it happen in the background? With time I am sure I can bring up the dialog box, count the tabs and spaces and make it a series of steps that show but I want no user interaction. Thanks, Tim
  8. I have a question: How to disable automatic search for printers on your local network? Of course I mean the solution, not of operations on the GUI interface, but for example in the system registry. Additional Information. System without a domain. System from XP to Win 8 Notes: I was looking for some and the best I have found so far is a description http://blogs.technet.com/b/networking/archive/2010/12/06/disabling-network-discovery-network-resources.aspx I will be grateful for your help. mLipok
  9. Hi, i'm trying to add a printer with RunAs credentials in a domain environment. I'm loged on as a local user, and in the startupscript it says: runas("administrator","domain","******",1,runwait("rundll32 printui.dll,PrintUIEntry /in /n" & "\\printserver\printername" & " /q")) It will not connect to the domain, and therefor will not install printer.
  10. This is a very simple application to backup a list of your local and network printers to a shared resource. when you restore the printers, the app will just install the printers that were networked. Feel free to improve upon and use. Let me know what you think I have many more applications and I may post more later. #include <File.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Backpath = "\\Myawesomeserver\useraccounts" Global $fp = ($Backpath & @UserName) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Printer Tools", 334, 75, 192, 124) $save = GUICtrlCreateButton("Save Printers", 8, 8, 155, 57) $load = GUICtrlCreateButton("Load Printers", 168, 8, 155, 57) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $save ExportPrinters() Case $load ImportPrinters() EndSwitch WEnd Func ImportPrinters() $File = $fp & "\NetworkPrinters.txt" FileOpen($File, 0) For $i = 1 to _FileCountLines($File) $line = FileReadLine($File, $i) RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /in /n " & $line, "", @SW_HIDE) Next FileClose($File) Msgbox(0, "", "Network Printer Import Complete") endfunc ;==>ImportPrinters Func ExportPrinters() $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $Output = "" $nOutput = "" $objWMIService = ObjGet("winmgmts:\\" & @computername & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems If Stringinstr($objItem.DeviceID, "\\") then $nOutput = $nOutput & $objItem.DeviceID & @CRLF else $Output = $Output & $objItem.DeviceID & @CRLF endif Next FileWrite($fp & "\NetworkPrinters.txt", $nOutput) FileWrite($fp & "\LocalPrinters.txt", $Output) Else FileWrite($fp & "\Printers.txt", "No printers Found") Endif Msgbox(0, "", "Printer Export Complete") EndFunc ;==>ExportPrinters
  11. Use these functions to capture and restore windows network printers. This script was used in a Win XP/7 environment running 2008 R2 servers. Global Const $PrinterList = (@DesktopDir & "printerlist.csv") Func PrinterBackup() Local $csvfile ConsoleWrite($PrinterList & @LF) $csvfile = FileOpen($PrinterList, 10) ; Pull default printer and write it to the first line of the file $objWMI = ObjGet("winmgmts:.rootCIMV2") $colPrinters = $objWMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", 0x10 + 0x20) If IsObj($colPrinters) Then For $objPrinter In $colPrinters If $objPrinter.Default = "True" And $objPrinter.Network = "-1" Then ConsoleWrite("Writing printer " & $objPrinter.Name & @CR) Sleep(500) FileWriteLine($PrinterList, $objPrinter.Name & @CR) EndIf Next EndIf ; Then grab the rest of the printers, if any $objWMI = ObjGet("winmgmts:.rootCIMV2") $colPrinters = $objWMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", 0x10 + 0x20) If IsObj($colPrinters) Then For $objPrinter In $colPrinters If $objPrinter.Network = "-1" And $objPrinter.Default = ("") Then ConsoleWrite("Writing printer " & $objPrinter.Name & @CR) Sleep(500) FileWriteLine($PrinterList, $objPrinter.Name & @CR) EndIf Next EndIf FileClose($csvfile) If FileExists($PrinterList) = 0 Then TrayItemSetState($ItemPrinterRestore, $TRAY_DISABLE) ElseIf FileExists($PrinterList) <> 0 Then TrayItemSetState($ItemPrinterRestore, $TRAY_ENABLE) EndIf EndFunc ;==>PrinterBackup Use this function to restore printers.... Global Const $PrinterList = (@DesktopDir & "printerlist.csv") Func PrinterRestore() Local $PrinterArray[1], $x, $csvfile If FileExists($PrinterList) Then $csvfile = FileReadLine($PrinterList) If Not $csvfile = ("") Then _FileReadToArray($PrinterList, $PrinterArray) For $x = 1 To 1 RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /in /n" & $PrinterArray[$x], "", @SW_HIDE) RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /y /n" & $PrinterArray[$x], "", @SW_HIDE) Next For $x = 2 To $PrinterArray[0] RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /in /n" & $PrinterArray[$x], "", @SW_HIDE) Next EndIf EndIf EndFunc ;==>PrinterRestore
  12. Ok, I'm hoping someone here can spot a problem that I'm missing. I'm in the process of converting all my workstations from printing through a print server to using TCP/IP ports. To make things easier, I'm scripting what I can. The script below is an example of what I'm doing, for an HP LaserJet P3005 and a Color LaserJet 3600. It works beautifully for both on x64, and for the color on x86, but with the p3005 on x86, I get an "Operation could not be completed" error. Since the only differences between the commands seem to be the driver, it would be the likely culprit. But on the same x86 XP box that throws the error, I can manually install that same driver with no problem. I'm attaching the .inf file in case it helps. Also, that box already had a P3005 PCL6 driver, so the /u switch on PrintUIEntry should have ignored the driver path, right? Anybody see something I'm missing? Thanks. InstallPrinter("HS Lobby 1","10.38.124.145","p3005") InstallPrinter("HS Lab Color","10.38.124.181","clj3600") Func InstallPrinter($PrName,$Address,$Driver,$Prompt=0) Local $msg If $Prompt = 1 Then $msg = MsgBox(35,"Question","Install "&$PrName&"?") Sleep(100) If $msg = 2 Then Exit If $msg = 7 Then Return $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $objNewPort = $objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ $objNewPort.Name = "IP_"&$Address $objNewPort.Protocol = 1 $objNewPort.HostAddress = $Address $objNewPort.PortNumber = "9100" $objNewPort.SNMPEnabled = False $objNewPort.Put_ $DriverPath = "\\server\util\drivers\"&@OSArch&"\printers" ;I've removed several of the Cases here for brevity. Select Case @OSArch="x86" AND $Driver="p3005" $LocalPath = $DriverPath & "\ljp3005.pcl6\hpc300xc.inf" $Model = "HP LaserJet P3005 PCL 6" Case @OSArch="x64" AND $Driver="p3005" $LocalPath = $DriverPath & "\ljp3005.pcl6\hpc300xu.inf" $Model = "HP LaserJet P3005 PCL 6" Case @OSArch="x86" AND $Driver="clj3600" $LocalPath = $DriverPath & "\clj3600\hpc3600e.inf" $Model = "HP Color LaserJet 3600" Case @OSArch="x64" AND $Driver="clj3600" $LocalPath = $DriverPath & "\clj3600\hpc3600w.inf" $Model = "HP Color LaserJet 3600" Case $Driver="wc5135" $LocalPath = $DriverPath & "\wc5135.ps\x2WPENP.inf" $Model = "Xerox WorkCentre 5135 PS" Case $Driver="d2150" $LocalPath = $DriverPath & "\d2150.pcl6\dlxrozi.inf" $Model = "Dell 2150cdn Color Printer PCL6" EndSelect RunWait('rundll32 printui.dll,PrintUIEntry /if /b "'&$PrName&'" /f "'&$LocalPath&'" /r "IP_'&$Address&'" /m "'&$Model&'" /u') EndFunchpc300xc.inf.txt
  13. I am trying to add a printer via the network share \\winprint($OS)\$printername But it seems like when the program gets to RegRead(to check if the printer is correctly added) it stops working and I have to exit the script by force. The program running got to be exited via the task manager(Autoit3Wrapper.exe*32) Really need this to work =) $CurrentOS = 0 $Printer = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Start $Printer = GUICtrlRead($Input) If GUICtrlRead(7) = "Windows XP" Then $CurrentOS = 2 ElseIf GUICtrlRead(7) = "Windows Vista" Then $CurrentOS = 2 ElseIf GUICtrlRead(7) = "Windows 7" Then $CurrentOS = 64 EndIf _RunDOS('start \\winprint' & $CurrentOS & '\' & $Printer & '') RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices', '\\winprint' & $CurrentOS & '\' & $Printer & '') If @error Then MsgBox(0, "Error", 'Error' & @error & ' appeared.' & @CRLF & 'Please contact edb@kjemi.uio.no.') Else MsgBox(0, "Done", "Printer should have been added successfully!") EndIf Case $Exit Exit EndSwitch WEnd Kind Regards, Akarillon
×
×
  • Create New...