Results 1 to 5 of 5

Thread: Bat file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Lisbon, Portugal
    Posts
    69

    Unhappy Bat file

    Hi all.

    I need to run a bat file from vb. It does not work with shell "...."

    Can anyone help me, please?

    Thanks in advanced.
    Rita Jaques

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    since bat files work just fine with shell, you'll need to post your code to get any help

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Lisbon, Portugal
    Posts
    69
    I have this code(instead of shell, but it doesn't work):


    Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInherithandle As Long, ByVal dwPrecessId As Long) As Long
    Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Const SYNCHONIZE = &H100000
    Const INFINITE = &HFFFF


    Public Function SyncShell(ByVal pathname As String, windowstyle As Integer) As Boolean
    Dim ProcessID As Long
    Dim ProcessHandle As Long

    On Error GoTo syncshell_error
    ProcessID = Shell(pathname, windowstyle)
    ProcessHandle = OpenProcess(SYNCHONIZE, True, ProcessID)
    WaitForSingleObject ProcessHandle, INFINITE
    SyncShell = True
    Exit Function

    syncshell_error:
    On Error GoTo 0
    SyncShell = False
    Exit Function
    End Function

    Call SyncShell("g:\Informatica Finantia\Area Front-Office\KondorMidas\ftpmain.bat", 1)

    Could you help me?
    Rita Jaques

  4. #4
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    if you were doing this with shell, your problem would be the space in the path name, so I assume it's the same problem here, and if it is then once you fix that, you can just use shell and dispense with all that other stuff

    shell "complicatedpathnamewithoutspaces\batfilename.bat" will work just fine

    you could use the path name that uses only the DOS-equivalent 8-char names for each dir in the path

  5. #5
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    By the way...

    Originally posted by ritaab
    I have this code(instead of shell, but it doesn't work):


    Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInherithandle As Long, ByVal dwPrecessId As Long) As Long
    Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Const SYNCHONIZE = &H100000
    Const INFINITE = &HFFFF


    Public Function SyncShell(ByVal pathname As String, windowstyle As Integer) As Boolean
    Dim ProcessID As Long
    Dim ProcessHandle As Long

    On Error GoTo syncshell_error
    ProcessID = Shell(pathname, windowstyle)
    ProcessHandle = OpenProcess(SYNCHONIZE, True, ProcessID)
    WaitForSingleObject ProcessHandle, INFINITE
    SyncShell = True
    Exit Function

    syncshell_error:
    On Error GoTo 0
    SyncShell = False
    Exit Function
    End Function

    Call SyncShell("g:\Informatica Finantia\Area Front-Office\KondorMidas\ftpmain.bat", 1)

    Could you help me?
    If the path doesn't work because there are spaces in it, then I suggest you change the path string variable to ...

    Example:

    C:\Program Files\Microsoft Visual Studio\MyApp1\Batch1.bat

    To:

    C:\Progra~1\Micros~1\MyApp1\Batch1.bat

    ...

    Or if the path is user defined, simply create a function trimming the path changing it to 6 character if to long between each "\" "\" and adding "~1" ...

    There you go sire, hope it helps!

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width