|
-
August 28th, 2008, 08:31 AM
#1
trying to inventory our computers
Hello,
I have been reading through the forums for a while and received some great advice. But I'm working on this one project and can't seem to get it right. I'm very new to scripting (only been doing it a few weeks) and can't figure out why this script is acting like it does. The script is
Code:
@echo off
If exist c:\inventoried goto A
md c:\inventoried
systeminfo /nh /fo csv >> N:\is\scripts\inventory\inventory.csv
cscript n:\is\scripts\inventory\servicetag.vbs >> n:\is\scripts\inventory\servicetags\%computername%.txt
goto A
:A exit
When it runs the first time one a computer it will bypass the if statement and create the folder "c:\inventoried", but then it will exit. If you go in and delete the folder it will go through and do the script correctly. I have tried this on 6 different machines and gotten the same reaction each time. The problem with having to go in and manually delete a folder for it to work is we need to run this on a little over 300 computers and don't want to have to physically touch all of them. Do you guys have any suggestions on why the code may be acting the way it is? Thanks in advance for your help.
Edited: to put in code boxes.
Last edited by sbevill7; August 28th, 2008 at 08:52 AM.
-
August 28th, 2008, 08:40 AM
#2
Re: trying to inventory our computers
Welcome to (posting on) the Forums! 
You have the problem...because that's what you've programmed it to do! If the folder exists, it's told to goto A, so it'll jump to the bottom of the script...
What condition do you want to use? if it's an Inventory Once program, then your code surely is correct, and it acting correctly?
Last edited by javajawa; August 28th, 2008 at 08:45 AM.
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
August 28th, 2008, 08:51 AM
#3
Re: trying to inventory our computers
Thank you for the welcome .
What I was intending to do is only have this script run once per computer (an inventory with 200 copies of the same computer isn't very useful). My line of thought was to have the script first check to see if this folder exists (which at this point it should not):
Code:
@echo off
If exist c:\inventoried goto A
Since it does not exist the if statement is not triggered so it moves on to the next part:
Code:
md c:\inventoried
systeminfo /nh /fo csv >> N:\is\scripts\inventory\inventory.csv
cscript n:\is\scripts\inventory\servicetag.vbs >> n:\is\scripts\inventory\servicetags\%computername%.txt
goto A
It will then create the folder (so that next time the user logs on it will see the folder and skip the inventory process), inventory the machine, and exit the script.
Like I said, that is just how it worked in my head which doesn't always translate well to notepad. Sorry for not making the intentions of the script clearer. I see your thought process on that and it makes perfect sense, but I don't know if it would do what we are really looking for.
-
August 28th, 2008, 09:05 AM
#4
Re: trying to inventory our computers
Hmmm...
I can't see anything wrong with the theory or the coding of the script - in fact, I think I haven't quite cottoned onto what the error you're getting is!
 Originally Posted by sbevill7
When it runs the first time on a computer it will bypass the if statement and create the folder "c:\inventoried"
That all makes sense...
 Originally Posted by sbevill7
, but then it will exit.
I assume you mean the next time you run it. However, is the second run on the same machine, or did you try running it once on on machine, then once on another, without touching the folders?
 Originally Posted by sbevill7
If you go in and delete the folder it will go through and do the script correctly. I have tried this on 6 different machines and gotten the same reaction each time.
Well, at least it's consistent...and it makes perfect sense, unless I'm missing something here...
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
August 28th, 2008, 09:24 AM
#5
Re: trying to inventory our computers
What i'm wanting it to do is on the first time it is run for it to skip the if statement, create the folder, inventory the machine, and exit. Then every time a user logs on after that it will catch on the if statement and exit (without creating the folder or running the inventory).
What is actually happening. The first time you run the script it skips the if statement (because the folder hasn't been created), and makes the folder, but after that it just exits. I'm wanting it to run the inventory commands. If you go back in and run it again it hits the if statement and exits. So without manually messing with the folder the systeminfo and vbs calls are never ran.
-
August 28th, 2008, 10:04 AM
#6
Re: trying to inventory our computers
Have you tried removing @echo off, and seeing if an error is occurring?
Of sticking in something other than the script calls you've got, to see if anything runs?
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
August 28th, 2008, 10:06 AM
#7
Re: trying to inventory our computers
That is a brilliant idea that I have not tried yet. Let me try a few things and see if I get anywhere. Thanks for your help, javajawa! I'll post back when I know more.
-
August 28th, 2008, 01:39 PM
#8
Re: trying to inventory our computers
I have to admit, I don't think I would have ever guessed the cause of the issue. After a painstaking amount of trial and error and error and error I finally discovered that it was the creation and updating of the user profile at logon that was messing up the script. Once I found this out I put in a piece of code at the beginning like this:
Code:
ping 127.0.0.1 -n 16
This code gave the profile enough time to load before starting to look for the folder. This was really only a problem if the user had never logged onto the machine before (which was the case with my test user), but adding that ping command gave everything enough time to balance out. Thank you so much, javajawa for helping me out. Now we will be able to inventory hundreds of our machines in just a few short days with virtually no added work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|