Desktop Functions: Smart Device Functions:
|
Search Results for "connect" in [All]iphlpapi
IF_TYPE_FRAMERELAY_INTERCONNECT = 58, // Obsolete, use 32 or 44
IF_TYPE_ESCON = 73, // IBM Enterprise Systems Connection
IF_TYPE_PROP_CNLS = 89, // Proprietary Connectionless Proto
IF_TYPE_FRAMERELAY_MPI = 92, // Multiproto Interconnect over FR
public enum NET_IF_CONNECTION_TYPE : uint
NET_IF_CONNECTION_DEDICATED = 1,
NET_IF_CONNECTION_PASSIVE = 2,
NET_IF_CONNECTION_DEMAND = 3,
NET_IF_CONNECTION_MAXIMUM = 4
public NET_IF_CONNECTION_TYPE ConnectionType;
public static List<MIB_TCPROW_OWNER_PID> GetAllTCPConnections()
return GetTCPConnections<MIB_TCPROW_OWNER_PID, MIB_TCPTABLE_OWNER_PID>(AF_INET);
public static List<MIB_TCP6ROW_OWNER_PID> GetAllTCPv6Connections()
return GetTCPConnections<MIB_TCP6ROW_OWNER_PID, MIB_TCP6TABLE_OWNER_PID>(AF_INET6);
private static List<IPR> GetTCPConnections<IPR, IPT>(int ipVersion)//IPR = Row Type, IPT = Table Type
public MIB_TCPROW_OWNER_PID[] GetAllTcpConnections()
TCP_TABLE_BASIC_CONNECTIONS,
TCP_TABLE_OWNER_PID_CONNECTIONS,
TCP_TABLE_OWNER_MODULE_CONNECTIONS,
public List<MIB_TCPROW_OWNER_PID> GetAllTCPv4Connections() {
return GetTCPConnections<MIB_TCPROW_OWNER_PID, MIB_TCPTABLE_OWNER_PID>(AF_INET);
public List<MIB_TCP6ROW_OWNER_PID> GetAllTCPv6Connections() {
return GetTCPConnections<MIB_TCP6ROW_OWNER_PID, MIB_TCP6TABLE_OWNER_PID>(AF_INET6);
public List<IPR> GetTCPConnections<IPR, IPT>(int ipVersion) { //IPR = Row Type, IPT = Table Type
$y=$x.GetAllTCPv4Connections() 3: GetIfTable
/// MIB_IFROW structure array. Content the active networks connection coredll
NOTIFICATION_EVENT_RS232_DETECTED is also raised when connecting the device to USB.
private static extern uint RasEnumConnections(
[Out] out int connections); public static RASCONN[] GetAllConnections()
RASCONN[] allConnections = tempConn;
int lpcConnections = 0;
uint ret = RasEnumConnections(tempConn, ref lpcb, out lpcConnections);
// first call returned that there are more than one connections
allConnections = new RASCONN[lpcb / Marshal.SizeOf(typeof(RASCONN))];
allConnections[0] = tempConn[0];
ret = RasEnumConnections(allConnections, ref lpcb, out lpcConnections);
if (lpcConnections > allConnections.Length)
throw new Exception("RAS: error retrieving correct connection count");
else if (lpcConnections == 0)
allConnections = new RASCONN[0];
return allConnections;
internal static extern UInt32 RasEnumConnections([In, Out] _RASCONN[] lprasconn, ref UInt32 lpcb, ref UInt32 lpcConnections);
public IntPtr ConnectionHandle { get { return m_hrasconn; } }
public static _RASCONN[] EnumerateConnections()
if (RasEnumConnections(rasconn, ref size, ref noelements) != 0x00)
if (RasEnumConnections(rasconn, ref size, ref noelements) != 0x00) { rasconn = null; }
public static extern int RasGetConnectStatus(IntPtr hrasconn, ref RASCONNSTATUS lprasconnstatus);
RASCS_ConnectDevice,
RASCS_DeviceConnected,
RASCS_AllDevicesConnected,
RASCS_Connected = RASCS_DONE,
RASCS_Disconnected
public static RASCONNSTATUS GetConnectStatus(IntPtr hrasconn)
RasGetConnectStatus(hrasconn, ref status); 8: RasHangUp Use this function together with RasEnumConnections, to return a list of the active connections, then the sample code below will loop through the RASCONN[] array and close each one. public static void CloseAllConnections()
RASCONN[] connections = GetAllConnections();
for (int i = 0; i < connections.Length; ++i)
RasHangUp(connections[i].hrasconn); aygshellMicrosoft.SmartDevice.Connectivity.Device.ProvisionDevice(string, Device.ConfigActions), although it is a desktop managed method and only works remotely, whereas this P/Invoke can be executed directly on the device. odbccp32
vAttributes &= "Trusted_Connection=Yes" & Convert.ToChar(0) This function persists a system data source with the provided name and connection string. Remember to add your own error checking mechanisms.
// Connection string for SQLConfigDataSource must be null- 12: SQLSetConfigMode This function persists a system data source with the provided name and connection string. Remember to add your own error checking mechanisms.
// Connection string for SQLConfigDataSource must be null- winfax
static extern bool FaxConnectFaxServer (string MachineName, out IntPtr FaxHandle);
Declare Function FaxConnectFaxServer Lib "winfax.dll" (TODO) As TODO 14: FaxEnumJobs
15: FaxEnumPorts
wlanapi
byte *connectionData = null;
uint sizeConnectionData = 0;
UInt32 result = EapHostPeerInvokeConfigUI(handle, 0, method, 0, null, &sizeConnectionData, &connectionData, ref er);
MessageBox.Show(sizeConnectionData+"jfdgkj");
output = new byte[sizeConnectionData];
for (int i = 0; i < sizeConnectionData; i++)
output[i] = *connectionData;
//MessageBox.Show(*connectionData+" value"+i);
connectionData++; 17: WlanConnect
public static extern uint WlanConnect(IntPtr hClientHandle,ref Guid pInterfaceGuid,ref WLAN_CONNECTION_PARAMETERS pConnectionParameters,IntPtr pReserved);
Declare Function WlanConnect Lib "wlanapi.dll" (ByVal hClientHandle As IntPtr, _
ByRef pConnectionParameters As WLAN_CONNECTION_PARAMETERS, _
WLAN_CONNECTION_PARAMETERS wlanConnectionParameters = new WLAN_CONNECTION_PARAMETERS();
wlanConnectionParameters.dot11BssType = DOT11_BSS_TYPE.dot11_BSS_type_any;
wlanConnectionParameters.dwFlags = 0;
wlanConnectionParameters.strProfile = "dlink";
wlanConnectionParameters.wlanConnectionMode = WLAN_CONNECTION_MODE.wlan_connection_mode_profile;
WlanConnect(ClientHandle,ref pInterfaceGuid,ref wlanConnectionParameters ,new IntPtr());
Dim wlanConnectionParameters As New WLAN_CONNECTION_PARAMETERS
wlanConnectionParameters.dot11BssType = DOT11_BSS_TYPE.dot11_BSS_type_any
wlanConnectionParameters.dwFlags = 0
wlanConnectionParameters.strProfile = "dlink"
wlanConnectionParameters.wlanConnectionMode = WLAN_CONNECTION_MODE.wlan_connection_mode_profile
WlanConnect(ClientHandle, pInterfaceGuid, wlanConnectionParameters, IntPtr.Zero) 18: WlanDisconnect
public static extern uint WlanDisconnect(IntPtr hClientHandle,ref Guid pInterfaceGuid,IntPtr pReserved);
Declare Function WlanDisconnect Lib "wlanapi.dll" (TODO) As TODO
WLAN_CONNECTION_ATTRIBUTES connection;
if (WlanQueryInterface(handle, ref guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, out dataSize, ref ptr, IntPtr.Zero) != 0)
connection = (WLAN_CONNECTION_ATTRIBUTES)Marshal.PtrToStructure(ptr, typeof(WLAN_CONNECTION_ATTRIBUTES));
// Do something here with the connection info....
Dim connection As WLAN_CONNECTION_ATTRIBUTES
If WlanQueryInterface(handle, guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, dataSize, ptr, _
connection = DirectCast(Marshal.PtrToStructure(ptr, GetType(WLAN_CONNECTION_ATTRIBUTES)), WLAN_CONNECTION_ATTRIBUTES)
' Do something here with the connection info.... kernel3220: ConnectNamedPipe
static extern bool ConnectNamedPipe(IntPtr hNamedPipe, Good example of named pipes using ConnectNamedPipe() can be found at http://wyday.com/blog/2010/multi-process-c-sharp-application-like-google-chrome-using-named-pipes/ 21: CreateNamedPipe
/// 2. Call Listen(). This will block until a client connects. Sorry, the alternatives
/// 3. Call DataAvailable() in a loop with Read(), Write, ReadLine(), etc. until IsConnected turns false.
private static extern bool DisconnectNamedPipe(
private static extern bool ConnectNamedPipe(
/// Waits indefinitely when connecting to a pipe.
private const ulong ERROR_PIPE_CONNECTED = 535;
/// Server only: block until client connects
DisconnectNamedPipe(_handle);
if (ConnectNamedPipe(_handle, IntPtr.Zero) != true)
if (lastErr == ERROR_PIPE_CONNECTED)
/// Server only: disconnect the pipe. For most applications, you should just call Listen()
/// instead, which automatically does a disconnect of any old connection.
public void Disconnect()
throw new Exception("Disconnect() is only for server-side streams");
DisconnectNamedPipe(_handle);
/// Returns true if client is connected. Should only be called after Listen() succeeds.
public bool IsConnected
throw new Exception("IsConnected() is only for server-side streams");
if (ConnectNamedPipe(_handle, IntPtr.Zero) == false)
if ((uint)Marshal.GetLastWin32Error() == ERROR_PIPE_CONNECTED)
} while (stream.IsConnected); setupapi23: Option Explicit MsgBox “Device not connected” rasapi3224: RasDial
25: RasDialDlg
public static extern int RasEnumConnections(
[Out] out int connections);
RAW.RASCONN[] connections = new RAW.RASCONN[1];
connections[0].dwSize = Marshal.SizeOf(typeof(RAW.RASCONN));
int connectionsCount = 0;
int nRet = RAW.RasEnumConnections(connections, ref cb, out connectionsCount);
if (connectionsCount == 0)
connections = new RAW.RASCONN[connectionsCount];
for (int i = 0; i < connections.Length; i++)
connections[i].dwSize = Marshal.SizeOf(typeof(RAW.RASCONN));
nRet = RAW.RasEnumConnections(connections, ref cb, out connectionsCount);
int cb = 0, connectionCount;
if (RAW.RasEnumConnections(null, ref cb, out connectionCount) == RAW.ERROR_BUFFER_TOO_SMALL)
if (connectionCount == 0) return;
if (RasApi.RasEnumConnections(buffer, ref cb, out conns) == RAW.ERROR_SUCCESS)
static extern uint RasGetConnectionStatistics(IntPtr hRasConn, ref RAS_STATS lpStatistics);
Public Shared Function RasGetConnectionStatistics( _
uint retVal = RasGetConnectionStatistics(rasConnectionHandle, ref statistics);
public static extern int RasGetConnectStatus(int hrasconn, ref RASCONNSTATUS lprasconnstatus);
Declare Function RasGetConnectStatus Lib "rasapi32.dll" (TODO) As TODO 30: RasHangUp
/// Changes the connection information for an entry in the phone book or creates a new phone-book entry.
/// <param name="lpRasEntry">Pointer to the RASENTRY structure that specifies the connection data to associate with the phone-book entry.</param>
public int dwIdleDisconnectSeconds;
ReconnectIfDropped = 0x100,
/// Create or modify network connection.
/// <param name="connectionName">Name of the network connection to create or modify.</param>
/// <param name="rasEntryStructure">RASENTRY structure containing connection settings.</param>
public static RasError SetEntryProperties(string connectionName, RASENTRY rasEntryStructure)
return (RasError)RasSetEntryProperties(null, connectionName, ref rasEntryStructure, Marshal.SizeOf(rasEntryStructure), IntPtr.Zero, 0); user3232: DdeConnect
static extern IntPtr DdeConnect(uint idInst, IntPtr hszService, IntPtr handle = DdeConnect(instanceId, serviceHandle, topicHandle, IntPtr.Zero); 33: DdeConnectList 34: DdeDisconnect 36: DdeReconnect
winspool37: AddPrinter
internal static extern bool AddPrinterConnection(String pszBuffer);
Declare Function AddPrinterConnection Lib "winspool.dll" (TODO) As TODO
internal static extern bool AddPrinterConnection(String pszBuffer);
Declare Function AddPrinterConnection Lib "winspool.dll" (TODO) As TODO 39: ClosePrinter
40: DeletePrinter
internal static extern bool DeletePrinterConnection(String pName);
Declare Function DeletePrinterConnection Lib "winspool.dll" (TODO) As TODO result = DeletePrinterConnection("\\\\Server_Name\\Printer_Share"); secur32
public const int ISC_REQ_CONNECTION = 0x00000800;
public const int STANDARD_CONTEXT_ATTRIBUTES = ISC_REQ_CONFIDENTIALITY | ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONNECTION;
/// <param name="LsaHandle">[in] Handle obtained from a previous call to LsaRegisterLogonProcess or LsaConnectUntrusted.</param>
public static extern WinStatusCodes LsaConnectUntrusted([Out] out IntPtr LsaHandle);
Declare Function LsaConnectUntrusted Lib "secur32.dll" (TODO) As TODO
NewCredentials, // Allows the caller to clone its current token and specify new credentials for outbound connections. 47: LsaLogonUser
public static extern WinStatusCodes LsaConnectUntrusted([Out] out IntPtr LsaHandle);
OSCalls.WinStatusCodes status = OSCalls.LsaConnectUntrusted(out lsaHandle); mpr
static extern int MultinetGetConnectionPerformance(
ref NetConnectInfoStruct lpNetConnectInfoStruct);
public struct NetConnectInfoStruct {
/// In the absence of information about the actual connection,
/// the current connection with the resource, with any routing
/// The connection is not being routed.
/// If this flag is not set, the connection may be going through
/// The connection is over a medium that is typically slow (for
NetConnectInfoStruct ci = new NetConnectInfoStruct();
RESOURCE_CONNECTED = 1,
RESOURCEUSAGE_CONNECTABLE = 0x00000001,
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
public enum ResourceConnection
CONNECT_UPDATE_PROFILE = 1,
CONNECT_UPDATE_RECENT = 2,
CONNECT_TEMPORARY = 4,
CONNECT_INTERACTIVE = 8,
CONNECT_PROMPT= 0X10,
CONNECT_REDIRECT = 0X80,
CONNECT_CURRENT_MEDIA = 0X200,
CONNECT_COMMAND_LINE = 0X800,
CONNECT_CMD_SAVECRED = 0X1000,
CONNECT_CRED_RESET = 0X2000 private static extern int WNetAddConnection2( NETRESOURCE lpNetResource,
Declare Function VVNetAddConnection2 Lib "mpr.dll" (TODO) As TODO nr.dwUsage = ResourceUsage.RESOURCEUSAGE_CONNECTABLE; int result = WNetAddConnection2(nr, password, user, (int)ResourceConnection.CONNECT_TEMPORARY);
private static extern int WNetAddConnection3(IntPtr hWndOwner,
Private Shared Function WNetAddConnection3(ByVal hWndOwner As IntPtr, _
private const int CONNECT_INTERACTIVE = 0x8;
private const int CONNECT_PROMPT = 0x10;
WNetAddConnection3(hWnd, ref ConnInf, null, null,
CONNECT_INTERACTIVE | CONNECT_PROMPT); http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/wnetaddconnection2.asp The WNetAddConnection2 function supersedes the WNetAddConnection function. If you can pass a handle to a window that the provider of network resources can use as an owner window for dialog boxes, call the WNetAddConnection3 function instead.
public static extern int WNetAddConnection2(ref NETRESOURCE netResource,
public static extern int WNetAddConnection2(NETRESOURCE netResource,
// RESOURCE_CONNECTED = 1,
// RESOURCEUSAGE_CONNECTABLE = 0x00000001,
// RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
// [DllImport("Mpr.dll", EntryPoint="WNetAddConnection2", CallingConvention=CallingConvention.Winapi)]
// private static extern ErrorCodes WNetAddConnection2(NETRESOURCE lpNetResource,ref string lpPassword,ref
public static extern int WNetAddConnection2( [In] NETRESOURCE netResource,
Declare Function WNetAddConnection2 Lib "mpr.dll" (ByRef netResource As _
Declare Function WNetAddConnection2 Lib "mpr.dll" (netResource As _ // int ret = WNetAddConnection2( myNetResource, "username", "password", 0);
int ret = WNetAddConnection2( myNetResource, "password", "username", 0); //by honglinlee
public class NetworkConnection : IDisposable
public NetworkConnection(string networkName,
var result = WNetAddConnection2(
throw new IOException("Error connecting to remote share",
~NetworkConnection()
WNetCancelConnection2(_networkName, 0, true);
private static extern int WNetAddConnection2(NetResource netResource,
private static extern int WNetCancelConnection2(string name, int flags,
Connected = 1,
RESOURCE_CONNECTED = 1,
RESOURCEUSAGE_CONNECTABLE = 0x00000001,
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
private static extern int WNetAddConnection2(NETRESOURCE lpNetResource, string lpPassword, string lpUsername, int dwFlags);
int result = WNetAddConnection2(myNetResource, password, user, 0); This is a function which connects to a share. Will throw a message box with any errors. Example connect code: ConnectDrive("\\server\share", "s:", "username", "password")
Public Function ConnectDrive(ByVal RemoteName As String, ByVal LocalName As String, Optional ByVal username As String = Nothing, Optional ByVal password As String = Nothing)
returnValue = WNetAddConnection2(myResource, password, username, 0)
MsgBox("Could not connect to " & myResource.RemoteName & ". The server said this: " & vbNewLine & vbNewLine & "(Error " & returnValue & ") " & errorM)
private static extern int WNetAddConnection3(IntPtr hWndOwner,
Private Shared Function WNetAddConnection3(ByVal hWndOwner As IntPtr, _
private const int CONNECT_INTERACTIVE = 0x8;
private const int CONNECT_PROMPT = 0x10;
WNetAddConnection3(hWnd, ref ConnInf, null, null,
CONNECT_INTERACTIVE | CONNECT_PROMPT); http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/wnetaddconnection2.asp
static extern int WNetCancelConnection2(string lpName, Int32 dwFlags, bool bForce);
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
''' The WNetCancelConnection2 function cancels an existing network connection.
''' You can also call the function to remove remembered network connections that are not currently connected.
Private Shared Function WNetCancelConnection2(ByVal lpName As String, _ The system updates the user profile with the information that the connection is no longer a persistent one if you pass this constant as <dwFlags>
private const int CONNECT_UPDATE_PROFILE = 0x1;
public static extern int WNetCancelConnection2(string lpName, Int32 dwFlags, bool fForce);
private const int CONNECT_UPDATE_PROFILE = 0x1;
int result=WNetCancelConnection2("Y:", CONNECT_UPDATE_PROFILE, true);
static extern int WNetCancelConnection2(string lpName, Int32 dwFlags, bool bForce);
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
''' The WNetCancelConnection2 function cancels an existing network connection.
''' You can also call the function to remove remembered network connections that are not currently connected.
Private Shared Function WNetCancelConnection2(ByVal lpName As String, _ The system updates the user profile with the information that the connection is no longer a persistent one if you pass this constant as <dwFlags>
private const int CONNECT_UPDATE_PROFILE = 0x1;
public static extern int WNetCancelConnection2(string lpName, Int32 dwFlags, bool fForce);
private const int CONNECT_UPDATE_PROFILE = 0x1;
int result=WNetCancelConnection2("Y:", CONNECT_UPDATE_PROFILE, true); 55: WNetEnumResource
RESOURCE_CONNECTED = 0x00000001,
RESOURCEUSAGE_CONNECTABLE =0x00000001,
RESOURCEUSAGE_ALL =(RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
RESOURCE_CONNECTED = &H1
RESOURCEUSAGE_CONNECTABLE = &H1
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE Or RESOURCEUSAGE_CONTAINER Or RESOURCEUSAGE_ATTACHED)
public static extern int WNetGetConnection([MarshalAs(UnmanagedType.LPTStr)] string localName, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName, ref int length);
Shared Function WNetGetConnection(<MarshalAs(UnmanagedType.LPTStr)> _
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer rc = WNetGetConnection("p:", rname, ref bsize);
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, _
WNetGetConnection(Microsoft.VisualBasic.Left(path, 2), UNC, length)
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
Dim err As Integer = WNetGetConnection(theDriveName, uncPathBuf, uncPathBuf.Capacity)
private static extern int WNetUseConnection
Connect dwFlags,
Declare Function WNetUseConnection Lib "mpr.dll" (TODO) As TODO
CONNECTED = 0x00000001,
CONNECTABLE = 0x00000001,
public enum Connect
public static void UseConnection(string localName, string remoteName, string username, string password)
ThrowIfError(WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null));
public static void UseConnection(string localName, string remoteName, bool promptUser = false)
ThrowIfError(WNetUseConnection(IntPtr.Zero, nr, null, null, promptUser ? Connect.INTERACTIVE | Connect.PROMPT : 0, null, null, null)); wininet58: FtpCommand hConnect (in) A handle returned from a call to InternetConnect. fExpectResponse (in) A Boolean value that indicates whether the application expects a data connection to be established by the FTP server. This must be set to TRUE if a data connection is expected, or FALSE otherwise.
Dim ret As Boolean = FTPCommandA(ConnectionHandle, False, 0, sCommand, IntPtr.Zero, IntPtr.Zero)
static extern bool FtpCreateDirectory(IntPtr hConnect, string lpszDirectory);
Private Shared Function FtpCreateDirectory(ByVal hConnect As IntPtr, ByVal lpszDirectory As String) As Boolean 60: FtpDeleteFile
static extern bool FtpDeleteFile(IntPtr hConnect, string fileName);
(ByVal hConnect As IntPtr, ByVal fileName As String) _ Cut off search results after 60. Please refine your search. |