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.
LVL 10
JoesmailAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

Jagadeesh MBig Data and Splunk ArchitectCommented:
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........
Jagadeesh MBig Data and Splunk ArchitectCommented:
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"
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

JoesmailAuthor Commented:
you guessed wrong.
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);
}

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
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?
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)
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
Programming

From novice to tech pro — start learning today.