Using Iexpress to wrap BAT file containing Env Variables

G

gary

(Had posted this in microsoft.public.windows.server.scripting but thought
mayube it would be better here. If anyone thinks there is a better forum to
post this in, please indicate. Thanks.)

Hello. I have a batch file that we'd like to run as a service so that it
runs before a user logs on. I have used Iexpress to wrap the BAT file into
an EXE, and used instsrv and srvany to create a service.

The problem is that the BAT file contains environment variables. When I run
the bat at the command prompt, it runs fine. But when I run the EXE created
by iexpress, it fails because none of the environment variables defined in
the BAT file are getting set..

Is there a way to have the EXE file created by iexpress preserve the
environment variables which are getting set in the BAT file?

A test batchfile I've created looks like this.

cd \servic~1
set fulltime=%time: =0%
set tm=%fulltime:~0,2%%fulltime:~3,2%%fulltime:~6,2%
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set var=%dt%%tm%
echo %var% > %var%.txt
exit

When this file runs as an EXE, all the env variables are set to blank, and
the testfile (%var%.txt) never gets created. When I run that BAT file, it
works fine.

Thanks.
 
P

Pegasus \(MVP\)

"gary" <gary@someplacesomewhere.net> wrote in message
news:uRxyEr5%23HHA.4956@TK2MSFTNGP06.phx.gbl...
> (Had posted this in microsoft.public.windows.server.scripting but thought
> mayube it would be better here. If anyone thinks there is a better forum
> to
> post this in, please indicate. Thanks.)
>
> Hello. I have a batch file that we'd like to run as a service so that it
> runs before a user logs on. I have used Iexpress to wrap the BAT file
> into
> an EXE, and used instsrv and srvany to create a service.
>
> The problem is that the BAT file contains environment variables. When I
> run
> the bat at the command prompt, it runs fine. But when I run the EXE
> created
> by iexpress, it fails because none of the environment variables defined in
> the BAT file are getting set..
>
> Is there a way to have the EXE file created by iexpress preserve the
> environment variables which are getting set in the BAT file?
>
> A test batchfile I've created looks like this.
>
> cd \servic~1
> set fulltime=%time: =0%
> set tm=%fulltime:~0,2%%fulltime:~3,2%%fulltime:~6,2%
> set dt=%date:~10,4%%date:~4,2%%date:~7,2%
> set var=%dt%%tm%
> echo %var% > %var%.txt
> exit
>
> When this file runs as an EXE, all the env variables are set to blank, and
> the testfile (%var%.txt) never gets created. When I run that BAT file, it
> works fine.
>
> Thanks.
>
>


This is a server newsgroup, not a scripting or batch newsgroup.
Try alt.msdos.batch.nt - this is where you will find the batch
file experts.
 
G

gary

"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:%23GHSe45%23HHA.536@TK2MSFTNGP06.phx.gbl...
>
> "gary" <gary@someplacesomewhere.net> wrote in message
> news:uRxyEr5%23HHA.4956@TK2MSFTNGP06.phx.gbl...
> > (Had posted this in microsoft.public.windows.server.scripting but

thought
> > mayube it would be better here. If anyone thinks there is a better

forum
> > to
> > post this in, please indicate. Thanks.)
> >
> > Hello. I have a batch file that we'd like to run as a service so that

it
> > runs before a user logs on. I have used Iexpress to wrap the BAT file
> > into
> > an EXE, and used instsrv and srvany to create a service.
> >
> > The problem is that the BAT file contains environment variables. When I
> > run
> > the bat at the command prompt, it runs fine. But when I run the EXE
> > created
> > by iexpress, it fails because none of the environment variables defined

in
> > the BAT file are getting set..
> >
> > Is there a way to have the EXE file created by iexpress preserve the
> > environment variables which are getting set in the BAT file?
> >
> > A test batchfile I've created looks like this.
> >
> > cd \servic~1
> > set fulltime=%time: =0%
> > set tm=%fulltime:~0,2%%fulltime:~3,2%%fulltime:~6,2%
> > set dt=%date:~10,4%%date:~4,2%%date:~7,2%
> > set var=%dt%%tm%
> > echo %var% > %var%.txt
> > exit
> >
> > When this file runs as an EXE, all the env variables are set to blank,

and
> > the testfile (%var%.txt) never gets created. When I run that BAT file,

it
> > works fine.
> >
> > Thanks.
> >
> >

>
> This is a server newsgroup, not a scripting or batch newsgroup.
> Try alt.msdos.batch.nt - this is where you will find the batch
> file experts.
>
>

Done. Thank you.

Had tried here since I was running on W2K3 Server using tools from the W2K3
Windows Resource Kit.
 
Back
Top Bottom