borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Getting windows folder location)Next Topic (Get Text in txt file) New Topic New Poll Post Reply
AndreaVB Forum : VB General : an impossible thing(Loading cmd commands output to text file)
Poster Message
Gharakhanlou
Level: Scholar

Registered: 30-04-2005
Posts: 40

icon an impossible thing(Loading cmd commands output to text file)

hi

i think this is impossible thing with VB

i have to get mac address from vb by WMI
but i couldnt find any solution.
now i have one way to do

Loadin cmd cmmands like "ipconfig /all" to text file and searching mac address from it
can someone do help me?

thank u everyone

[Edited by Gharakhanlou on 22-08-2005 at 05:48 PM GMT]

19-08-2005 at 12:56 PM
View Profile Send Email to User Show All Posts | Quote Reply
dreamvb
Level: Trainee

Registered: 17-08-2005
Posts: 2
icon Re: an impossible thing(Loading cmd commands output to text file)

Hi you can get the outputs of ipconfig by createing a DOS pipe. you can then phase the outputs to find the address.

Start a new vb project and add a class file call it DosStdOut
and place in this code.

Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type

Private Type STARTUPINFO
    cb As Long
    lpReserved As Long
    lpDesktop As Long
    lpTitle As Long
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Byte
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Private Const NORMAL_PRIORITY_CLASS As Long = &H20
Private Const STARTF_USESHOWWINDOW As Long = &H1
Private Const STARTF_USESTDHANDLES As Long = &H100
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF      '  Infinite timeout

Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function CreatePipe Lib "Kernel32.dll" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
Private Declare Function CreateProcess Lib "Kernel32.dll" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private m_Outputs As String

Public Property Get Outputs()
    Outputs = m_Outputs
End Property

Public Function DosPipe(lpFileCommand As String, Optional PipeReadSize As Long, Optional lpAppName As String = vbNullString, Optional lpCurDir As String = vbNullString) As Boolean
Dim si As STARTUPINFO, pi As PROCESS_INFORMATION, sa As SECURITY_ATTRIBUTES
Dim hPipe As Long, hReadPipe As Long, hWritePipe As Long, lBytesRead As Long
Dim StrBuffer As String, StrA As String, iRet As Long

    DosPipe = False
    StrBuffer = Space(PipeReadSize)

    If Len(Trim(lpFileCommand)) = 0 Then Exit Function 'No lpFileCommand was found
    If PipeReadSize = 0 Then Exit Function ' Exit if no PipeReadSize was found
    
    With sa
        .nLength = Len(sa)
        .lpSecurityDescriptor = 0
        .bInheritHandle = True
    End With
    
    ' Create a new pipe
    hPipe = CreatePipe(hReadPipe, hWritePipe, sa, 0)
    
    If hPipe = 0 Then
        'if pipe is zero we exit
        Exit Function
    Else
        'fill in the start up information
        With si
            .cb = Len(si) 'Size of this type
            .dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
            .hStdOutput = hWritePipe 'Output pipe hangle
            .hStdError = hWritePipe
            .wShowWindow = 0 ' Hide the console
        End With
    End If

    iRet = CreateProcess(lpAppName, lpFileCommand, sa, sa, True, NORMAL_PRIORITY_CLASS, 0, lpCurDir, si, pi)
    
    If iRet = 0 Then
        Exit Function
    Else
        CloseHandle hWritePipe 'Close the WritePipe
        Do
            iRet = ReadFile(hReadPipe, StrBuffer, PipeReadSize, lBytesRead, 0&)
            StrA = StrA & Left(StrBuffer, lBytesRead)
        Loop While iRet <> 0
    End If
    
    'Close the hangles
    CloseHandle pi.hProcess
    CloseHandle pi.hThread
    CloseHandle hReadPipe
    
    m_Outputs = StrA
    StrA = ""
    
    StrBuffer = ""
    lBytesRead = 0
    
    DosPipe = True
    
End Function

Sub Wait(lPid As Long)
Dim Pro As Long
    Pro = OpenProcess(SYNCHRONIZE, 0, lPid)
    Call WaitForSingleObject(Pro, INFINITE)
    Call CloseHandle(Pro)
End Sub


Private Sub Class_Initialize()
    m_Outputs = ""
End Sub

Private Sub Class_Terminate()
    m_Outputs = ""
End Sub



Now add a new command button to your form and palce all this code into the general declarances of the form, Press F5 and click the button.

Private Sub Command1_Click()
    With DosOut
        If .DosPipe("c:\windows\system32\ipconfig.exe /all", 256, , vbNullString) = False Then
            MsgBox "Error reading pipe", vbInformation, "Error"
            Exit Sub
        Else
            MsgBox .Outputs ' here are you outputs tp phase
        End If
    End With
End Sub

Private Sub Form_Load()
    Set DosOut = New DosStdOut
End Sub


hope that may help you a little.



____________________________
http://www.eraystudios.com/forum
Programming Forum help and more.

19-08-2005 at 05:34 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Gharakhanlou
Level: Scholar

Registered: 30-04-2005
Posts: 40
icon Re: an impossible thing(Loading cmd commands output to text file)

thank u dreamvb

really your solution were so helpfull
finally you helped me to get mac address.

thank u more and more

thank u

22-08-2005 at 02:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : an impossible thing(Loading cmd commands output to text file)
Previous Topic (Getting windows folder location)Next Topic (Get Text in txt file) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder