Hide console when running ManagementClass

I have a GUI application that maps drives to other computers. While the code below works fine I really don't want the console to flesh out for every drive mapping. Also I searched for a solution and found similar question with an answer http://www.experts-exchange.com/Programming/Misc/Q_23506112.html?sfQueryTermInfo=1+consol+hide+managementclass but unfortunately that's not enough for me. Can someone give me more detailed answer, possibly with some code using ManagementClass that hides the console?
Appreciate it


 public static void MapDrive(String ip, String myUser, String myPass)
        {
             String cmdString = "net use \\\\"+ip+"\\C /user:" + myUser + " " + myPass;            
            ManagementClass processClass = new ManagementClass("Win32_Process");        
            object[] methodArgs = { cmdString, null, null, 0 };
            object result = processClass.InvokeMethod("Create", methodArgs);          

        }
RushiiAsked:
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.

Alexandre SimõesManager / Technology SpecialistCommented:
Try it this way:

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("create", cmdString);
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
0
RushiiAuthor Commented:
AlexCode,
I think you got me close..
this line
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("create", cmdString);
didn't work for me, but I found that ProcessStartInfo constructor takes filename and arguments as parameters. So I am guessing I need to run a file that has "cmdString" in it and pass Ip, myUser and myPass as parameters to batch file?.. I have never done this but will try tomorrow. I will report on my progress, shortly.
0
Alexandre SimõesManager / Technology SpecialistCommented:
Hummm... I think I led you wrong mate, sorry.

If you were on a console already, the commend that you would want to execute was:
net use \\192.168.1.66 \C /user:alexcode P@ssw0rd

correct?
Assuming so, the correct code to execute it is:

String cmdString = "use \\\\"+ip+"\\C /user:" + myUser + " " + myPass;
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("net", cmdString);
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);


Try it and let me know.

Cheers!
0
RushiiAuthor Commented:
Alexcode,
well I am not sure how that would work.  I looked up constructor for ProcessStartInfo and it goes like this
public ProcessStartInfo(string fileName, sring arguments)
So what I did is I created a batch file (I had to school myself a little) like this

net use \\%1\c /user:%2 %3
where %1, %2, %3 stand for IP, username, password and used your other code to call this batch file

String args =ip+" "+myUser+" "+myPass;
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("C:\\mapdrive.bat, args);
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
And it worked seamlessly. Thanks for help

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
RushiiAuthor Commented:
Thank you for help
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
C#

From novice to tech pro — start learning today.