Batch file hanging

I have written a batch file that seems to hang when run remotely via the "system" command or via CMD <batchfilename>.

My batch file uses command line winzip to compress a load of files, then calls winzip self extractor via command line to change the zip into a .exe.
When this batch file is run from a normal cmd window it runs perfectly, no gui is ever shown, all quick and proper.
When invoked remotely (from oracle to a C dll that runs the system command with the batch file name), it runs until it gets to the winzip self extractor bit then stops and hangs.

To put another way: if i write another batch file with one line in it "cmd <old batch file name>" and run that, then it hangs also ie puts an entry in the processes list and never finishes.

Does this point to an  environmental difference between going into a normal cmd window and running a batch file (and it working) and doing it via the CMD method (and it not working)????

Please Help!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>> Does this point to an  environmental difference between going into a normal cmd window and running a batch file

I don't think so, but there's probably something in your environment that tells cmd to stay open once its job is finished (not the case on my box here). Could you please test again your 'other' batch, but this time changing from "cmd <old batch file name>" to "cmd /c <old batch file name>" ? If it works as expected, I'd suggest trying to use something like system("cmd.exe /c zipit.cmd") in the C code.

mwoolgerAuthor Commented:
I have tested it with the following:

c:\winnt\system32\cmd.exe /c c:\<name>.bat

Same problem. doh! winzip self extractor process created and just sits there. its almost as if the self extractor program has launched a gui, even though it hasnt and doesnt need to.
So, it's the winzip executable that is hanging ? ...

For debugging purposes, could you add some lines at the beginning of the batch :

set > batch.log

and additionally if you're running 2K

echo %CD% >>batch.log

The idea is to try to locate the environmental differences.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

mwoolgerAuthor Commented:
The results of running the batch file in this remote way are as follows. presumably there is something here which is different from that of a normal cmd window??
ALLUSERSPROFILE=C:\Documents and Settings\All Users
CommonProgramFiles=C:\Program Files\Common Files
Path=D:\Oracle\Ora81\bin;C:\Program Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Plan_Dissemination\PD_Task_Generation;C:\Program Files\WINZIP81;C:\Program Files\WinZip Self-Extractor
PROCESSOR_IDENTIFIER=x86 Family 15 Model 1 Stepping 2, GenuineIntel
ProgramFiles=C:\Program Files
USERPROFILE=C:\Documents and Settings\Default User
Hmm, looks like a permissions issue. I see no USERNAME and the USERPROFILE variable points to Default User. Strange...

Wild guess : it looks like the batch is started in some other context. I don't know the details of an Oracle install, but if it's a service which is running under a specific account, you might want to try to give that account enough rights over the files and directories which are to be manipulated...

Another suggestion : if you haven't done it yet, have some explicit cd commands in the batch just to make sure you are in the right directory.
mwoolgerAuthor Commented:
this is a little bizarre as my batch file works up until the winzip self extracting line so by thatpoint it has already created files and run an exe (the winzip command to zip files up) so some permissions presumably exist.
what ones would be missing and how do i add them? its win2k.

in terms of directory, the winzip self extractor is in the path so its obviously finding it, and the batch file is invoked with a full path too so i dont think its that. permissions sounds more likely. what like i said, what rights are missing?
mwoolgerAuthor Commented:
then also theres the fact that the batch file runs perfectly locally so how does this mean that there is a disparity between the rights assigned to an invoked command window and that assigned to a command window opened by conventional means?
I rather think it's something like : the self extracting creation tool somehow requires (although it apparently doesn not use it) to interact with the desktop and is getting prevented to do so when run in that service context.

Just got a stupid idea : that tool creates a .exe file right ? Are you running some AV on that box ? If yes, did you try to deactivate it ?
mwoolgerAuthor Commented:
we were running AV but disabling it has made no difference.

my gut feeling is that it looks like its trying to run a gui, just as if a default user was trying to invoke notepad.exe, it would appear in the processes list but never actually appear on screen as it is essentially being run remotely. of course the annoying thing is that it doesnt flick up a gui when running it locally, thereby giving some proof that it needs to interact with the desktop.

Is Oracle running under a specific account or is it LocalSystem ?
What version of winzip is this ? I can try to download it and reproduce the phenomenon here.
mwoolgerAuthor Commented:
it is winzip self extractor 2.2, but only the licensed version can be run from a batch file silently (unless you crack it of course).
oracle is running under a named account in this instance.

when i did the set command within a command window launched locally, the username environment variable was specified as being the user that was logged onto the win2k server. contrast this with the "Default User" of the remotely launched cmd window and this is the most obvious pointer to permissions etc.

[the batch file will be different each time as well so its a default user setting that needs to be changed rather than an attribute of the batch file]
>> it is winzip self extractor 2.2, but only the licensed version can be run from a batch file silently (unless you crack it of course).

Ah. looks like I won't be able to reproduce very quickly... Since it's registered, I could imagine that the executable is looking for the license key in the registry. Possibly it cannot find it when run from that account... At this point, I'd use regmon :
to try to find out. Start it, set a filter to the executable name of the self extractor, run it from the logged on user and compare against a run in the Oracle context. Maybe you'll be able to see something interesting.
In case the license key is located in a file, use filemon instead :

I'm sorry to tap in the dark like this, but that's the best I can do for now. Hopefully, an expert having experiencing a similar issue will be able to help more quickly.
mwoolgerAuthor Commented:
Interesting discussion. You said, you've "done this", but how ? Logged in interactively under that Oracle account or used the indicated procedure with an AT-scheduled cmd.exe ?
mwoolgerAuthor Commented:
instead of sending getting oracle (via this c dll) to execute a command "<batch filename>.bat" i did the at command. then on the server at the appropriate time the cmd window came up. in this window i then went and made something into a self extracting exe and lo it brought up a license agreement. i ok'd this and now have the following results:

1) i reran the batch file (via C dll etc) from a SQL session on the server and it went belly up again. just sat there.
2) i accidentally reran batch file (via C dll etc) from the SQl session on my client machine and it worked fine!!!!!!!!!

now this raises an important question: the "user" that is invoking this file - is it ME (ie my oracle username) or is it an "oracle" account. due to (1) this suggests the former (as this was the useraccount that did the AT command to get a window up etc and so from this users perspective has accepted the license agreement).
does this mean that every individual client machine will have to do this AT command method thingy to start with as a one off when i deliver the software? bizarre or what.

(I'll still give you the points when we've finished hypothesizing)

Well, that's the reason why I was trying to get you using regmon, because that first-time run agreement thingie is most likely stored somewhere in the registry. So, if you can write that key in the correct place at the moment your software is installed, the problem could be avoided altogether. What do you think ?

>> oracle is running under a named account in this instance

I would still try to log in interactively with that account and do the same operation (agreement ok). An AT-scheduled command is suppose to start in the context of the LocalSystem, which may possibly explain the differences you observed between remote and local sql sessions.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.