nmX.Memnoch Posted October 2, 2005 Share Posted October 2, 2005 (edited) Here is a KiX script that you could run on each machine at user logon. This will automatically update the file, but only if the workstation's information isn't already in the file. Be warned that if two users logon at the same time the first one that gets the file open will be the only one updated. However, since the other workstation's data isn't written it'll be written the next time someone logs onto that workstation.The script can probably be modified to delete any entries older than a set amount of time so that a workstation's information remains relatively current.I used to use something similar to this for gathering information on our PCs at user logon. For example, workstation name, who was logging on, what date/time they logged on, IP address, Windows version, Service Pack level, etc, etc.EDIT: I guess I could've also mentioned that KiXtart can also read from/write to native Excel and Access files. I'm pretty sure it'll even read from/write to a SQL database.; Allow script to be exited. Set to 'On' for testing and 'Off' for production; 'Break Off' will automatically log the user off if they force; the script to exit while it's runningBreak On; Common variables; Edit '<server name' and 'share name'; Users will need modify access to the share$FILE = "\\<server name\<share name\wkid.csv"$KEY = "HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration"; Check for the existence of the InterNetworX Systems key; If it exists, read the value of 'Workstation ID'; If it doesn't exists, exit scriptIf KeyExist("$KEY") = 1 $ID = ReadValue("$KEY","ReinstallMode")Else GoTo EndEndIf; Open the file for read to see if this workstation has already been checked; If this workstation has already been included in the file, the script will exitIf Open(1,$FILE,4) = 0 $LINE = ReadLine(1) While @Error = 0 If InStr($line,@WKSTA) $X = Close(1) GoTo end EndIf $LINE = ReadLine(1) LoopEndIf; Write the data to the file if not previously written$X = WriteLine(1,"@WKSTA,@DATE,@TIME,$ID"); Close the file$X = Close(1):endExit Edited October 2, 2005 by nmX.Memnoch Link to comment Share on other sites More sharing options...
chilifrei64 Posted October 3, 2005 Author Share Posted October 3, 2005 correct me if i am wrong but do I have to install this KiX software on all of my PCs before this script will run?If anyone can figure out how to get the batch script that Yzöwl wrote to output the file this will work perfectly and I would prefer this way. Any ideas anyone? Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted October 3, 2005 Share Posted October 3, 2005 (edited) correct me if i am wrong but do I have to install this KiX software on all of my PCs before this script will run?There's no install, but the KIX32.EXE executable does need to be available. The executable doesn't have to be on the local machine, it could be on a network share. Using GPO you can set a CMD file as a startup script that has this command in it:\\<server name>\<share name>\KIX32.EXE \\<server name>\<share name>\wkid.kixYou could also use the WKIX32 version and hide it with a /i switch:\\<server name>\<share name>\WKIX32.EXE /i \\<server name>\<share name>\wkid.kix Edited October 3, 2005 by nmX.Memnoch Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted October 3, 2005 Share Posted October 3, 2005 Ok...try this. It's been tested and you can run it from your workstation instead of on each workstation. I used part of Yzöwl's CMD script. Grab KiX from www.kixtart.org. There is no install...just drop KIX32.EXE in an empty folder with the .kix script. You can either run it from the command line or via a CMD file...either way the syntax to run it is simply:KIX32.EXE <scriptname.kix>; Allow script to be exited. Set to 'On' for testing and 'Off' for production; 'Break Off' will automatically log the user off if they force; the script to exit while it's runningBreak OnIf Exist("_PCNAMES.TXT") ? "Deleting old _PCNAMES.TXT file" Del "_PCNAMES.TXT"EndIfIf Exist("_OUTPUT.CSV") ? "Deleting old _OUTPUT.CSV file" Del "_OUTPUT.CSV"EndIf? "Querying for computer names"Shell '%COMSPEC% /C NET VIEW |FIND "\\" > _PCNAMES.TXT'? "Reading values and creating new _OUTPUT.CSV"If Open(1,"_PCNAMES.TXT",2) = 0 $LINE = ReadLine(1) While @ERROR = 0 $WK = Trim(Left($LINE,20)) $Val = ReadValue("$WK\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration","Workstation ID") If Open(2,"_OUTPUT.CSV",5) = 0 $X = WriteLine(2,"$WK,$Val@CRLF") $X = Close(2) EndIf $LINE = ReadLine(1) LoopElse ? "File not opened."EndIf Link to comment Share on other sites More sharing options...
TheFlash428 Posted October 3, 2005 Share Posted October 3, 2005 (edited) Figured I'd add my 2 cents--Here is a .vbs script that should do what you are trying to do. I just made some modifications to script I had been using for a different but similar purpose, and I apologize if there are still some unnecessary remnants of the old version.Steps to take:1. Replace "xxx" in lines 14 and 27 with the name of your domain.2. Written to capture a registry string value, if the key your looking for is a D_WORD then change "Getstringvalue" at line 130 to "Getdwordvalue" (result will be in Hex.)3. Other than that just copy to a text editor (notepad, or my favorite, notepad2), save with a .vbs extension and run it. You will need to make a folder called "C:\Logs"--this is the default location; you will be prompted to do so if it does not exist.' Declare the constantsConst HKLM = &H80000002 ' HKEY_LOCAL_MACHINEConst REG_SZ = 1 ' String value in registry (Not DWORD)Const ForReading = 1 Const ForWriting = 2' Set File objects...Set objFSO = CreateObject("Scripting.FileSystemObject")Set objDictionary = CreateObject("Scripting.Dictionary")Set objDictionary2 = CreateObject("Scripting.Dictionary")' Set string variablesstrDomain = "xxx" ' Your DomainstrPCsFile = "DomainPCs.txt" strPath = "C:\logs\" ' Create this folderstrWorkstationID = "C:\logs\WorkstationID.txt"If objFSO.FolderExists(strPath) ThenWscript.Echo "This program will collect Workstation ID on remote compter(s)"ElseWscript.Echo "This program will collect Workstation ID on remote compter(s)"WScript.Echo "Please create folder: <c:\Logs> then click OK."End If' Get list of domain PCs - Using above variables.strMbox = MsgBox("Would you like info for entire domain: xxx ?",3,"Hostname")'an answer of yes will return a value of 6, causing script to collect domain PC infoIf strMbox = 6 ThenSet objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not workobjDomain.Filter = Array("Computer")For Each pcObject In objDomainobjPCTXTFile.WriteLine pcObject.NameNextobjPCTXTFile.closeElse'an answer of no will prompt user to input name of computer to scan and create PC filestrHost = InputBox("Enter the computer you wish to get Workstation ID","Hostname"," ")Set strFile = objfso.CreateTextFile(strPath & strPCsFile, True)strFile.WriteLine(strHost)strFile.CloseEnd If' Read list of computers from strPCsFile into objDictionarySet readPCFile = objFSO.OpenTextFile(strPath & strPCsFile, ForReading)i = 0Do Until readPCFile.AtEndOfStream strNextLine = readPCFile.ReadlineobjDictionary.Add i, strNextLinei = i + 1LoopreadPCFile.Close' Run the procedure defined in the Sub routine GetWorkstationID()For each DomainPC in objDictionarystrComputer = objDictionary.Item(DomainPC)GetWorkstationID()NextSet objFilesystem = NothingWScript.echo "Finished Scanning Network check : " & strPathobjFSO.DeleteFile(strWorkstationID)objFSO.DeleteFile(strPath & strPCsFile)Sub GetWorkstationID()On Error Resume next' WMI connection to the operating system note StdRegProvSet objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv")If Err <> "0" ThenExit SubEnd If' Registry paths which hold the WorkstationID information.unKeyPath = "SOFTWARE\InterNetworX Systems\ICS\Configuration"unValueName = ("Workstation ID")' Enumerate Registry subkey paths for WorkstationID. 'objReg.EnumKey HKLM, unKeyPathSet objTextFile1 = objFSO.OpenTextFile(strWorkstationID, ForWriting,True)'For Each Subkey in arrSubKeysobjTextFile1.WriteLine (unKeyPath & (Enter))'Next' Read Registry info stored in the strWorkstationID fileSet objTextFile3 = objFSO.OpenTextFile(strWorkstationID, ForReading)'pipe the WorkstationID paths from the WorkstationID.txt file into a second dictionaryi = 0Do Until objTextFile3.AtEndOfStream strNextLine = objTextFile3.ReadlineobjDictionary2.Add i, strNextLinei = i + 1Loop ' These paths are used in the filenames you see in the strPathpcName = "SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\"pcNameValueName = "ComputerName"userPath = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon\"userValueName = "DefaultUserName"objReg.GetStringValue HKLM,pcName,pcNameValueName,pcValueobjReg.GetStringValue HKLM,userPath,userValueName,userValue' Build up the filename found in the strPathstrFileName = UserValue & "_" & "On" & "_" & PCValue & "_" & "Workstation ID" _& year(date()) & right("0" & month(date()),2) _& right("0" & day(date()),2) & ".txt"' Write each PC's software info file...Set objTextFile2 = objFSO.OpenTextFile(strPath & strFileName, ForWriting, True)' Writing info to the corresponding Software info file... objTextFile2.WriteLine(vbCRLF & "==============================" & vbCRLF & _"Current Workstation ID " & vbCRLF & Time & vbCRLF & Date _& vbCRLF & "ID for:" & "" & userValue & vbCRLF & "On System:" _& "" & pcValue & vbCRLF & "----------------------------------------" & vbCRLF)' First enumeration also clean up if error exists (Second enumaration omitted)For Each objItem in objDictionary2strKeyPath = "SOFTWARE\InterNetworX Systems\ICS\Configuration"objReg.GetstringValue HKLM ,strKeyPath, unValueName, strValueobjTextFile2.WriteLine (strValue)If Err Then objDictionary2.Remove(objItem)End IfNextEnd Subwscript.QuitCredit for the original script goes to Shane Rudy and Guy Thomas. Edited October 3, 2005 by TheFlash428 Link to comment Share on other sites More sharing options...
chilifrei64 Posted October 4, 2005 Author Share Posted October 4, 2005 nmX.MemnochI downloaded the exe from the site and it appears to of executed however no outputTheFlash428This is almost exactally what I am looking for... It runs and creates an output file.. however.. is there any way to get it to write to a single file as oppsed to a different file for each pc?Yzöwl you say that if the output isnt being created. there is a problem with the query.. if i run the REG QUERY \\computername\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID"from the command line i get a result.. this is the same query I have in the batch file. except with the %_NAME% instead of the computer namewhen i turn echo on.. it says basically says that it found it and that it is writing _OUTPUT.TXT but nothing shows up. (for testing purposes.. share and ntfs permissions are set to full control everyone) Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted October 4, 2005 Share Posted October 4, 2005 (edited) nmX.MemnochI downloaded the exe from the site and it appears to of executed however no outputThat's odd...the same exact code worked perfectly when I tested it.Try the attachment. Just extract to an empty folder. KIX32.EXE will also need to be in either the same folder or somewhere in your path (i.e. in %WINDIR%). Run wkid.cmd to execute the script.wkid.zip Edited October 4, 2005 by nmX.Memnoch Link to comment Share on other sites More sharing options...
TheFlash428 Posted October 4, 2005 Share Posted October 4, 2005 (edited) OK, let's give this a shot...Again, copy to text editor and save with .vbs extension. Edit lines 13 and 26 for your domain.I made the edits at home, so I didn't have a domain to test this on, but it should work (it worked when I ran it on my single PC). I'll test it on my domain tomorrow morning (GMT -4) and make additional edits if necessary.' Declare the constantsConst HKLM = &H80000002 ' HKEY_LOCAL_MACHINEConst REG_SZ = 1 ' String value in registry (Not DWORD)Const ForReading = 1 Const ForWriting = 2' Set File objects...Set objFSO = CreateObject("Scripting.FileSystemObject")Set objDictionary = CreateObject("Scripting.Dictionary")Set objDictionary2 = CreateObject("Scripting.Dictionary")' Set string variablesstrDomain = "xxx" ' Your DomainstrPCsFile = "DomainPCs.txt" strPath = "C:\logs\" ' Create this folderstrWorkstationID = "C:\logs\WorkstationID.txt"If objFSO.FolderExists(strPath) ThenWscript.Echo "This program will collect Workstation ID on remote compter(s)"ElseWscript.Echo "This program will collect Workstation ID on remote compter(s)"WScript.Echo "Please create folder: <c:\Logs> then click OK."End If' Get list of domain PCs - Using above variables.strMbox = MsgBox("Would you like info for entire domain: xxx ?",3,"Hostname")'an answer of yes will return a value of 6, causing script to collect domain PC infoIf strMbox = 6 ThenSet objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not workobjDomain.Filter = Array("Computer")For Each pcObject In objDomainobjPCTXTFile.WriteLine pcObject.NameNextobjPCTXTFile.closeElse'an answer of no will prompt user to input name of computer to scan and create PC filestrHost = InputBox("Enter the computer you wish to get Workstation ID","Hostname"," ")Set strFile = objfso.CreateTextFile(strPath & strPCsFile, True)strFile.WriteLine(strHost)strFile.CloseEnd If' Read list of computers from strPCsFile into objDictionarySet readPCFile = objFSO.OpenTextFile(strPath & strPCsFile, ForReading)i = 0Do Until readPCFile.AtEndOfStream strNextLine = readPCFile.ReadlineobjDictionary.Add i, strNextLinei = i + 1LoopreadPCFile.Close' Build up the filename found in the strPathstrFileName = "Workstation ID_" _& year(date()) & right("0" & month(date()),2) _& right("0" & day(date()),2) & ".txt"' Write each PC's software info file...Set objTextFile2 = objFSO.OpenTextFile(strPath & strFileName, ForWriting, True)For each DomainPC in objDictionarystrComputer = objDictionary.Item(DomainPC)' WMI connection to the operating system note StdRegProvSet objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv")' Registry paths which hold the WorkstationID information.unKeyPath = "SOFTWARE\InterNetworX Systems\ICS\Configuration"unValueName = ("Workstation ID")' These paths are used in the filenames you see in the strPathpcName = "SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\"pcNameValueName = "ComputerName"userPath = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon\"userValueName = "DefaultUserName"objReg.GetStringValue HKLM,pcName,pcNameValueName,pcValueobjReg.GetStringValue HKLM,userPath,userValueName,userValueobjTextFile2.WriteLine(vbCRLF & "==============================" & vbCRLF & _"Current Workstation ID " & vbCRLF & Time & vbCRLF & Date _& vbCRLF & "ID for:" & "" & userValue & vbCRLF & "On System:" _& "" & pcValue & vbCRLF & "----------------------------------------" & vbCRLF)strKeyPath = "SOFTWARE\InterNetworX Systems\ICS\Configuration"objReg.GetstringValue HKLM ,strKeyPath, unValueName, strValueobjTextFile2.WriteLine (strValue)'GetWorkstationID()NextSet objFilesystem = NothingWScript.echo "Finished Scanning Network check : " & strPath'objFSO.DeleteFile(strWorkstationID)objFSO.DeleteFile(strPath & strPCsFile)wscript.Quit Edited October 4, 2005 by TheFlash428 Link to comment Share on other sites More sharing options...
chilifrei64 Posted October 4, 2005 Author Share Posted October 4, 2005 (edited) This one seems to have a problem if the machine is unavailable(turned off/firewalled) it returns the error on line 70 character 1 which is Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _This would be fine if it misses some but it errors out and stopsIf i run it on a single machine that I know is online it works fine Edited October 4, 2005 by chilifrei64 Link to comment Share on other sites More sharing options...
TheFlash428 Posted October 4, 2005 Share Posted October 4, 2005 Add the commandOn error resume nextat line 68 and see if that makes a difference. Link to comment Share on other sites More sharing options...
chilifrei64 Posted October 4, 2005 Author Share Posted October 4, 2005 It worked. Thanks alot TheFlash428.. this is a big help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now