Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel
Killing IPC with NetUseDel Killing IPC with NetUseDel
Killing IPC with NetUseDel
Go Back  Xtreme Visual Basic Talk > > > Killing IPC with NetUseDel


Reply
 
Thread Tools Display Modes
  #1  
Old 12-04-2010, 02:44 PM
AgentSmithers AgentSmithers is offline
Contributor
 
Join Date: Jan 2005
Location: SOCal
Posts: 492
Default Killing IPC with NetUseDel


Quote:
New connections will be remembered.


Status Local Remote Network

-------------------------------------------------------------------------------
OK \\winxp-base02\IPC$ Microsoft Windows Network
The command completed successfully.
Code:
<DllImport("C:\windows\system32\netapi32.dll")> Public Shared Function NetUseDel(ByRef UncServerName As String, ByVal UseName As String, ByVal ForceCond As ForceCond) As UInt32
    End Function

    Const USE_LOCAL_PARMNUM As Integer = 1
    Const USE_REMOTE_PARMNUM As Integer = 2
    Const USE_PASSWORD_PARMNUM As Integer = 3
    Const USE_ASGTYPE_PARMNUM As Integer = 4
    Const USE_USERNAME_PARMNUM As Integer = 5
    Const USE_DOMAINNAME_PARMNUM As Integer = 6
    Const USE_OK As Integer = 0
    Const USE_PAUSED As Integer = 1
    Const USE_SESSLOST As Integer = 2
    Const USE_DISCONN As Integer = 2
    Const USE_NETERR As Integer = 3
    Const USE_CONN As Integer = 4
    Const USE_RECONN As Integer = 5
    Public Enum ConType As Integer
        USE_WILDCARD = -1&
        USE_DISKDEV = 0
        USE_SPOOLDEV = 1
        USE_CHARDEV = 2
        USE_IPC = 3
    End Enum

 Dim Ret = NetUseDel(vbNullString, "\\" & TextBox1.Text & "\IPC$", ForceCond.USE_NOFORCE)
NetUseDel: 2250 (Connect does not exist)

keeps saying that it does not exist, and yes TextBox1.text = "winxp-base02"

It clearly shows in CMD with net use that the connection does exist, anyone know Why I can't kill IPC$ or from what you see should work?
__________________
Http://ControllingTheInter.Net
My General Computer Forum, From Security To Programming And Back To Troubleshooting.

Last edited by AgentSmithers; 12-04-2010 at 03:41 PM.
Reply With Quote
  #2  
Old 12-04-2010, 04:17 PM
jo0lsKilling IPC with NetUseDel jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

I got the same thing with your code, though it worked for my simpler tests. It was only once I ventured out of my cosy duvet palace to switch on another computer on the network that I could reproduce the error.

I get a bit more pedantic with the marshalling code and then it worked.

The C is:

Code:
NET_API_STATUS NetUseDel(
  __in          LMSTR UncServerName,
  __in          LMSTR UseName,
  __in          DWORD ForceCond
);
So:
- the first parameter can just go ByVal. Send Nothing instead of VBNullString.
- the first and second are of type LMSTR, which is a redeclared LPWSTR. That's a Unicode string, so decorate the call with the Unicode charset attribute and marshal the strings as LPWStr:

Code:
Imports System.Runtime.InteropServices
Imports System.ComponentModel

Module Module1

    Private Class NativeMethods
        <DllImport("netapi32", CharSet:=CharSet.Unicode)> _
        Public Shared Function NetUseDel( _
            <MarshalAs(UnmanagedType.LPWStr)> ByVal uncServerName As String, _
            <MarshalAs(UnmanagedType.LPWStr)> ByVal useName As String, _
            ByVal forceCond As ForceCond) As Integer
        End Function
    End Class

    Private Enum ForceCond
        USE_NOFORCE = 0
        USE_FORCE = 1
        USE_LOTS_OF_FORCE = 2
    End Enum

    Public Sub Main()
        Dim result As Integer = NativeMethods.NetUseDel(Nothing, "\\ORAC\IPC$", ForceCond.USE_NOFORCE)
        If result = 0 Then
            Console.WriteLine("success")
        Else
            Console.WriteLine((New Win32Exception(result)).Message)
        End If
        Console.ReadKey()
    End Sub

End Module
Reply With Quote
  #3  
Old 12-04-2010, 07:35 PM
AgentSmithers AgentSmithers is offline
Contributor
 
Join Date: Jan 2005
Location: SOCal
Posts: 492
Default

Yeah I figured, reading up on MSDN if you use any force at all you need to have it be unicode. Thanks.
__________________
Http://ControllingTheInter.Net
My General Computer Forum, From Security To Programming And Back To Troubleshooting.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel Killing IPC with NetUseDel
Killing IPC with NetUseDel
Killing IPC with NetUseDel
 
Killing IPC with NetUseDel
Killing IPC with NetUseDel
 
-->