?
Solved

Creating an evironment variable using an batch script with WMI

Posted on 2005-04-05
2
Medium Priority
?
1,801 Views
Last Modified: 2008-02-01
I've been googling for hours now and just can't find any information. I'm not really formiliar with batch programming and don't know how to some things.
First of all I want to set a variable with a wmi command. This is the command for looking up a serial key of an computer: wmic csproduct get IdentifyingNumber

I want this in a variable because I want to write this to an environment variable on a computer. Does anybody know how to set a variable with the value from a dos commandline function and how do I create an environment variable with the value from the dos command.

I hope somebody can help me because I've been searching for so long and can't find it. this i the code so far with some tests:

@echo off
rem clear screen
cls
rem Variables

rem Start
echo #####################################################
echo #################-=][ WMI BATCH ][=-#################
echo #####################################################

rem Display the value from the command
wmic csproduct get IdentifyingNumber /value

rem Declare the variable
set _IDNumber = wmic csproduct get IdentifyingNumber /value

rem Display the value of the variable
echo %_IDNumber%

echo on


Thanx in advance.
0
Comment
Question by:Sander Stad
[X]
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
2 Comments
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 375 total points
ID: 13706980
Hey sstad.

You can capture the output of a command, in MS-DOS, like so:

for /f "delims=" %%O in ('wmic csproduct get IdentifyingNumber /value') do set _IDNumber=%%O

Now, you can just do:

echo %_IDNumber%

As for assigning it as an Environment Variable, it differs with OS... What Operating System are you using for this?

Regards,
>> IM
0
 
LVL 15

Expert Comment

by:sr75
ID: 13709949
I have never done it, but environmental variables reside in the HKCU>Environment and HKCU>Volatile Environment keys.  Since you are using WMI, you should be able to access the registry and add the necessary values to these keys.  I however would do it in a vbscript and not in a batch script.  Here are some examples from MS:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__connecting_to_the_wmi_service.asp 
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

800 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