GetLastError returns success after InternetSetCookie returns false





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Using .NET 4.6.2, coding in C#



Having a problem for just a customer on a handful of their machines. When the user is in Local Administrator group, everything works fine but when they remove them from Local Administrators, it would appear InternetSetCookie returns false, but GetLastWin32Error returns success.



I concluded InternetSetCookie is returning false, because I fail to see any line above it could possibly throw such an exception. But I guess anything is possible.



[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string lpszUrl, string lpszCookieName, string lpszCookieData);

private bool SetUriCookie(CookieContainer container, Uri uri, string cookieName){
bool bRetVal = false;
try{
Cookie cookie = container.GetCookies(uri)[cookieName];
string cookieValue = cookie == null ? "" : cookie.Value;
DateTime cookieExpire = cookie == null ? DateTime.Now.AddMinutes(2) : cookie.Expires;
string cookieData = string.Format("{0};expires={1}", cookieValue, cookieExpire.ToString("R"));
bRetVal = InternetSetCookie(uri.ToString(), cookieName, cookieData);
if (!bRetVal) throw new Win32Exception(Marshal.GetLastWin32Error());
} catch (Exception e) {
Logger.LogError(e, "Exception thrown attempting to store '{0}' cookie", cookieName);
}
return bRetVal;
}


This is what logged is:




Exception thrown attempting to store 'xxxxx' cookie Error: The operation completed successfully




I have reason to believe the cookie is being stored, even though the API returns false. I have yet to confirm that. Any suggestions on how I should proceed?










share|improve this question

























  • This is job for the customer's IT staff to sort out. Starting by winnowing down on the crapware that always hangs off a HTTP socket, anti-malware and whatnot. Fwiw, the framework uses InternetSetCookieEx().

    – Hans Passant
    Nov 16 '18 at 16:15













  • @HansPassant, I would agree if the cookie wasn't being saved, however, it would be nice to give them a clue what to look for. But it appears the cookie is being saved and obviously would impact my error handling code.

    – tdemay
    Nov 16 '18 at 20:54











  • @HansPassant, what .NET function can I use to call InternetSetCookieEx

    – tdemay
    Nov 16 '18 at 22:38











  • It is not accessible. referencesource.microsoft.com/#WindowsBase/Shared/MS/Win32/…

    – Hans Passant
    Nov 16 '18 at 22:44


















0















Using .NET 4.6.2, coding in C#



Having a problem for just a customer on a handful of their machines. When the user is in Local Administrator group, everything works fine but when they remove them from Local Administrators, it would appear InternetSetCookie returns false, but GetLastWin32Error returns success.



I concluded InternetSetCookie is returning false, because I fail to see any line above it could possibly throw such an exception. But I guess anything is possible.



[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string lpszUrl, string lpszCookieName, string lpszCookieData);

private bool SetUriCookie(CookieContainer container, Uri uri, string cookieName){
bool bRetVal = false;
try{
Cookie cookie = container.GetCookies(uri)[cookieName];
string cookieValue = cookie == null ? "" : cookie.Value;
DateTime cookieExpire = cookie == null ? DateTime.Now.AddMinutes(2) : cookie.Expires;
string cookieData = string.Format("{0};expires={1}", cookieValue, cookieExpire.ToString("R"));
bRetVal = InternetSetCookie(uri.ToString(), cookieName, cookieData);
if (!bRetVal) throw new Win32Exception(Marshal.GetLastWin32Error());
} catch (Exception e) {
Logger.LogError(e, "Exception thrown attempting to store '{0}' cookie", cookieName);
}
return bRetVal;
}


This is what logged is:




Exception thrown attempting to store 'xxxxx' cookie Error: The operation completed successfully




I have reason to believe the cookie is being stored, even though the API returns false. I have yet to confirm that. Any suggestions on how I should proceed?










share|improve this question

























  • This is job for the customer's IT staff to sort out. Starting by winnowing down on the crapware that always hangs off a HTTP socket, anti-malware and whatnot. Fwiw, the framework uses InternetSetCookieEx().

    – Hans Passant
    Nov 16 '18 at 16:15













  • @HansPassant, I would agree if the cookie wasn't being saved, however, it would be nice to give them a clue what to look for. But it appears the cookie is being saved and obviously would impact my error handling code.

    – tdemay
    Nov 16 '18 at 20:54











  • @HansPassant, what .NET function can I use to call InternetSetCookieEx

    – tdemay
    Nov 16 '18 at 22:38











  • It is not accessible. referencesource.microsoft.com/#WindowsBase/Shared/MS/Win32/…

    – Hans Passant
    Nov 16 '18 at 22:44














0












0








0








Using .NET 4.6.2, coding in C#



Having a problem for just a customer on a handful of their machines. When the user is in Local Administrator group, everything works fine but when they remove them from Local Administrators, it would appear InternetSetCookie returns false, but GetLastWin32Error returns success.



I concluded InternetSetCookie is returning false, because I fail to see any line above it could possibly throw such an exception. But I guess anything is possible.



[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string lpszUrl, string lpszCookieName, string lpszCookieData);

private bool SetUriCookie(CookieContainer container, Uri uri, string cookieName){
bool bRetVal = false;
try{
Cookie cookie = container.GetCookies(uri)[cookieName];
string cookieValue = cookie == null ? "" : cookie.Value;
DateTime cookieExpire = cookie == null ? DateTime.Now.AddMinutes(2) : cookie.Expires;
string cookieData = string.Format("{0};expires={1}", cookieValue, cookieExpire.ToString("R"));
bRetVal = InternetSetCookie(uri.ToString(), cookieName, cookieData);
if (!bRetVal) throw new Win32Exception(Marshal.GetLastWin32Error());
} catch (Exception e) {
Logger.LogError(e, "Exception thrown attempting to store '{0}' cookie", cookieName);
}
return bRetVal;
}


This is what logged is:




Exception thrown attempting to store 'xxxxx' cookie Error: The operation completed successfully




I have reason to believe the cookie is being stored, even though the API returns false. I have yet to confirm that. Any suggestions on how I should proceed?










share|improve this question
















Using .NET 4.6.2, coding in C#



Having a problem for just a customer on a handful of their machines. When the user is in Local Administrator group, everything works fine but when they remove them from Local Administrators, it would appear InternetSetCookie returns false, but GetLastWin32Error returns success.



I concluded InternetSetCookie is returning false, because I fail to see any line above it could possibly throw such an exception. But I guess anything is possible.



[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string lpszUrl, string lpszCookieName, string lpszCookieData);

private bool SetUriCookie(CookieContainer container, Uri uri, string cookieName){
bool bRetVal = false;
try{
Cookie cookie = container.GetCookies(uri)[cookieName];
string cookieValue = cookie == null ? "" : cookie.Value;
DateTime cookieExpire = cookie == null ? DateTime.Now.AddMinutes(2) : cookie.Expires;
string cookieData = string.Format("{0};expires={1}", cookieValue, cookieExpire.ToString("R"));
bRetVal = InternetSetCookie(uri.ToString(), cookieName, cookieData);
if (!bRetVal) throw new Win32Exception(Marshal.GetLastWin32Error());
} catch (Exception e) {
Logger.LogError(e, "Exception thrown attempting to store '{0}' cookie", cookieName);
}
return bRetVal;
}


This is what logged is:




Exception thrown attempting to store 'xxxxx' cookie Error: The operation completed successfully




I have reason to believe the cookie is being stored, even though the API returns false. I have yet to confirm that. Any suggestions on how I should proceed?







c# .net wininet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:30









kit

1,10631017




1,10631017










asked Nov 16 '18 at 15:49









tdemaytdemay

354318




354318













  • This is job for the customer's IT staff to sort out. Starting by winnowing down on the crapware that always hangs off a HTTP socket, anti-malware and whatnot. Fwiw, the framework uses InternetSetCookieEx().

    – Hans Passant
    Nov 16 '18 at 16:15













  • @HansPassant, I would agree if the cookie wasn't being saved, however, it would be nice to give them a clue what to look for. But it appears the cookie is being saved and obviously would impact my error handling code.

    – tdemay
    Nov 16 '18 at 20:54











  • @HansPassant, what .NET function can I use to call InternetSetCookieEx

    – tdemay
    Nov 16 '18 at 22:38











  • It is not accessible. referencesource.microsoft.com/#WindowsBase/Shared/MS/Win32/…

    – Hans Passant
    Nov 16 '18 at 22:44



















  • This is job for the customer's IT staff to sort out. Starting by winnowing down on the crapware that always hangs off a HTTP socket, anti-malware and whatnot. Fwiw, the framework uses InternetSetCookieEx().

    – Hans Passant
    Nov 16 '18 at 16:15













  • @HansPassant, I would agree if the cookie wasn't being saved, however, it would be nice to give them a clue what to look for. But it appears the cookie is being saved and obviously would impact my error handling code.

    – tdemay
    Nov 16 '18 at 20:54











  • @HansPassant, what .NET function can I use to call InternetSetCookieEx

    – tdemay
    Nov 16 '18 at 22:38











  • It is not accessible. referencesource.microsoft.com/#WindowsBase/Shared/MS/Win32/…

    – Hans Passant
    Nov 16 '18 at 22:44

















This is job for the customer's IT staff to sort out. Starting by winnowing down on the crapware that always hangs off a HTTP socket, anti-malware and whatnot. Fwiw, the framework uses InternetSetCookieEx().

– Hans Passant
Nov 16 '18 at 16:15







This is job for the customer's IT staff to sort out. Starting by winnowing down on the crapware that always hangs off a HTTP socket, anti-malware and whatnot. Fwiw, the framework uses InternetSetCookieEx().

– Hans Passant
Nov 16 '18 at 16:15















@HansPassant, I would agree if the cookie wasn't being saved, however, it would be nice to give them a clue what to look for. But it appears the cookie is being saved and obviously would impact my error handling code.

– tdemay
Nov 16 '18 at 20:54





@HansPassant, I would agree if the cookie wasn't being saved, however, it would be nice to give them a clue what to look for. But it appears the cookie is being saved and obviously would impact my error handling code.

– tdemay
Nov 16 '18 at 20:54













@HansPassant, what .NET function can I use to call InternetSetCookieEx

– tdemay
Nov 16 '18 at 22:38





@HansPassant, what .NET function can I use to call InternetSetCookieEx

– tdemay
Nov 16 '18 at 22:38













It is not accessible. referencesource.microsoft.com/#WindowsBase/Shared/MS/Win32/…

– Hans Passant
Nov 16 '18 at 22:44





It is not accessible. referencesource.microsoft.com/#WindowsBase/Shared/MS/Win32/…

– Hans Passant
Nov 16 '18 at 22:44












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341222%2fgetlasterror-returns-success-after-internetsetcookie-returns-false%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341222%2fgetlasterror-returns-success-after-internetsetcookie-returns-false%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python