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?
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.

athapaCEO / 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

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
Computer101Commented:
Forced accept.

Computer101
EE Admin
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
.NET Programming

From novice to tech pro — start learning today.