Jump to content
Can't remember your login details? Read more... ×


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Serf

About s3069260

  • Rank
  1. s3069260

    vbs - default printer

    Hi All, I'm looking for a way to determine the default printer name for every user in a large AD enterprise. The only thing i have come up with is a vb script to append to a text file upon logon. This will cause alot of repeatition, but it'll do. I'm really not much of a programmer, so don't expect too much. A few google searches later and I have this. Which will give me the name of the default printer on this machine. strComputer = "." Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colPrinters = objWMIService.ExecQuery _ ("Select * From Win32_Printer Where Default = TRUE") For Each objPrinter in colPrinters Wscript.Echo objPrinter.ShareName Next I also have this, which will create/append to a file when given a UNC path. However I need to merge the two (placing teh printer name within the file) and add the username of the logged on user. ' NewTextEC.vbs ' Sample VBScript to write to a file. With added error-correcting ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 1.5 - August 2005 ' ---------------------------------------------------------------' Option Explicit Dim objFSO, objFolder, objShell, objTextFile, objFile Dim strDirectory, strFile, strText strDirectory = "\\servername\share\folder" strFile = "\defaultprinters.txt" strText = "MiscText" strComputer = "." ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) WScript.Echo "Just created " & strDirectory End If If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile(strDirectory & strFile) Wscript.Echo "Just created " & strDirectory & strFile End If set objFile = nothing set objFolder = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 8 Set objTextFile = objFSO.OpenTextFile _ (strDirectory & strFile, ForAppending, True) ' Writes strText every time you run this VBScript objTextFile.WriteLine(strText) ' Bonus or cosmetic section to launch explorer to check file If err.number = vbEmpty then Set objShell = CreateObject("WScript.Shell") objShell.run ("Explorer" &" " & strDirectory & "\" ) Else WScript.echo "VBScript Error: " & err.number End If WScript.Quit ' End of VBScript to write to a file with error-correcting Code Finally, I have the code for finsind the username. Here is where we extract the UserName Set objNetwork = WScript.CreateObject("WScript.Network") strUserName = objNetwork.UserName Any help anyone can make would be great.