Link to home
Start Free TrialLog in
Avatar of locpham
locpham

asked on

Script to get Computer Name

Hi,

I am writting a script to extract Windows server NT/2000/2003 user accounts password information for auditing. I achieved almost all information I need from my script.

However, I could not get this piece from my script to work with NT server (It works in 2K and 2K3), this small script come from Microsoft scripting center:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSettings = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_ComputerSystem")
For Each objComputer in colSettings
    Wscript.Echo "Computer Name: " & objComputer.Name
Next

This script works on W2K and W2K3 server but not NT. My goal is modify and add this to my script to get computer name and feed it back as a variable so I don't need to hard code or type in the computer name. I need to run my srcipt on different domains and stand alone server from NT to W2K3.

My test NT server already has ADSI installed. What do I need to do make this script works on NT?

Thanks


Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

You can use the environment variable %computername% - but how to incorporate that into a vbscript I'm not sure.  
Avatar of locpham
locpham

ASKER


I believe %computername% is used in a batch file. This ia VBS script.

I did try  %computername% before but it didn't work. May be I don't know how!
Are you sure the NT4 system have VBScript on them?  AS I recall, they didn't come with it, but I do think there was an add-on.  (One reason I never use it - I can't be sure the NT 4 systems are going to be able to execute it).
Avatar of locpham

ASKER


I am 100% sure. My VBS script already works on NT. It extracts user accounts, last time logon, never logon, last change password, expiration date, account expired and account disabled information.

The only draw back with my script is I have to manually enter the server name when I run it from different servers/domains. I want to automate it by having the script gets the computer name by itself.
SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of locpham

ASKER


Before I posted my question. I came accross the same link you prefer to. Basically the script in the link uses the same scripting method/syntax. But I will look at it again...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of locpham

ASKER


This script work! Now I need to add it to my script.

I'd like to give 30 point to leew for his effort. 70 point to oBdA.
Well, go right ahead, then ;)
More than one Expert helped solve my problem. What do I do?
https://www.experts-exchange.com/help.jsp#hi69
ASP.NET copy and paste code into the page load for the form.

        // get the name of the computer the web page is running on.
        System.Net.IPHostEntry host = new System.Net.IPHostEntry();
        host = System.Net.Dns.GetHostByAddress(Request.ServerVariables["REMOTE_HOST"]);
        ComputerName = host.HostName;