Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Batch file hanging

Posted on 2003-11-12
Medium Priority
Last Modified: 2013-12-03
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!
Question by:mwoolger
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
LVL 16

Expert Comment

ID: 9730713
>> 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.


Author Comment

ID: 9730795
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.
LVL 16

Expert Comment

ID: 9730854
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.
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


Author Comment

ID: 9730898
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
LVL 16

Expert Comment

ID: 9730945
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.

Author Comment

ID: 9730971
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?

Author Comment

ID: 9730980
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?
LVL 16

Expert Comment

ID: 9731067
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 ?

Author Comment

ID: 9731155
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.

LVL 16

Expert Comment

ID: 9731212
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.

Author Comment

ID: 9731250
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]
LVL 16

Expert Comment

ID: 9731501
>> 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.
LVL 16

Expert Comment

ID: 9731976
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 ?

Author Comment

ID: 9732049
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)

LVL 16

Accepted Solution

_nn_ earned 1000 total points
ID: 9732180
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.

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question