Why don't I give a call to your IT Administrator or the DET to let them see what you're trying to do here.
IO.File.WriteAllText("C:\somefolder\file.txt", TextBox2.Text)
If you want to use the REAL API instead of just simulating that window, use this example I made:
Code:
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Net
Public Class Form1
<DllImport("ole32.dll")> _
Public Shared Sub CoTaskMemFree(ByVal ptr As IntPtr)
End Sub
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure CREDUI_INFO
Public cbSize As Integer
Public hwndParent As IntPtr
Public pszMessageText As String
Public pszCaptionText As String
Public hbmBanner As IntPtr
End Structure
<DllImport("credui.dll", CharSet:=CharSet.Auto)> _
Private Shared Function CredUnPackAuthenticationBuffer(ByVal dwFlags As Integer, ByVal pAuthBuffer As IntPtr, ByVal cbAuthBuffer As UInteger, ByVal pszUserName As StringBuilder, ByRef pcchMaxUserName As Integer, ByVal pszDomainName As StringBuilder, _
ByRef pcchMaxDomainame As Integer, ByVal pszPassword As StringBuilder, ByRef pcchMaxPassword As Integer) As Boolean
End Function
<DllImport("credui.dll", CharSet:=CharSet.Auto)> _
Private Shared Function CredUIPromptForWindowsCredentials(ByRef notUsedHere As CREDUI_INFO, ByVal authError As Integer, ByRef authPackage As UInteger, ByVal InAuthBuffer As IntPtr, ByVal InAuthBufferSize As UInteger, ByRef refOutAuthBuffer As IntPtr, _
ByRef refOutAuthBufferSize As UInteger, ByRef fSave As Boolean, ByVal flags As Integer) As Integer
End Function
Public Shared Sub GetCredentials(ByRef networkCredential As NetworkCredential)
Dim credui As New CREDUI_INFO()
credui.pszCaptionText = String.Empty
credui.pszMessageText = "The server 10.28.160.20 at NSW Department of Education and Training requires a username and password" + Environment.NewLine + Environment.NewLine +
"Warning: This server is requesting that your username and password be sent in an insecure manner (basic authentication without a secure connection)."
credui.cbSize = Marshal.SizeOf(credui)
Dim authPackage As UInteger = 0
Dim outCredBuffer As New IntPtr()
Dim outCredSize As UInteger
Dim save As Boolean = False
' Generic
Dim result As Integer = CredUIPromptForWindowsCredentials(credui, 0, authPackage, IntPtr.Zero, 0, outCredBuffer, _
outCredSize, save, 1)
Dim usernameBuf = New StringBuilder(100)
Dim passwordBuf = New StringBuilder(100)
Dim domainBuf = New StringBuilder(100)
Dim maxUserName As Integer = 100
Dim maxDomain As Integer = 100
Dim maxPassword As Integer = 100
If result = 0 Then
If CredUnPackAuthenticationBuffer(0, outCredBuffer, outCredSize, usernameBuf, maxUserName, domainBuf, _
maxDomain, passwordBuf, maxPassword) Then
CoTaskMemFree(outCredBuffer)
networkCredential = New NetworkCredential() With { _
.UserName = usernameBuf.ToString(), _
.Password = passwordBuf.ToString(), _
.Domain = domainBuf.ToString() _
}
Return
End If
End If
networkCredential = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim nc As New NetworkCredential()
GetCredentials(nc)
If nc IsNot Nothing Then 'We need to check if the credentials are there or not
Dim username As String = nc.UserName 'This is the username
Dim password As String = nc.Password 'This is the password
End If
End Sub
End Class
Credits to Rubinsh.