My first VB.Net project

I am new to Visual Basic.net 2005 so please bear with me.  I am tring to create an exe that is executed from a web page.  When the exe is used it will map printer's for the user off of our network.  I had this working in regular VB but do not know how to convert the code.  Can someone lead me in the right directions.  I know I need to do some inheiting things but not sure how to do this.

My questions:
1.) Should I be using WshNetwork and if so what reference does it need and how do you add it?
2.) How do I get the project to run?
Like I said I am very new to this.



My Form (frmAddPrinter):
Option Strict Off
Option Explicit On
 
Public Class frmAddPrinters
    Inherits System.Windows.Forms.Form
 
    Private Sub frmAddPrinters_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Add_AR_Printers()
        Me.Close()
 
    End Sub
End Class
 
My Module(ModPrinter):
Module modPrinter
 
    Public Sub Add_AR_Printers()
        'Dim WScript As New WshNetwork
        Dim objWshN As New IWshRuntimeLibrary.WshNetwork
        Dim strPrinterPath As String
 
        'Set objWshN = WScript.CreateObject("WScript.Network")
 
 
        strPrinterPath = "\\Ho000xstls01\HO000XP11-011"
        'objWshN.AddWindowsPrinterConnection strPrinterPath
        objWshN.AddWindowsPrinterConnection(strPrinterPath)
 
        strPrinterPath = "\\HO000XSTLS01\HO000XP11-006"
        'objWshN.AddWindowsPrinterConnection strPrinterPath
        objWshN.SetDefaultPrinter(strPrinterPath)
 
        strPrinterPath = "\\HO000XSTLS01\HO000XP11-007"
        objWshN.AddWindowsPrinterConnection(strPrinterPath)
 
        strPrinterPath = "\\HO000XSTLS01\HO000XP11-014"
        objWshN.AddWindowsPrinterConnection(strPrinterPath)
 
 
        MsgBox("Finished Printer Connections!", MsgBoxStyle.Information, "Printers Installed")
    End Sub
End Module

Open in new window

flfmmqpAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
athapaConnect With a Mentor CEO / CTOCommented:
Add this somewhere in your class

<System.Runtime.Interop.Dllimport("winspool.drv")> _
public shared function AddPrinterConnection(PrinterName as string) as boolean
end function

<System.Runtime.Interop.Dllimport("winspool.drv")> _
public shared function SetDefaultPrinter(PrinterName as string) as boolean
end function

replace
    objWshN.AddWindowsPrinterConnection strPrinterPath
with
   AddPrinterConnection(strPrinterPath)
and replace
    objWshN.SetDefaultPrinter(strPrinterPath)
with
   SetDefaultPrinter(strPritnerPath)

You should check the return value of both functions to make sure both calls were successful.


If you don't want to use pinvoke and would like to use WSH objects as in your old code then do this
Replace
     Set objWshN = WScript.CreateObject("WScript.Network")
with
    dim  objWshN  as object = Microsoft.VisualBasic.CreateObject("WScript.Network")
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
All Courses

From novice to tech pro — start learning today.