From: Bob Butler on

"Steve Ricketts" <velocedge(a)hotmail.com> wrote in message
news:uNf4lElgKHA.2188(a)TK2MSFTNGP04.phx.gbl...
> The .bat file calls ImageMagick four times. The "%IM%" is the path to the
> ImageMagic executables and the .bat file shows the replaced values so it's
> writing the .bat file back out... just not executing it. The shell return
> value shows a value but I haven't done anything with it. I essentially
> don't have to log anything out, each line of the .bat file will produce
> another file so I can tell none of them are being executed.
>
> If objFSO.FileExists(sAry(2)) Then
> Set objTextFile = objFSO.OpenTextFile(sAry(2), ForReading)
> sWork = objTextFile.ReadAll
> objTextFile.Close
> sWork = Replace(sWork, "%IM%", Exe)
> Set objTextFile = objFSO.OpenTextFile(sAry(2), ForWriting)
> objTextFile.Write (sWork)
> objTextFile.Close
> ret = Shell(sAry(2), vbHide)
> End If
>
> .bat file contents:
>
> %IM%convert -size 80x20 gradient:#FFFFFF-#09355A normal.gif
> %IM%convert -size 80x20 gradient:#09355A-#FFFFFF hover.gif
> %IM%composite -compose CopyOpacity mask.gif normal.gif btn_normal.gif
> %IM%composite -compose CopyOpacity mask.gif hover.gif btn_hover.gif

Are you setting the working directory before you start the BAT file? If not
then that may be one difference compared to running it directly.

If the path contains spaces then it'd be best to have quotes around the full
path..
"%IM%convert.exe" -size 80x20 gradient:#FFFFFF-#09355A normal.gif
<etc>

If the BAT file always consists of just a sequence of executable command
lines then I'd consider reading the contents and executing each line from
the VB app sequentially rather than shelling out to a command environment
and running the BAT file itself. You'd then be able to log progress and
check individual return values.


From: Steve Ricketts on
I put the quotes in, good idea in case this is ever run in a location like
"c:\program files". Very good idea on the ComSpec avenue. I think that's
along the right idea with the user privileges, but unfortunately it modified
the .bat but didn't execute it.

sr

"Nobody" <nobody(a)nobody.com> wrote in message
news:OqFep6hgKHA.1460(a)TK2MSFTNGP06.phx.gbl...
> "Steve Ricketts" <velocedge(a)hotmail.com> wrote in message
> news:uBAkxXcgKHA.1540(a)TK2MSFTNGP06.phx.gbl...
>>I need to make a modification to a service written in VB6 that modifies
>>and then executes a .bat file. This runs fine when it's run from the
>>command line, but when I start it as a service, it creates the .bat file
>>but doesn't run it. I'm sure there's some sort of a permissions issue
>>with the account the service is running under but I've tried the local
>>system account as well as the administrator's account and there is no
>>difference.
>>
>> Can someone tell me what I need to do in order to run a .bat file from a
>> service?
>
> Too many things could be happening, and not enough information. Try using
> Shell, and surround the path by double-quotes. Example:
>
> sBatchFile = """" & "C:\Program Files\Test\test.bat" & """""
> Debug.Print sBatchFile
> Shell sBatchFile & " /SomeOption", vbHide
>
> Whether you use Shell or CreateProcess, the target process runs as the
> same user as the service. If using CreateProcess, I think you need to run
> "CMD.EXE /C file.bat", but instead of hard coding "CMD.EXE", use
> Environ("ComSpec").
>
>
>
From: Steve Ricketts on
BTW, I can make this work by calling the executables directly in each line
of the .bat file. But I would really like to know how to run a .bat file
from a service in case I ever need to do it again.

Thanks for all your help on this... User rights and privileges always kick
my butt! ;-)

sr

"Steve Ricketts" <velocedge(a)hotmail.com> wrote in message
news:uBAkxXcgKHA.1540(a)TK2MSFTNGP06.phx.gbl...
> I need to make a modification to a service written in VB6 that modifies
> and then executes a .bat file. This runs fine when it's run from the
> command line, but when I start it as a service, it creates the .bat file
> but doesn't run it. I'm sure there's some sort of a permissions issue
> with the account the service is running under but I've tried the local
> system account as well as the administrator's account and there is no
> difference.
>
> Can someone tell me what I need to do in order to run a .bat file from a
> service?
>
> Thanks,
>
> Steve

From: Steve Ricketts on
Actually, yes... I neglected to copy the CD <directory name> when I pasted
the bat file contents here. That was a very good thought though. I
actually had that problem the first time I ran the program from inside VB
and couldn't find the output! ;-) The directories involved don't have
spaces in them, but I've since added the quotes around them in case things
change.

I have made it work the way you suggested, executing each line individually,
but I'd like to know how to a .bat from a service in case I need to some

"Bob Butler" <noway(a)nospam.ever> wrote in message
news:uYrVrQlgKHA.5568(a)TK2MSFTNGP02.phx.gbl...
>
> "Steve Ricketts" <velocedge(a)hotmail.com> wrote in message
> news:uNf4lElgKHA.2188(a)TK2MSFTNGP04.phx.gbl...
>> The .bat file calls ImageMagick four times. The "%IM%" is the path to
>> the ImageMagic executables and the .bat file shows the replaced values so
>> it's writing the .bat file back out... just not executing it. The shell
>> return value shows a value but I haven't done anything with it. I
>> essentially don't have to log anything out, each line of the .bat file
>> will produce another file so I can tell none of them are being executed.
>>
>> If objFSO.FileExists(sAry(2)) Then
>> Set objTextFile = objFSO.OpenTextFile(sAry(2), ForReading)
>> sWork = objTextFile.ReadAll
>> objTextFile.Close
>> sWork = Replace(sWork, "%IM%", Exe)
>> Set objTextFile = objFSO.OpenTextFile(sAry(2), ForWriting)
>> objTextFile.Write (sWork)
>> objTextFile.Close
>> ret = Shell(sAry(2), vbHide)
>> End If
>>
>> .bat file contents:
>>
>> %IM%convert -size 80x20 gradient:#FFFFFF-#09355A normal.gif
>> %IM%convert -size 80x20 gradient:#09355A-#FFFFFF hover.gif
>> %IM%composite -compose CopyOpacity mask.gif normal.gif btn_normal.gif
>> %IM%composite -compose CopyOpacity mask.gif hover.gif btn_hover.gif
>
> Are you setting the working directory before you start the BAT file? If
> not then that may be one difference compared to running it directly.
>
> If the path contains spaces then it'd be best to have quotes around the
> full path..
> "%IM%convert.exe" -size 80x20 gradient:#FFFFFF-#09355A normal.gif
> <etc>
>
> If the BAT file always consists of just a sequence of executable command
> lines then I'd consider reading the contents and executing each line from
> the VB app sequentially rather than shelling out to a command environment
> and running the BAT file itself. You'd then be able to log progress and
> check individual return values.
>
>
From: Steve Ricketts on
I neglected to copy the CD <directory name> when I pasted the contents of
the bat file. I actually had that problem the first time I ran it inside
VB. All the directories in this case don't have spaces, but I've added
them in case things change... and they will. ;-) I have made the program
work by doing exactly what you've suggested, but I'd really like to know how
to run a bat from a service in case I have a situation where I can't execute
everything from the service.

sr

"Bob Butler" <noway(a)nospam.ever> wrote in message
news:uYrVrQlgKHA.5568(a)TK2MSFTNGP02.phx.gbl...
>
> "Steve Ricketts" <velocedge(a)hotmail.com> wrote in message
> news:uNf4lElgKHA.2188(a)TK2MSFTNGP04.phx.gbl...
>> The .bat file calls ImageMagick four times. The "%IM%" is the path to
>> the ImageMagic executables and the .bat file shows the replaced values so
>> it's writing the .bat file back out... just not executing it. The shell
>> return value shows a value but I haven't done anything with it. I
>> essentially don't have to log anything out, each line of the .bat file
>> will produce another file so I can tell none of them are being executed.
>>
>> If objFSO.FileExists(sAry(2)) Then
>> Set objTextFile = objFSO.OpenTextFile(sAry(2), ForReading)
>> sWork = objTextFile.ReadAll
>> objTextFile.Close
>> sWork = Replace(sWork, "%IM%", Exe)
>> Set objTextFile = objFSO.OpenTextFile(sAry(2), ForWriting)
>> objTextFile.Write (sWork)
>> objTextFile.Close
>> ret = Shell(sAry(2), vbHide)
>> End If
>>
>> .bat file contents:
>>
>> %IM%convert -size 80x20 gradient:#FFFFFF-#09355A normal.gif
>> %IM%convert -size 80x20 gradient:#09355A-#FFFFFF hover.gif
>> %IM%composite -compose CopyOpacity mask.gif normal.gif btn_normal.gif
>> %IM%composite -compose CopyOpacity mask.gif hover.gif btn_hover.gif
>
> Are you setting the working directory before you start the BAT file? If
> not then that may be one difference compared to running it directly.
>
> If the path contains spaces then it'd be best to have quotes around the
> full path..
> "%IM%convert.exe" -size 80x20 gradient:#FFFFFF-#09355A normal.gif
> <etc>
>
> If the BAT file always consists of just a sequence of executable command
> lines then I'd consider reading the contents and executing each line from
> the VB app sequentially rather than shelling out to a command environment
> and running the BAT file itself. You'd then be able to log progress and
> check individual return values.
>
>
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: A problem using PrintForm
Next: How To Know