Showing posts with label Printer. Show all posts
Showing posts with label Printer. Show all posts

Wednesday, September 22, 2010

Powershell - Setting default printer in the Desktop

In Windows 7 setting a default printer through powershell cmdlets is a easier task when compared to VBscript. It can achieved through fewer commands. The commands and their description are given below

CMDLETS

$Printer = Get-WmiObject win32_printer  | where {$_.name -match "XPS"}
$Printer.SetDefaultPrinter()

"XPS" in the command can be replaced by your printer name , unique word which will exactly point your printer can be mentioned within the quotations  

win32_Printer 

This WMI class will hold all the printer information in your computer

SetDefaultPrinter() 

This method inside Win32_Printer will set the selected printer as a default printer



Tuesday, October 2, 2007

VBScript - Printer - Logging when printer is used

'Script start

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where LogFile='System' and eventcode=10")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Events.CSV")
For Each objEvent in colEvents
strTimeWritten = objEvent.TimeWritten
dtmTimeWritten = CDate(Mid(strTimeWritten, 5, 2) & "/" & _
Mid(strTimeWritten, 7, 2) & "/" & Left(strTimeWritten, 4) _
& " " & Mid (strTimeWritten, 9, 2) & ":" & _
Mid(strTimeWritten, 11, 2) & ":" & Mid(strTimeWritten, 13, 2))
dtmDate = FormatDateTime(dtmTimeWritten, vbShortDate)
dtmTime = FormatDateTime(dtmTimeWritten, vbLongTime)
strDescription = objEvent.Message
strEvent = dtmTime & "," & trim(strDescription)
objFile.WriteLine strEvent
Next
objFile.Close


'Script End

Queries on scripts ? . Open http://orangescripts.blogspot.com and post it.

Thursday, September 27, 2007

VBScript to set default printer in your desktop

'Script Start


Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.SetDefaultPrinter("\\servername\printername")





'Script End



How to execute a VBScript