Jump to content

Printer Per Machine


Dustinorange
 Share

Recommended Posts

Hello-

I've finally wrote my first script using this code, a friend of mine introduced me to it. This script will add a network printer to a networked computer for all users that log into the machine. No more adding it for each individual user :) Enjoy!

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3

#Region ### START Koda GUI section ### Form=c:\users\dorange\desktop\koda_1.7.3.0\forms\form1.kxf


Opt("GUIOnEVentMode", 1) ;Turns on Gui Event mode

$Form1_1 = GUICreate("Printer Per Machine v1.0", 269, 217, 728, 423) ;Title

$ComputerName = GUICtrlCreateLabel("Computer Name", 16, 32, 77, 17) ;Computer Name Button

$PrinterName = GUICtrlCreateLabel("Printer Name", 24, 80, 62, 17) ;Computer Name Button

$ServerName = GUICtrlCreateLabel("Server Name", 24, 128, 63, 17)


$Computer = GUICtrlCreateInput("", 96, 32, 137, 21) ;Computer name Input

GUICtrlSetTip(-1, "Type In The Computer Name")

$Printer = GUICtrlCreateInput("", 96, 80, 137, 21) ;Printer name Input

GUICtrlSetTip(-1, "Type In The Printer Name")

$Server = GUICtrlCreateInput("", 96, 128, 137, 21)

GUICtrlSetTip(-1, "Type In The Server Name")



$Add = GUICtrlCreateButton("Add", 40, 176, 65, 25) ;Add Button

GUICtrlSetTip(-1, "Adds Printer For All Users")

GUICtrlSetOnEvent($Add, "Add")



$Delete = GUICtrlCreateButton("Delete", 144, 176, 73, 25) ;Delete Button

GUICtrlSetTip(-1, "Deletes Printer For All Users")

GUICtrlSetOnEvent($Delete, "Delete")



GUISetState(@SW_SHOW)



GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

#EndRegion ### END Koda GUI section ###



While 1

Sleep(100)

WEnd



Func CLOSEClicked()

Exit

EndFunc



Func Add() ;Adds the printer



$aComputer = GUICtrlRead ($Computer, 1) ;Reads input from variable $Computer

$aPrinter = GUICtrlRead ($Printer, 1) ;Reads input from variable $Printer

$aServer = GuiCtrlRead ($Server, 1)



Run("rundll32 printui.dll PrintUIEntry /ga /c\\"&$aComputer&" /n\\"&$aServer&"\"&$aPrinter)

SplashTextOn("Printer Per Machine", "Adding Printer, Please Wait...", 150, 75)

Sleep(5000)

;_RunDos("start /wait sc stop spooler")

Sleep(5000)

SplashOff()

;_RunDos("start /wait sc start spooler")

MsgBox(0, "Printer Per Machine", "Added Successfully!")

EndFunc



Func Delete()



$aComputer = GUICtrlRead ($Computer, 1) ;Reads input from variable $Computer

$aPrinter = GUICtrlRead ($Printer, 1) ;Reads input from variable $Printer

$aServer = GuiCtrlRead ($Server, 1)



Run("rundll32 printui.dll PrintUIEntry /gd /c\\"&$aComputer&" /n\\"&$aServer&"\"&$aPrinter)

SplashTextOn("Printer Per Machine", "Deleting Printer, Please Wait...", 150, 75)

Sleep(5000)

;_RunDos("start /wait sc stop spooler")

Sleep(5000)

SplashOff()

;_RunDos("start /wait sc start spooler")

MsgBox(0, "Printer Per Machine", "Deleted Successfully!")

EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...