• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7159
  • Last Modified:

using IWshRuntimeLibrary in C#

Hi Experts,

I would like to know how to use the using WshNetworkClass.....to safely Add Printers and Map a Network Drive.

I have managed to Add a printer passing it "" values for driver & port, although when I try to MapNetworkDrive I don't know what I should be supplying the ref objects?

Can anyone help me with this please...

Thanks in advance.
0
Joesmail
Asked:
Joesmail
  • 3
  • 2
  • 2
1 Solution
 
jagadeesh_motamarriCommented:
0
 
JoesmailAuthor Commented:
To be clearer....I am trying to map a drive using the following library....

using IWshRuntimeLibrary;
...
...
WshNetworkClass network = new  WshNetworkClass();
...
...
network.MapNetworkDrive(_drive,  @"\\" + _server + @"\" + _share,REF OBJECT, REF OBJECT, REF OBJECT);

Can anyone give me some examples of the REFs required here........
0
 
jagadeesh_motamarriCommented:
i guess this works in VBScript. It should successfully map to a network drive
\\server1\data.


Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
sPwd = inputbox("Enter password")
WshNetwork.MapNetworkDrive "J:", "\\server1\data", false,
"xyz_net\John", sPwd
Msgbox "Drives has been mapped successfully"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
JoesmailAuthor Commented:
you guessed wrong.
0
 
gregoryyoungCommented:
In poking around I found some sample code ...

public static void createmappeddrive(string driveletter, string
username, string pass)
{
bool blnUpdateProfile = false;
bool blnForce = true;
object objblnForce = (object)blnForce;
object objblnUpdateProfile = (object)blnUpdateProfile;
object objstrUserName;
object objstrPassword;
string strMapDriveLetter = driveletter + ":";
WshNetworkClass wshNET = new WshNetworkClass();
//"cbcg\\rwma"
objstrUserName = (object)username;
objstrPassword = (object)pass;
wshNET.MapNetworkDrive(strMapDriveLetter, @"\\networklocation\", ref
objblnUpdateProfile,ref objstrUserName, ref objstrPassword);
}


public static void removemapdrive(string driveletter)
{
bool blnUpdateProfile = false;
bool blnForce = true;
WshNetworkClass wshNET = new WshNetworkClass();
object objblnForce = (object)blnForce;
object objblnUpdateProfile = (object)blnUpdateProfile;
string strMapDriveLetter = driveletter + ":";
wshNET.RemoveNetworkDrive(strMapDriveLetter,ref objblnForce,ref
objblnUpdateProfile);
}
0
 
JoesmailAuthor Commented:
Thanks for this gregoryyoung

Just one last question.  Do you know if there is a way around having to PASS the password.  I can identify the username easily enought Environment.Username although I don't know how I would pass the "password" credentials through?
0
 
gregoryyoungCommented:
I would imagine that is if you want to use a different username/pass (without knowing the library). My guess would be that passing null attempts to use your current token (but this is just a guess)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now