reddurex

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    reddurex
    Member
    in reply to: Read, parse, then write to a file #388047

    Re: Read, parse, then write to a file

    To do this in batch, you’d have to do something like this to start:

    Code:
    set file=%temp%%random%.txt
    findstr /I “” “Z:file.txt” > !file! & set /p A1=< !file! & echo !A1!
    findstr /I "” “Z:file.txt” > !file! & set /p A2=< !file! & echo !A2!<br /> findstr /I "<track>” “Z:file.txt” > !file! & set /p A3=< !file! & echo !A3!<br /> del /f/q !file!</track>

    Then what I would do is use a for loop and delimit by “>”, attempt to grab the value at token 2, and get rid of everything starting with the first “< " to get the value itself.

    I could do it, but if someone has already posted a VBScript solution then that works.

    Avatar
    reddurex
    Member
    in reply to: DOS Batch file to pull certain info from a text file #388046

    Re: DOS Batch file to pull certain info from a text file

    Dragokas;272169 wrote:
    @echo off
    Set Src=file.txt
    Set Dest=Out.txt
    for /f “UseBackQ tokens=14,19 delims=” %%a in (“%Src%”) do (
    if “%%~a”==”O” echo %%~b>> “%Dest%”
    )

    This isn’t comma delimited however, and you’re not checking for the 3 character value.

    By 3 character value, you mean anything A-Z? Or just 3 in length? Try this:

    Code:
    @echo off & setlocal enabledelayedexpansion

    set inputFile=”Z:file.txt”
    set outputFile=”Z:file_out.txt”

    if exist %outputFile% del /f/q %outputFile%

    set i=1
    set n=1
    for /f “UseBackQ tokens=14,19 delims=,” %%G in (%inputFile%) do (
    if /i %%~G==O (
    call :GetLength %%~H
    if !length!==3 (
    set line!n!=!i!
    set /a n+=1
    )
    )
    set /a i+=1
    )

    set i=1
    set n=1
    for /f “UseBackQ delims=” %%G in (%inputFile%) do (
    call set line=%%line!n!%%
    if !i!==!line! (
    echo %%G >> %outputFile%
    set /a n+=1
    )
    set /a i+=1
    )

    goto :eof

    :GetLength
    set str=%1
    set /a length=0
    :loop
    set indexedChar=!str:~%length%,1!
    if defined indexedChar set /a length+=1 & goto loop

    Avatar
    reddurex
    Member
    in reply to: Get PC name from Dell Service Tag #388045

    Re: Get PC name from Dell Service Tag

    noxigen;272967 wrote:
    Out of habit. I usually create scripts that target a single machine so that I can execute them against multiple machines in parallel or import them into System Frontier. :cool:

    You could still make this dynamic in that way. :smile:

    Code:
    On Error Resume Next

    ‘ Input File Example:
    ‘ 127.0.0.1
    ‘ 127.0.0.1, UserName, Password’

    Dim fileStream, fileSystemObj
    Const ForReading = 1
    Dim strArr

    localUserName = “”
    localPass = “”

    If WScript.Arguments.Length = 0 Then
    Call GetInfo(“127.0.0.1”, localUserName, localPass, False)
    Else
    filePath = WScript.Arguments(0)
    Set fileSystemObj = CreateObject(“Scripting.FileSystemObject”)
    If fileSystemObj.FileExists(filePath) Then
    Set fileStream = fileSystemObj.OpenTextFile(filePath, ForReading, 0)
    Do Until fileStream.AtEndOfStream
    strLn = fileStream.ReadLine()
    If Trim(strLn) “” Then
    arg1 = “”
    arg2 = “”
    strArr = Split(strLn, “,”)
    If UBound(strArr) = 2 Then
    arg1 = Trim(strArr(1))
    arg2 = Trim(strArr(2))
    End If
    Call GetInfo(Trim(strArr(0)), user, pass, True)
    End If
    Loop
    Else
    MsgBox “File does not exist: ” & filePath, 48, “Error”
    End If
    End If

    Sub GetInfo(strComputer, userName, pass, abortOption)
    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,userName,pass)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    Style = 64
    If abortOption Then Style = 67
    For Each objItem in colItems
    Result = MsgBox(“Computer: ” & strComputer & vbNewLine & _
    “Manufacturer: ” & objItem.Manufacturer & vbNewLine & _
    “SerialNumber: ” & objItem.SerialNumber, Style, “WMI Results”)
    If abortOption And Result = 7 Then WScript.Quit(0)
    Next
    Else
    MsgBox “(” & strComputer & “) – ” & _
    Err.Description, 48, “WMI Error”
    End If
    End Sub

    You can specify a file that contains a list of computer names and optional username and password delimited by a “,” (comma). So for instance the file may look like this:

    Code:
    127.0.0.1
    127.0.0.1, UserName, Password

    Where the username and password are optional for each line. Otherwise just invoking the script without any arguments assumes “127.0.0.1”.

    Note: You could edit the script to output all of the information at the end once all queries are completed, or add a messagebox that has 2 buttons, and check for whether the user wants to continue checking the next one, otherwise exit the script.

    edit: I edited the script with the most up to date version I have right now.

    VBscript isn’t really my thing, I know VB.net and C#, but I mainly deal with C/C++.

    Cheers,
    Ace

    Avatar
    reddurex
    Member
    in reply to: Get PC name from Dell Service Tag #388044

    Re: Get PC name from Dell Service Tag

    noxigen;272829 wrote:
    First, get a list of all machines in your domain and put them in a text file called pcs.txt, for example. One hostname per line.

    Take the following VBScript snippet and save it to a file called GetSerial.vbs (or whatever you like):

    On Error Resume Next

    strComputer = WScript.Arguments(0)

    UserName = “”
    Password = “”

    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,UserName,Password)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    For Each objItem in colItems
    WScript.Echo strComputer & vbTab & objItem.Manufacturer & vbTab & objItem.SerialNumber
    Next
    Else
    WScript.Echo strComputer & vbTab & “WMI Error” & vbTab & Err.Description
    End If[/CODE]Now run the script against every PC in the list to get the serial numbers back for identification. From a CMD prompt run:

    [CODE]for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script ([B]not [/B]recommended).[/QUOTE]

    Instead of using batch, why not put all of that functionality into the VBS script? :idea:[CODE]On Error Resume Next

    strComputer = WScript.Arguments(0)

    UserName = “”
    Password = “”

    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,UserName,Password)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    For Each objItem in colItems
    WScript.Echo strComputer & vbTab & objItem.Manufacturer & vbTab & objItem.SerialNumber
    Next
    Else
    WScript.Echo strComputer & vbTab & “WMI Error” & vbTab & Err.Description
    End If[/CODE]Now run the script against every PC in the list to get the serial numbers back for identification. From a CMD prompt run:

    for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script ([B]not [/B]recommended).[/QUOTE]

    Instead of using batch, why not put all of that functionality into the VBS script? :idea:[CODE]for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script (not recommended).

    Instead of using batch, why not put all of that functionality into the VBS script? :idea:

Viewing 4 posts - 1 through 4 (of 4 total)