eventcreate in CMD file

  • Thread starter Thread starter Gordon
  • Start date Start date
G

Gordon

I'm working on a CMD/VBS script package to do some automated cleanup
processes.
The VBS portion of the package that performs the bulk of the process,
also creates a
system environment variable that contains a string value that I want
to use as an argument
for the eventcreate command in my CMD file.
Try as I have, I just cannot figure out the syntax to get the
environment variable string
into the eventcreate line so that it executes properly and writes a
correctly formatted
event to the event log.

The environment variable name is JPEG_COUNT and I've verified in
testing that it is
properly created in my VBS script and is properly named and valued in
the registry.

Would someone please offer some suggestions on how to get this CMD
statement
to work by explaining how to get the /D argument right using the
environment variable?

eventcreate /T INFORMATION /ID 500 /L APPLICATION /SO Scripting /D %
%JPEG_COUNT%%

The preceding line results in the description field for the generated
event reading like this:
%JPEG_COUNT%

BTW The reason I'm not using the LogEvent method in my VBS script is
because I have no
control over the source and ID portions of the generated event log
entry and a different event
log filtering script relies on being able to filter /ID 500 /SO
Scripting events.

TIA
Gordon
 
Gordon said:
I'm working on a CMD/VBS script package to do some automated cleanup
processes.
The VBS portion of the package that performs the bulk of the process,
also creates a
system environment variable that contains a string value that I want
to use as an argument
for the eventcreate command in my CMD file.
Try as I have, I just cannot figure out the syntax to get the
environment variable string
into the eventcreate line so that it executes properly and writes a
correctly formatted
event to the event log.

The environment variable name is JPEG_COUNT and I've verified in
testing that it is
properly created in my VBS script and is properly named and valued in
the registry.

Would someone please offer some suggestions on how to get this CMD
statement
to work by explaining how to get the /D argument right using the
environment variable?

eventcreate /T INFORMATION /ID 500 /L APPLICATION /SO Scripting /D %
%JPEG_COUNT%%

The preceding line results in the description field for the generated
event reading like this:
%JPEG_COUNT%

BTW The reason I'm not using the LogEvent method in my VBS script is
because I have no
control over the source and ID portions of the generated event log
entry and a different event
log filtering script relies on being able to filter /ID 500 /SO
Scripting events.

TIA
Gordon

Eventcreate doesn't exist on my system, so I can't test this, but

The documentation shows each example of /D usage with the text-description
in double-quotes. This may or may not be because each of the messages in the
examples contains spaces. The syntax description implies that the quotes are
not required, but this is not explicit (SOP)

I'd try

.... /D "Jpeg count was %jpeg_count%"
 
billious said:
Eventcreate doesn't exist on my system, so I can't test this, but

The documentation shows each example of /D usage with the text-description
in double-quotes. This may or may not be because each of the messages in
the examples contains spaces. The syntax description implies that the
quotes are not required, but this is not explicit (SOP)

I'd try

... /D "Jpeg count was %jpeg_count%"

I'm wondering what the context of the OP's original command was, as he had
the percent signs doubled. That is a technique often used when a command
will be parsed twice by cmd.exe before being executed. This is necessary
sometimes when a batch file uses ECHO statements to write commands
containing variable references to another batch file, or to force multiple
parsing using call:

set target=abcdefghijklmnop
set/p from=what character to replace:
set/p to=what character to replace with:
call set target=%%target:%from%=%to%%%

In this case, it appears that the doubled percent signs were parsed once,
resulting in the expected value of "%jpeg_count%".

I also wonder if this is a CMD/VBS script package or a VBS/CMD script
package. If the vbs script is called by the cmd script, and the expectation
that environment variables set by the vbs script will be available to the
cmd file that invoked the vbs script, well, that is just not going to work.

If the vbs calls a simple cmd just for the purpose of executing the
eventcreate command, it could either run that executable directly using
..run, create the equivalent batch file on the fly with the desired values
embedded literally rather than by trying to pass them through environment
variables, or the batch file could be modified to accept the variable
information through positional parameters.


/Al
 
Billious was right: I needed to embed my env var ref in double quotes
- like this:
.... /D "%JPEG_COUNT%"
I KNEW that the syntax for the /D argument required d-quotes but
thought that since my string already had them, they weren't needed.

Al is also right, insofar as the env var being available in its
updated form.
The package consists of a CMD script that calls a VBS script (which
does the bulk of the work), and I was having difficulties trying to
figure out how to pass the event description string - easy to make in
the VBS part - back out to the CMD part where I could then use it with
the XP/2003 Server based eventcreate command line tool.
Now when I run the test package, the NEW env var is in the registry
but the eventcreate is using the older string.
Also, the only reason I showed double-percent signs is it was just one
of the many combinations I tried in my testing. No other significance
than that.

So, methinks I have to rethink the whole package design....

Thanks for the help guys, I knew it was something simple.
/Gordon
 
Gordon said:
Billious was right: I needed to embed my env var ref in double quotes
- like this:
... /D "%JPEG_COUNT%"
I KNEW that the syntax for the /D argument required d-quotes but
thought that since my string already had them, they weren't needed.

Al is also right, insofar as the env var being available in its
updated form.
The package consists of a CMD script that calls a VBS script (which
does the bulk of the work), and I was having difficulties trying to
figure out how to pass the event description string - easy to make in
the VBS part - back out to the CMD part where I could then use it with
the XP/2003 Server based eventcreate command line tool.
Now when I run the test package, the NEW env var is in the registry
but the eventcreate is using the older string.
Also, the only reason I showed double-percent signs is it was just one
of the many combinations I tried in my testing. No other significance
than that.

So, methinks I have to rethink the whole package design....

Thanks for the help guys, I knew it was something simple.

Simple to diagnose, less so to resolve ;-(

So, what else does your cmd script do beyond starting the vbs script and
then attempting to process some commands based on values the vbscript tried
to return in environment variables? If that is it, why not have the vbscript
use the .run method to execute the desired eventcreate command? Or to have
it run a batch file containing the basic eventcreate command with batch
parameters supplying the info you tried to pass back in environment
variables? A more convoluted approach would be for your vbscript to create a
batch script to be called by the originating batch script once the vbscript
has finished running.

/Al
 
Back
Top