xmen
xmen

Reputation: 1967

WNetGetConnection and run as admin

I need to call WNetGetConnection to get the UNC path and it works good when application run as standard user but it returns 1201(ERROR_CONNECTION_UNAVAIL) error code when application run as admin. According to the documentation its working as expected.

If the network connection was made using the Microsoft LAN Manager network, and the calling application is running in a different logon session than the application that made the connection, a call to the WNetGetConnection function for the associated local device will fail. The function fails with ERROR_NOT_CONNECTED or ERROR_CONNECTION_UNAVAIL. This is because a connection made using Microsoft LAN Manager is visible only to applications running in the same logon session as the application that made the connection. (To prevent the call to WNetGetConnection from failing it is not sufficient for the application to be running in the user account that created the connection.)

that means its not possible at all to get the UNC path from the app running as admin ? Is there some other way ?

Upvotes: 1

Views: 2387

Answers (2)

Bilbo
Bilbo

Reputation: 380

Network connections cannot normally be shared across different Windows login sessions. This is regardless of admin account / elevation level. Each Windows login or impersonation session needs to create its own network connections.

Upvotes: 0

Jonathan Potter
Jonathan Potter

Reputation: 37192

This is by design. Network shares created by a non-elevated account are not visible under elevation, and vice versa.

See this question on Super User for discussion of the issue. There is apparently a registry setting that enables mapped drives to be shared between elevated and non-elevated accounts but I've never tried it myself.

Upvotes: 2

Related Questions