|
-
Apr 28th, 2003, 05:30 AM
#1
Thread Starter
Lively Member
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.
-
Apr 28th, 2003, 05:36 AM
#2
PowerPoster
since bat files work just fine with shell, you'll need to post your code to get any help
-
Apr 28th, 2003, 09:44 AM
#3
Thread Starter
Lively Member
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?
-
Apr 28th, 2003, 09:54 AM
#4
PowerPoster
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
-
Apr 28th, 2003, 01:37 PM
#5
Fanatic Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|