Prompt User to choose a Default Printer

Experts,

I would like a batch / VBscript that will look at what printers are installed, and then prompt the user to specify what printer they want to be their default.

Then the user, can "click to pick" the printer in this interface or even "press a number" printer list.
Then close this printer selection interface.

Also,
if no action is taken, it closes after a 60 seconds.
LVL 2
Glenn MSystems Engineer / ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn MSystems Engineer / ManagerAuthor Commented:
I have this, but there are two problems:

1. The width of the dialogue box is crazy big. Second, it would be great after they click "set as default" it actions the change and then closes. I think my statement SetDefault" and "ExitProgram" isn't right, but works fine for  the Exit Button.


<html>
<head>
<title>Specify A Default Printer.</title>
</head>
<SCRIPT LANGUAGE="VBScript">

    Sub Window_Onload
        strComputer = "."

        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

        For Each objPrinter in colPrinters
            strPrinter = objPrinter.Name
            Set objOption = Document.createElement("OPTION")
            objOption.Text = strprinter
            objOption.Value = strPrinter
            AvailablePrinters.Add(objOption)
        Next
    End Sub

    Sub SetDefault
        strPrinter = AvailablePrinters.Value
        Set WshNetwork = CreateObject("Wscript.Network")
        WshNetwork.SetDefaultPrinter strPrinter
        Msgbox strprinter & " is your default printer."
    End Sub

   Sub ExitProgram
        window.close()
    End Sub

sub DoResize
    resize   
    window.resizeTo 100,100
    screenWidth = Document.ParentWindow.Screen.AvailWidth
    screenHeight = Document.ParentWindow.Screen.AvailHeight
    posLeft = (screenWidth - 1700) / 2
    posTop = (screenHeight - 430) / 2     
    move centerscreen
    window.moveTo posLeft, posTop
  end sub

</SCRIPT>

<select size="8" name="AvailablePrinters"></select><p>
<input type="button" value="Set as Default" onClick="SetDefault""ExitProgram">

<body>
    <input id=runbutton type="button" value="Exit" onClick="ExitProgram">
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robberbaron (robr)Commented:
the onClick can only refer to one routine...
<input type="button" value="Set as Default" onClick="SetDefault">

Open in new window

then at the end of the SetDefault routine, add ExitProgram
    Sub SetDefault
        strPrinter = AvailablePrinters.Value
        Set WshNetwork = CreateObject("Wscript.Network")
        WshNetwork.SetDefaultPrinter strPrinter
        Msgbox strprinter & " is your default printer."
        ExitProgram  '<<<now quit the selection
    End Sub

Open in new window

0
oBdACommented:
Would you be interested in an AutoIt solution (https://www.autoitscript.com) that you could "compile" into a stand-alone exe?
0
Glenn MSystems Engineer / ManagerAuthor Commented:
I was able to resolve it with these changes:

<html>
<head>
<title>Printers</title>
</head>
<FONT FACE="Calibri"</FONT>
<font size="4" color="GhostWhite"><b>Choose a <u>Default</u> printer for App:</b></center>
  <DIV ID="HScroll" STYLE="Position:absolute;Width:400;Height:18;Left:100;Top:100;">
   <DIV ID="HScrollMax" STYLE="Position:absolute;"></DIV>
  </DIV>
 </BODY>

<HTA:APPLICATION
SCROLL="no"
BORDER="thin"
BORDERSTYLE="dialog"
version="1.0"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"/>

<body bgcolor="#3399FF">

<SCRIPT LANGUAGE="VBScript">

On Error Resume Next 
Sub Window_onLoad
	window.resizeTo 274,380
    strComputer = "."
    

        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

        For Each objPrinter in colPrinters
            strPrinter = objPrinter.Name
            Set objOption = Document.createElement("OPTION")
            objOption.Text = strprinter
            objOption.Value = strPrinter
            AvailablePrinters.Add(objOption)
        Next
    End Sub

    Sub SetDefault
    	strPrinter = AvailablePrinters.Value
        Set WshNetwork = CreateObject("Wscript.Network")
        WshNetwork.SetDefaultPrinter strPrinter
        window.close()
    End Sub


</SCRIPT>
<select size="14" name="AvailablePrinters"></select><p>
<input type="button" value=" Apply & Exit " onClick="SetDefault">
</body>
</html>

Open in new window

0
hdhondtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.