select directory on remote machine using WMI

C

CosminB [BRT]

Hi,

How can this be done? I've searched the internet for a solution to this
problem, and can't find a clear answer. I need to be able to browse a
remote computer's filesystem, using a certain user and password, and
select a storage location (for some files to be created later). I've
seen that WMI has Win32_Directory, but I don't know how find which
files are contained in a specific directory. I was thinking of using a
query select which would filter from all entries, only the ones that
are in a specific directory, but I don't know how. Is there
documentation for the WMI Query Language?

Hope someone can help...

Thanks in advance,
Cosmin.
 
W

Willy Denoyette [MVP]

| Hi,
|
| How can this be done? I've searched the internet for a solution to this
| problem, and can't find a clear answer. I need to be able to browse a
| remote computer's filesystem, using a certain user and password, and
| select a storage location (for some files to be created later). I've
| seen that WMI has Win32_Directory, but I don't know how find which
| files are contained in a specific directory. I was thinking of using a
| query select which would filter from all entries, only the ones that
| are in a specific directory, but I don't know how. Is there
| documentation for the WMI Query Language?
|
| Hope someone can help...
|
| Thanks in advance,
| Cosmin.
|

The docs for WMI are in the Platform SDK documnetation and in the MSDN
library.
Question is why you want to use WMI for this?

Willy.
 
W

Willy Denoyette [MVP]

|I thought this is the way to go... any other ideas?

No, this is one way to go but maybe not the best.
The DirectoryInfo class accepts a UNC path like \\\\MyServer\\MyShare, so
you may use this one to connect/access a remote share or drive. Sure you
need access privileges to the remote resource, but this can be achieved by
1) impersonation or 2) by establishing a network session with the resource.
Option 2 is simple, just issue a 'net use ...' command (from the commandline
or using Process.Start), specifying the network path and the credentials
needed. Option 1 is more involving and wight not work if the client is
running W2K, basically you have to retrieve an access token by calling
LogonUser through PInvoke specifying the credentials for which you want to
obtain a token, use this token to Impersonate. Search MSDN for a sample
(look for LogonUser).

Willy.
 
C

CosminB [BRT]

Willy said:
|I thought this is the way to go... any other ideas?

No, this is one way to go but maybe not the best.
The DirectoryInfo class accepts a UNC path like \\\\MyServer\\MyShare, so
you may use this one to connect/access a remote share or drive. Sure you
need access privileges to the remote resource, but this can be achieved by
1) impersonation or 2) by establishing a network session with the resource.
Option 2 is simple, just issue a 'net use ...' command (from the commandline
or using Process.Start), specifying the network path and the credentials
needed. Option 1 is more involving and wight not work if the client is
running W2K, basically you have to retrieve an access token by calling
LogonUser through PInvoke specifying the credentials for which you want to
obtain a token, use this token to Impersonate. Search MSDN for a sample
(look for LogonUser).

Willy.

I need to be sure it works on W2K also. As for option 2, I need to be
able to select any drive the remote host has... anyway, I've found a
way, with WMI, like this:

SELECT * FROM CMI_LogicalFile WHERE Path="\\somepath\\" AND Drive="X:"

and the drives, I get them with:

SELECT * FROM CMI_LogicalDisk

I don't mind doing a little extra work, but this seems fine, I hope it
will work well.

Thanks for the quick replies,
Cosmin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top