Batch file auto exit

Microsoft Windows xp professional w/sp2
July 12, 2010 at 19:25:08
Specs: Windows XP, 2.8Ghz Pentium4
Hi All,

I have this batch file which is working fine on other system except one. When executing the following line:

for /f "tokens=1 delims=: " %%A in ('call who') do set nowuser=%%A

the batch just exit automatically with the command prompt closed . I suspect it is windows/user settings. All the system have same config and using winxp sp2.

Any gurus can point me to the right direction?


See More: Batch file auto exit

Report •

July 12, 2010 at 21:33:01
is that one line the entirety of the script? If so, nothing else would really be expected cause all it does is set an environment variable ("nowuser") silently.
If not, put in some echos and pauses in strategic places in the script to see how far it gets and what's what before the
window closes.

Report •

July 13, 2010 at 05:59:00
hi nbrane, thanks for your reply.

I have set pause to debug and find out this is the line that causes the script to exit. This line appear in the beginning of the script which is to verify current user account and store to this nowuser variable and would be compared to a local variable useradmin before proceeding to other tasks.

This script is to be run only in admin account and this check is to prevent the script to be run from other user account.

I have manually entered 'call who' in command prompt and it managed to output administrator as the first token. I guess its the script unable to store this token to nowuser variable. So how do i proceed from here?

This batch file has been set full control access under admin account and is already running admin account.

Report •

July 14, 2010 at 11:35:45
I don't have WHO so I dunno.

It may help to post the output of WHO.

Helping others achieve escape felicity


Report •

Related Solutions

July 14, 2010 at 16:45:48
yeah, it does look like who.bat may be the problem - maybe post the who.bat content while you're at it.
i figure there's a system command to iterate the privelage/permissions level, just don't know it offhand. might look into substituting that if you know what it is.

Report •

July 14, 2010 at 18:02:08
hi guys, apologize for not giving the details.
'who' is actually the unix command coming from SFU which is installed to every system.

eg output
Kevin ttyn00 Jul 15 09:00

i tried using other function call but the result is the same. So i dont think the problem comes from there.
I even reinstall SFU on this system but to no avail.
It could be some windows env setting, admin user access rights corrupted, etc but i can't nail down the cause

Report •

July 14, 2010 at 18:18:37
I'm not an expert, but doesn't call run whatever what in a second batch file?


Report •

July 14, 2010 at 19:07:40
It is not another batch file but a command coming from SFU. If u have installed to ur sys, u will find this command under drive:\SFU\bin\. This directory has been included in the PATH env, so u can execute 'who', 'ls', 'pwd', etc anywhere in the command prompt.

here is the link to download sfu:

Report •

July 14, 2010 at 20:33:36
Obviously, your script is bombing. But because you're not running it though the Command Prompt proper, you don't see the error message. Do that (or put in logging), then at least you won't be blindly guessing.

Report •

July 14, 2010 at 21:30:49
if i enter the whole line in the command prompt & enter, the command prompt close immediately.
if i run through a batch file with only the line and a pause, the prompt will still close immediately with no pause
if i set the output to a log file, after the prompt close, there is no log file generated for me to see any error.

If i do these exactly in working system, i will see the output and the nowuser variable generated & set to current user account

Report •

July 15, 2010 at 12:21:59
if i enter the whole line in the command prompt & enter, the command prompt close immediately.
Assuming there's no user error, then WHO is crashing the Command Prompt. That's not impossible, but pretty uncommon for something released by Microsoft.

Check the hash of that WHO and compare it to a known good copy. Also, check and make sure you're running the version of WHO you think you're running. Also, don't CALL programs. Only CALL other command scripts.

Report •

July 15, 2010 at 12:42:22
grasping here, but might try wrapping it in cmd:
cmd /c "who" > who.log

Report •

Ask Question