gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

w32prn-customize.el


From: Bruce_Ingalls
Subject: w32prn-customize.el
Date: Thu, 29 Sep 2005 00:55:17 GMT

;;;w32prn-customize.el --- VBscript wrap imports w32 printer ports to customize
;;-*- Mode: Emacs-Lisp -*-      ;Folding-Mode: C-c @ C-o to show all.
;; Time-stamp: <2005-09-28 20:21:04 bingalls>
;; $Id:$

;;__________________________________________________________________________
;;; Legal:
;;Copyright © 2005 Bruce Ingalls
;;This file is not (yet) part of Emacs nor XEmacs. See file COPYING for license
;;Next version will be part of EMacro. GPL license also at http://www.gnu.org

;;; Version 2005-9alpha
(defconst w32prn-customize-version "2005-9alpha")

;;__________________________________________________________________________
;;{{{   Commentary
;;Requires MS Windows 2000 or higher, for VBScript support.
;;Lists default printer port and recognized printer ports by calling the
;;scripts getDefaultPrn.vbs & getAllPrn.vbs in the current path
;;
;;You should be able to use this, by invoking
;;      (require 'lpr)
;;      (w32prn-customize)

;;;Bugs:
;;w32prn-default() & w32prn-all work, as intended.
;;I need help with customize.
;;The w32prn-customize defun might not be quite right.
;;Also, w32prn-all does not yet populate a list of customize options.

;;; Keywords: w32, vbscript, printer, customize
;;; Author: Bruce Ingalls
;;; URL: http://emacro.sourceforge.net/
;;; History:
;;; Change Log: 2005-9-28 created

;;__________________________________________________________________________
;;}}}
;;{{{   Code


;;__________________________________________________________________________
;;}}}
;;{{{   w32prn-customize
(defun w32prn-customize()
  "Set `printer-name' to w32 default printer. This code might not work."
  (customize-set-value 'printer-name (w32prn-default))
  (customize-save-variable))

;;__________________________________________________________________________
;;}}}
;;{{{   w32prn-default
(defun w32prn-default()
  "Calls .\getDefaultPrn.vbs on w2k or newer, returning default printer port."
  (let ((buf (get-buffer-create "*w32prn-customize*")))
    (set-buffer buf)
    (erase-buffer)
    (call-process "cscript.exe" nil buf nil "//nologo" ".\\getDefaultPrn.vbs")
    (end-of-line)
    (buffer-substring (point-min) (point))))

;;__________________________________________________________________________
;;}}}
;;{{{   w32prn-all
(defun w32prn-all()
  "Calls .\getAllPrn.vbs on w2k or newer, setting \n delimited ports in
w32prn-all. This provides a list for `customize' to choose from. Customize
code to be provided in future."
  (let ((buf (get-buffer-create "*w32prn-customize*")))
    (set-buffer buf)
    (erase-buffer)
    (call-process "cscript.exe" nil buf nil "//nologo" ".\\getAllPrn.vbs")

    (goto-char (point-min))
    (end-of-buffer)
    (buffer-substring (point-min) (point))
    ;;(split-string prn)
    ))

;;__________________________________________________________________________
;; Local variables:
;; folded-file: t
;; folding-internal-margins: nil
;; end:

(provide 'w32prn-customize)
;;}}} w32prn-customize.el ends here

______________________________ cut here ______________________________

' getDefaultPrn.vbs
' Prints the default printer port. For use with Emacs
' Copyright 2005 Bruce Ingalls

' Modified from
' 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__printers_and_printing.asp
' 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Default = True")
For Each objPrinter in colInstalledPrinters
     Wscript.Echo objPrinter.PortName
Next

'Other interesting attributes:
'     Wscript.Echo "name " + objPrinter.Name
'     Wscript.Echo "port " + objPrinter.PortName
'     Wscript.Echo "server " + objPrinter.ServerName
'     Wscript.Echo "location " + objPrinter.Location
'     Wscript.Echo "shareName " + objPrinter.ShareName
'     Wscript.Echo "systemName " + objPrinter.SystemName

'     If objPrinter.Network then
'        Wscript.Echo "net = true"
'     End If

'     If objPrinter.Local then
'        Wscript.Echo "local = true"
'     End If

______________________________ cut here ______________________________

' getDefaultPrn.vbs
' Prints all known printer ports. For use with Emacs
' Copyright 2005 Bruce Ingalls

' Modified from
' 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__printers_and_printing.asp
' 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo objPrinter.PortName
Next



 



-- 
Sent by bruce.ingalls from gmail element  from com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]