1

I have C# .Net windows application and using WNetAddConnection2 to connect network share folder. I want to validate SharedFolder with username/password with access rights. Please refer detail explanation of class at http://msdn.microsoft.com/en-us/library/windows/desktop/aa385413(v=vs.85).aspx

For CONNECT_PROMPT, it is instruction in msdn that "This flag is ignored unless CONNECT_INTERACTIVE is also set." My code like

 var result = WNetAddConnection2(netResource,credentials.Password,userName,0x00000010//CONNECT_PROMPT]);

So Question is how to set both CONNECT_INTERACTIVE and CONNECT_PROMPT for class to prompt username and password for shared folder?

Any help would be appreciated.

Miki Shah
  • 815
  • 9
  • 20

1 Answers1

3

You should OR the values together using the | operator, e.g.:

var both = CONNECT_INTERACTIVE | CONNECT_PROMPT;
John Willemse
  • 6,608
  • 7
  • 31
  • 45
  • I am using C# windows application.dwFlags is DWORD and format is WNetAddConnection2(netResource, credentials.Password, userName, 0x00000008); Now How can use ‘or’ between 0x00000008(CONNECT_INTERACTIVE) and 0x00000010(CONNECT_PROMPT)? – Miki Shah Mar 01 '13 at 13:06
  • 2
    @MikiShah Simply do `WNetAddConnection2(netResource, credentials.Password, userName, 0x8 | 0x10);`. – Otiel Mar 01 '13 at 13:07
  • John and Otiel, Thank you very much guys, I have credential prompt now. – Miki Shah Mar 01 '13 at 13:21
  • @John can you help me other issue?http://stackoverflow.com/questions/15159564/prevent-wnetaddconnection2-class-which-allows-prohibited-user-to-access-shared-f#comment21366269_15159564 – Miki Shah Mar 02 '13 at 05:40