C# – Mapped Network drive couldn’t access using WMI

cmappingwinformswmi

I have two machines, Say Machine1 and Machine2. I have mapped one shared folder in Machine2 in Machine1 as Z.
I started one application say App1 which list all drives of machine and the application is in Machine1. I started this App1 from Machine1 and I got all my drives
Including the mapped drive 'Z'. But when I Started the App1 which is in Machine1 from Machine2 using WMI [Windows Management Instrumentation. Code used for WMI communication is given below.]. App1 lists all drives except the mapped network drive 'Z'.
Is there any possible way to list out all drives of Machine1 even if I start App1 from Machine2 using WMI.

// Code to start application on remote machine.
ManagementPath path =     new ManagementPath( string.Format( @"\\{0}\root\cimv2:Win32_Process", machine ) );
try
{
    // Connect options include user name and password of the remote machine to connect.
    ConnectionOptions options = new ConnectionOptions();
    options.Username = UserName;
    options.Password = Password;

    ManagementPath path =  new ManagementPath( string.Format( @"\\{0}\root\cimv2:Win32_Directory", machine ) );
    ManagementScope scope = new ManagementScope( path, options );
    if( scope != null )
    {
        ObjectGetOptions getOptions = new ObjectGetOptions();
        ManagementClass cimInstance = new ManagementClass( scope, path, getOptions );

        // Fill the necessary parameters for Create method of Win32 Process.
        ManagementBaseObject inParams = cimInstance.GetMethodParameters( "Create" );

        // Commandline is the full path of the application including the exe name.
        inParams["CommandLine"] = commandLine;

        // Execute the method and obtain the return values.
        cimInstance.InvokeMethod( "Create", inParams, null );
    }
}

Me trying using .Net 2.0 Windows.

Best Answer

Mapped drives are a per-user setting. When you run the app from the other machine, it probably uses a different user account.

Related Topic