Using XmlUriResolver to provide credentials to remote share
up vote
0
down vote
favorite
Thank you in advance for any and all help.
I have seen several post on Stack Overflow and other sites on the net (including Microsoft Docs), but none seeming to help resolve my issue.
I am working on a project that connects to a xml file on a remote file share from WinPE. I have used suggestions from another post on SO about using the XmlUriResolver class to "moderate" success.
The issue I am currently being faced with is either a "Access Denied" error (several attempts to modify the XmlUriResolver.Credentials class) or a complete failure without any reason for failure. I am assuming it is going to be another "Access Denied" error, but my try/catch (Exception e) isn't capturing the reason.
Below is a snippet and relevant part of the method I am trying to implement:
relativeSysData = relativeSysData.Replace(@"", "/");
SysdataXml = $"file://_globaldata.Server/_globaldata.Share/relativeSysData";
XmlUrlResolver XmlResolver = new XmlUrlResolver();
XmlResolver.Credentials = new NetworkCredential(_UserName,
_Password);
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.XmlResolver = XmlResolver;
LogWriter.WriteLogFile((int)LogWriter.EventID.Xml, (int)LogWriter.EventType.Info,
$"Connecting to (remote) System information store at: SysdataXml");
xDoc = XDocument.Load(XmlReader.Create(SysdataXml, xmlSettings));
if (xDoc == null)
LogWriter.WriteLogFile((int)LogWriter.EventID.XmlError, (int)LogWriter.EventType.Error,
$"Unable to connect to the (remote) data store located at: SysdataXml");
deploy = false;
capture = false;
return result;
This part of the method is specific to accessing the remote data. I have a try/catch statement encompassing all of the method.
If I have an open connection to the Network Share, the method will work flawlessly, but will cause the application this application starts to fail - due to an open connection already.
I have a possible alternative to work round this solution but will cost extra lines of code.
Any help in resolving this matter, without resorting to WNetAddConnection() will be gratefully received
Kind Regards
Richie
N.B. I am aware that this is an authentication issue.
c# xml winpe
|
show 12 more comments
up vote
0
down vote
favorite
Thank you in advance for any and all help.
I have seen several post on Stack Overflow and other sites on the net (including Microsoft Docs), but none seeming to help resolve my issue.
I am working on a project that connects to a xml file on a remote file share from WinPE. I have used suggestions from another post on SO about using the XmlUriResolver class to "moderate" success.
The issue I am currently being faced with is either a "Access Denied" error (several attempts to modify the XmlUriResolver.Credentials class) or a complete failure without any reason for failure. I am assuming it is going to be another "Access Denied" error, but my try/catch (Exception e) isn't capturing the reason.
Below is a snippet and relevant part of the method I am trying to implement:
relativeSysData = relativeSysData.Replace(@"", "/");
SysdataXml = $"file://_globaldata.Server/_globaldata.Share/relativeSysData";
XmlUrlResolver XmlResolver = new XmlUrlResolver();
XmlResolver.Credentials = new NetworkCredential(_UserName,
_Password);
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.XmlResolver = XmlResolver;
LogWriter.WriteLogFile((int)LogWriter.EventID.Xml, (int)LogWriter.EventType.Info,
$"Connecting to (remote) System information store at: SysdataXml");
xDoc = XDocument.Load(XmlReader.Create(SysdataXml, xmlSettings));
if (xDoc == null)
LogWriter.WriteLogFile((int)LogWriter.EventID.XmlError, (int)LogWriter.EventType.Error,
$"Unable to connect to the (remote) data store located at: SysdataXml");
deploy = false;
capture = false;
return result;
This part of the method is specific to accessing the remote data. I have a try/catch statement encompassing all of the method.
If I have an open connection to the Network Share, the method will work flawlessly, but will cause the application this application starts to fail - due to an open connection already.
I have a possible alternative to work round this solution but will cost extra lines of code.
Any help in resolving this matter, without resorting to WNetAddConnection() will be gratefully received
Kind Regards
Richie
N.B. I am aware that this is an authentication issue.
c# xml winpe
if (xDoc == null) has been modified to if (string.IsEmptyorNull(xDoc..ToString()))
– R.McInnes-Piper
Nov 10 at 20:42
With Windows never use a username and password to access a shared folder. It will not work. Use default credential if you have access to the driver using an explorer : XmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials; or XmlResolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
– jdweng
Nov 10 at 20:55
Default credentials will not work. I'm operating from WinPe (Win 10 ver 1809). The credentials are "User" and without building my own file explorer (or using a third party design for WinPE). I can connect using WNetAddConnection(), but would rather not, as the implications of it failing to close the connection will fail the entire remote build.
– R.McInnes-Piper
Nov 10 at 21:02
Can you access the shared drive using a Window Explorer? Windows doesn't allow remote connections without a Group setup to allow a connection from another PC.
– jdweng
Nov 10 at 21:12
I'm programming for Windows Pre-Installation Environment (WinPE), there are no Explorers, whether Windows or Internet - the application works a dream in the full version of Windows, but is failing in the mini-os that WinPE is. The Remote computer is setup to allow remote connections. The Application that this one starts relies upon WNetAddConnection to transfer 4GB+ file sizes. That is why I would like to utilise a method like this to connect to the UNC file path. My apologies - I may not have explained it fully in my question post.
– R.McInnes-Piper
Nov 10 at 21:21
|
show 12 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Thank you in advance for any and all help.
I have seen several post on Stack Overflow and other sites on the net (including Microsoft Docs), but none seeming to help resolve my issue.
I am working on a project that connects to a xml file on a remote file share from WinPE. I have used suggestions from another post on SO about using the XmlUriResolver class to "moderate" success.
The issue I am currently being faced with is either a "Access Denied" error (several attempts to modify the XmlUriResolver.Credentials class) or a complete failure without any reason for failure. I am assuming it is going to be another "Access Denied" error, but my try/catch (Exception e) isn't capturing the reason.
Below is a snippet and relevant part of the method I am trying to implement:
relativeSysData = relativeSysData.Replace(@"", "/");
SysdataXml = $"file://_globaldata.Server/_globaldata.Share/relativeSysData";
XmlUrlResolver XmlResolver = new XmlUrlResolver();
XmlResolver.Credentials = new NetworkCredential(_UserName,
_Password);
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.XmlResolver = XmlResolver;
LogWriter.WriteLogFile((int)LogWriter.EventID.Xml, (int)LogWriter.EventType.Info,
$"Connecting to (remote) System information store at: SysdataXml");
xDoc = XDocument.Load(XmlReader.Create(SysdataXml, xmlSettings));
if (xDoc == null)
LogWriter.WriteLogFile((int)LogWriter.EventID.XmlError, (int)LogWriter.EventType.Error,
$"Unable to connect to the (remote) data store located at: SysdataXml");
deploy = false;
capture = false;
return result;
This part of the method is specific to accessing the remote data. I have a try/catch statement encompassing all of the method.
If I have an open connection to the Network Share, the method will work flawlessly, but will cause the application this application starts to fail - due to an open connection already.
I have a possible alternative to work round this solution but will cost extra lines of code.
Any help in resolving this matter, without resorting to WNetAddConnection() will be gratefully received
Kind Regards
Richie
N.B. I am aware that this is an authentication issue.
c# xml winpe
Thank you in advance for any and all help.
I have seen several post on Stack Overflow and other sites on the net (including Microsoft Docs), but none seeming to help resolve my issue.
I am working on a project that connects to a xml file on a remote file share from WinPE. I have used suggestions from another post on SO about using the XmlUriResolver class to "moderate" success.
The issue I am currently being faced with is either a "Access Denied" error (several attempts to modify the XmlUriResolver.Credentials class) or a complete failure without any reason for failure. I am assuming it is going to be another "Access Denied" error, but my try/catch (Exception e) isn't capturing the reason.
Below is a snippet and relevant part of the method I am trying to implement:
relativeSysData = relativeSysData.Replace(@"", "/");
SysdataXml = $"file://_globaldata.Server/_globaldata.Share/relativeSysData";
XmlUrlResolver XmlResolver = new XmlUrlResolver();
XmlResolver.Credentials = new NetworkCredential(_UserName,
_Password);
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.XmlResolver = XmlResolver;
LogWriter.WriteLogFile((int)LogWriter.EventID.Xml, (int)LogWriter.EventType.Info,
$"Connecting to (remote) System information store at: SysdataXml");
xDoc = XDocument.Load(XmlReader.Create(SysdataXml, xmlSettings));
if (xDoc == null)
LogWriter.WriteLogFile((int)LogWriter.EventID.XmlError, (int)LogWriter.EventType.Error,
$"Unable to connect to the (remote) data store located at: SysdataXml");
deploy = false;
capture = false;
return result;
This part of the method is specific to accessing the remote data. I have a try/catch statement encompassing all of the method.
If I have an open connection to the Network Share, the method will work flawlessly, but will cause the application this application starts to fail - due to an open connection already.
I have a possible alternative to work round this solution but will cost extra lines of code.
Any help in resolving this matter, without resorting to WNetAddConnection() will be gratefully received
Kind Regards
Richie
N.B. I am aware that this is an authentication issue.
c# xml winpe
c# xml winpe
edited Nov 10 at 21:25
asked Nov 10 at 20:40
R.McInnes-Piper
105
105
if (xDoc == null) has been modified to if (string.IsEmptyorNull(xDoc..ToString()))
– R.McInnes-Piper
Nov 10 at 20:42
With Windows never use a username and password to access a shared folder. It will not work. Use default credential if you have access to the driver using an explorer : XmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials; or XmlResolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
– jdweng
Nov 10 at 20:55
Default credentials will not work. I'm operating from WinPe (Win 10 ver 1809). The credentials are "User" and without building my own file explorer (or using a third party design for WinPE). I can connect using WNetAddConnection(), but would rather not, as the implications of it failing to close the connection will fail the entire remote build.
– R.McInnes-Piper
Nov 10 at 21:02
Can you access the shared drive using a Window Explorer? Windows doesn't allow remote connections without a Group setup to allow a connection from another PC.
– jdweng
Nov 10 at 21:12
I'm programming for Windows Pre-Installation Environment (WinPE), there are no Explorers, whether Windows or Internet - the application works a dream in the full version of Windows, but is failing in the mini-os that WinPE is. The Remote computer is setup to allow remote connections. The Application that this one starts relies upon WNetAddConnection to transfer 4GB+ file sizes. That is why I would like to utilise a method like this to connect to the UNC file path. My apologies - I may not have explained it fully in my question post.
– R.McInnes-Piper
Nov 10 at 21:21
|
show 12 more comments
if (xDoc == null) has been modified to if (string.IsEmptyorNull(xDoc..ToString()))
– R.McInnes-Piper
Nov 10 at 20:42
With Windows never use a username and password to access a shared folder. It will not work. Use default credential if you have access to the driver using an explorer : XmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials; or XmlResolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
– jdweng
Nov 10 at 20:55
Default credentials will not work. I'm operating from WinPe (Win 10 ver 1809). The credentials are "User" and without building my own file explorer (or using a third party design for WinPE). I can connect using WNetAddConnection(), but would rather not, as the implications of it failing to close the connection will fail the entire remote build.
– R.McInnes-Piper
Nov 10 at 21:02
Can you access the shared drive using a Window Explorer? Windows doesn't allow remote connections without a Group setup to allow a connection from another PC.
– jdweng
Nov 10 at 21:12
I'm programming for Windows Pre-Installation Environment (WinPE), there are no Explorers, whether Windows or Internet - the application works a dream in the full version of Windows, but is failing in the mini-os that WinPE is. The Remote computer is setup to allow remote connections. The Application that this one starts relies upon WNetAddConnection to transfer 4GB+ file sizes. That is why I would like to utilise a method like this to connect to the UNC file path. My apologies - I may not have explained it fully in my question post.
– R.McInnes-Piper
Nov 10 at 21:21
if (xDoc == null) has been modified to if (string.IsEmptyorNull(xDoc..ToString()))
– R.McInnes-Piper
Nov 10 at 20:42
if (xDoc == null) has been modified to if (string.IsEmptyorNull(xDoc..ToString()))
– R.McInnes-Piper
Nov 10 at 20:42
With Windows never use a username and password to access a shared folder. It will not work. Use default credential if you have access to the driver using an explorer : XmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials; or XmlResolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
– jdweng
Nov 10 at 20:55
With Windows never use a username and password to access a shared folder. It will not work. Use default credential if you have access to the driver using an explorer : XmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials; or XmlResolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
– jdweng
Nov 10 at 20:55
Default credentials will not work. I'm operating from WinPe (Win 10 ver 1809). The credentials are "User" and without building my own file explorer (or using a third party design for WinPE). I can connect using WNetAddConnection(), but would rather not, as the implications of it failing to close the connection will fail the entire remote build.
– R.McInnes-Piper
Nov 10 at 21:02
Default credentials will not work. I'm operating from WinPe (Win 10 ver 1809). The credentials are "User" and without building my own file explorer (or using a third party design for WinPE). I can connect using WNetAddConnection(), but would rather not, as the implications of it failing to close the connection will fail the entire remote build.
– R.McInnes-Piper
Nov 10 at 21:02
Can you access the shared drive using a Window Explorer? Windows doesn't allow remote connections without a Group setup to allow a connection from another PC.
– jdweng
Nov 10 at 21:12
Can you access the shared drive using a Window Explorer? Windows doesn't allow remote connections without a Group setup to allow a connection from another PC.
– jdweng
Nov 10 at 21:12
I'm programming for Windows Pre-Installation Environment (WinPE), there are no Explorers, whether Windows or Internet - the application works a dream in the full version of Windows, but is failing in the mini-os that WinPE is. The Remote computer is setup to allow remote connections. The Application that this one starts relies upon WNetAddConnection to transfer 4GB+ file sizes. That is why I would like to utilise a method like this to connect to the UNC file path. My apologies - I may not have explained it fully in my question post.
– R.McInnes-Piper
Nov 10 at 21:21
I'm programming for Windows Pre-Installation Environment (WinPE), there are no Explorers, whether Windows or Internet - the application works a dream in the full version of Windows, but is failing in the mini-os that WinPE is. The Remote computer is setup to allow remote connections. The Application that this one starts relies upon WNetAddConnection to transfer 4GB+ file sizes. That is why I would like to utilise a method like this to connect to the UNC file path. My apologies - I may not have explained it fully in my question post.
– R.McInnes-Piper
Nov 10 at 21:21
|
show 12 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
After research into how the XmlUrlResolver class works, I think that it may be referencing/accessing API's that are not included within the WinPE API framework.
After testing, I have used the WNetAddConnection2() API to connect to the Server and authenticate before anything happens, ensuring that the local name of the NETRESOURCE structure is left null, and that DisplayType is set to Server.
public static int ConnectToServer()
int result = 0;
var _netresource = new NetResource()
scope = _ResourceScope.GlobalNetwork,
ResourceType = _ResourceType.Any,
DisplayType = _ResourceDisplayType.Server,
RemoteName = $@"\Program._globaldata.Server"
;
string _username = $@"Program._globaldata.ServerRemoteDKBuild";
string _passsword = "Hic3nuasno6epyndtenars4yDifrts";
var _connectiontype = (int)_ConnectionType.Interactive
[DllImport("mpr.dll", SetLastError = true)]
private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
After research into how the XmlUrlResolver class works, I think that it may be referencing/accessing API's that are not included within the WinPE API framework.
After testing, I have used the WNetAddConnection2() API to connect to the Server and authenticate before anything happens, ensuring that the local name of the NETRESOURCE structure is left null, and that DisplayType is set to Server.
public static int ConnectToServer()
int result = 0;
var _netresource = new NetResource()
scope = _ResourceScope.GlobalNetwork,
ResourceType = _ResourceType.Any,
DisplayType = _ResourceDisplayType.Server,
RemoteName = $@"\Program._globaldata.Server"
;
string _username = $@"Program._globaldata.ServerRemoteDKBuild";
string _passsword = "Hic3nuasno6epyndtenars4yDifrts";
var _connectiontype = (int)_ConnectionType.Interactive
[DllImport("mpr.dll", SetLastError = true)]
private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);
add a comment |
up vote
0
down vote
accepted
After research into how the XmlUrlResolver class works, I think that it may be referencing/accessing API's that are not included within the WinPE API framework.
After testing, I have used the WNetAddConnection2() API to connect to the Server and authenticate before anything happens, ensuring that the local name of the NETRESOURCE structure is left null, and that DisplayType is set to Server.
public static int ConnectToServer()
int result = 0;
var _netresource = new NetResource()
scope = _ResourceScope.GlobalNetwork,
ResourceType = _ResourceType.Any,
DisplayType = _ResourceDisplayType.Server,
RemoteName = $@"\Program._globaldata.Server"
;
string _username = $@"Program._globaldata.ServerRemoteDKBuild";
string _passsword = "Hic3nuasno6epyndtenars4yDifrts";
var _connectiontype = (int)_ConnectionType.Interactive
[DllImport("mpr.dll", SetLastError = true)]
private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
After research into how the XmlUrlResolver class works, I think that it may be referencing/accessing API's that are not included within the WinPE API framework.
After testing, I have used the WNetAddConnection2() API to connect to the Server and authenticate before anything happens, ensuring that the local name of the NETRESOURCE structure is left null, and that DisplayType is set to Server.
public static int ConnectToServer()
int result = 0;
var _netresource = new NetResource()
scope = _ResourceScope.GlobalNetwork,
ResourceType = _ResourceType.Any,
DisplayType = _ResourceDisplayType.Server,
RemoteName = $@"\Program._globaldata.Server"
;
string _username = $@"Program._globaldata.ServerRemoteDKBuild";
string _passsword = "Hic3nuasno6epyndtenars4yDifrts";
var _connectiontype = (int)_ConnectionType.Interactive
[DllImport("mpr.dll", SetLastError = true)]
private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);
After research into how the XmlUrlResolver class works, I think that it may be referencing/accessing API's that are not included within the WinPE API framework.
After testing, I have used the WNetAddConnection2() API to connect to the Server and authenticate before anything happens, ensuring that the local name of the NETRESOURCE structure is left null, and that DisplayType is set to Server.
public static int ConnectToServer()
int result = 0;
var _netresource = new NetResource()
scope = _ResourceScope.GlobalNetwork,
ResourceType = _ResourceType.Any,
DisplayType = _ResourceDisplayType.Server,
RemoteName = $@"\Program._globaldata.Server"
;
string _username = $@"Program._globaldata.ServerRemoteDKBuild";
string _passsword = "Hic3nuasno6epyndtenars4yDifrts";
var _connectiontype = (int)_ConnectionType.Interactive
[DllImport("mpr.dll", SetLastError = true)]
private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);
answered Nov 11 at 19:53
R.McInnes-Piper
105
105
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243202%2fusing-xmluriresolver-to-provide-credentials-to-remote-share%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if (xDoc == null) has been modified to if (string.IsEmptyorNull(xDoc..ToString()))
– R.McInnes-Piper
Nov 10 at 20:42
With Windows never use a username and password to access a shared folder. It will not work. Use default credential if you have access to the driver using an explorer : XmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials; or XmlResolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
– jdweng
Nov 10 at 20:55
Default credentials will not work. I'm operating from WinPe (Win 10 ver 1809). The credentials are "User" and without building my own file explorer (or using a third party design for WinPE). I can connect using WNetAddConnection(), but would rather not, as the implications of it failing to close the connection will fail the entire remote build.
– R.McInnes-Piper
Nov 10 at 21:02
Can you access the shared drive using a Window Explorer? Windows doesn't allow remote connections without a Group setup to allow a connection from another PC.
– jdweng
Nov 10 at 21:12
I'm programming for Windows Pre-Installation Environment (WinPE), there are no Explorers, whether Windows or Internet - the application works a dream in the full version of Windows, but is failing in the mini-os that WinPE is. The Remote computer is setup to allow remote connections. The Application that this one starts relies upon WNetAddConnection to transfer 4GB+ file sizes. That is why I would like to utilise a method like this to connect to the UNC file path. My apologies - I may not have explained it fully in my question post.
– R.McInnes-Piper
Nov 10 at 21:21