473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

WSHNetwork.AddWindowsPrinterConnection in VB.NET


I have the following code snippit written in VB.NET to
map a network drive to the local machine. This works
perfectly and throws the proper exceptions when the
parameters are wrong or unreachable .. no problem.

'begin code
Imports IWshRuntimeLibrary
Public Sub MapDrive()
Dim oNet As New WshNetwork()
oNet.MapNetworkDrive("D:","\\Server\Data")
oNet = Nothing
End Sub
'end code

Now, whenever I try to run this code below to map a
printer, I get:
"An unhandled exception of
type 'System.NullReferenceException' occurred in
AppName.exe Additional information: Invalid Pointer"

The Exception stops with the AddWindowsPrinterConnection
line highlighted.

As far as I can tell, the code is fine. The code works
perfectly in WSH. Is there an incompatibility between
VB.NET and the WshRuntimeLibrary? If I can't do it this
way, is there another way to install a network based
printer to the machine where the application is running?

'begin code
Imports IWshRuntimeLibrary
Public Sub MapPrinter()
Dim oNet as New WshNetwork()
oNet.AddWindowsPrinterConnection("\\Server\Printer ")
oNet = Nothing
End Sub
' end code

Thanks!
Craig Matthews

Jul 21 '05 #1
0 5286

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Alex Ang | last post by:
I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data. Dim WshNetwork Set WshNetwork =...
5
by: Aaron_TekRecycle.com | last post by:
Someone must have done this before?!? I have VBS code that will Enumerate all the Printers in the AD and Add the Printer Connection to the client... I'm just not a web developer so I need some...
1
by: Christian-Josef Schrattenthaler | last post by:
Hi! I have a batch-file (*.bat) which logon the client to our server, including printer and drive mappings. Now I want to replace the batch-file with a script for the windows scripting host,...
1
by: Mullin Yu | last post by:
I want to know can I add printer programatically? E.g. I want to create a File Printer to a specify local port, say, C:\test\test.prn with the name as FilePrinter Can I do so? Thanks! ...
0
by: Craig Matthews | last post by:
I have the following code snippit written in VB.NET to map a network drive to the local machine. This works perfectly and throws the proper exceptions when the parameters are wrong or unreachable...
3
by: ctbfalcon | last post by:
So I have a progress bar that I would like to be diplayed as the program is working on adding a network printer. I want to do this because while the program is "thinking" the user is not sure if...
8
rcollins
by: rcollins | last post by:
I am not sure if I am in the right place, but maybe someone can help me anyway. I am trying to map a printer by using the IP address in my logon script. I had it set up from the print server...
0
by: neo3114 | last post by:
I am trying to use a web page on our local intranet running on IIS server to add printers the following is the vbs Function addPrint(pname) Set WshNetwork = CreateObject("WScript.Network") ...
0
by: Riannon | last post by:
Have a new domain with users from 2 different location and only want 1 script. Have started a login script that should be based on what OU the user is located in. Here is what i have done that is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.