Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Installing Remote TCP/IP Printer via VB.NET

$
0
0
I'm trying to write an application that allows our administrators to install a printer onto a Win 7 PC remotely.

So far what I have works perfectly to install a printer on my computer. But when I run it from another user's I get incorrect argument errors. I'm not sure if I should be posting this on Microsoft's forums since it uses their printui.dll and PrintUIEntry, but I thought someone might've had some experience working with this.

Also, if you have any recommendations on how to do this in an easier manner, please feel free to interject. I'm all self-taught and I am still learning.

Here's my Code:


Private Sub btnInstall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstall.Click
        If Me.txtComputerName.Text <> Nothing Or Me.txtIPAddress.Text <> Nothing Or Me.txtPrinterName.Text <> Nothing Then
            Dim objWriter As New System.IO.StreamWriter("\\" & Me.txtComputerName.Text & "\C$\Temp\InstallPrinter.bat")

            objWriter.WriteLine("@echo off")
            objWriter.WriteLine("cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -s " & Me.txtComputerName.Text & " -a -r " & Me.txtIPAddress.Text & " -h " & Me.txtIPAddress.Text & " -o raw -n 9100 -me")
            objWriter.WriteLine("pause")
            objWriter.WriteLine("rundll32 printui.dll,PrintUIEntry /ia /c\\" & Me.txtComputerName.Text & " /m " & ControlChars.Quote & PrntDriver & ControlChars.Quote & " /h " & ControlChars.Quote & OSVer & ControlChars.Quote & " /f \\" & Me.txtComputerName.Text & "\C$\windows\inf\ntprint.inf")
            objWriter.WriteLine("echo Driver Installed Successfully...")
            objWriter.WriteLine("pause")
            objWriter.WriteLine("rundll32 printui.dll,PrintUIEntry /if /b " & ControlChars.Quote & Me.txtPrinterName.Text & ControlChars.Quote & " /c\\" & Me.txtComputerName.Text & " /f \\" & Me.txtComputerName.Text & "\C$\windows\inf\ntprint.inf" & "/r " & ControlChars.Quote & Me.txtIPAddress.Text & ControlChars.Quote & " /m " & ControlChars.Quote & PrntDriver & ControlChars.Quote)
            objWriter.WriteLine("echo Printer Installed Successfully...")
            objWriter.WriteLine("pause")
            objWriter.Close()


            Shell("\\" & Me.txtComputerName.Text & "\C$\Temp\InstallPrinter.bat")

            Call Form1.ShowButtons()
            Me.Close()
        Else
            MessageBox.Show("Please fill in all fields.")
        End If

    End Sub



Thanks!
-Scynic

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>