bsharath
asked on
Script that works as a login script need to query on a list of machine names in a txt file.
Hi,
Script that works as a login script need to query on a list of machine names in a txt file.
The only change is query the machines whose names are in the txt file.
I tried psexec method but that did not work.
Regards
sharath
Script that works as a login script need to query on a list of machine names in a txt file.
The only change is query the machines whose names are in the txt file.
I tried psexec method but that did not work.
Regards
sharath
What are you trying to do
ASKER
Sorry missed the code.
Software inventory
I dont know why the code snippet is not attaching
Pasting the code below
@echo off
:: Start getting the date and time and then into single variable - Don't Modify
for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set MM=%%j
set DD=%%k
set YYYY=%%l
set date=%%k-%%j-%%l
set dirdate=%%k-%%j-%%l
)
for /f "Tokens=1-2 delims=/ " %%i in ('time /t') do (
set tm=%%i
set ampm=%%j
)
:: End getting the date and time and then into single variable - Don't Modify
set ServerLoc=\\insm\Logs\Soft ware\
::It's check for current date folder, if not available, it will create one
if not exist "%ServerLoc%\%dirdate%\" mkdir "%ServerLoc%\%dirdate%\"
if exist "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.t xt" del "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.t xt"
for /f "tokens=*" %%a in ('reg query "hklm\software\microsoft\w indows\cur rentversio n\uninstal l" ^| find /i "currentversion\uninstall\ "') do (
reg query "%%a" | find /i "parentkeyname">NUL
if errorlevel 1 (
reg query "%%a" | find /i "systemcomponent" | find /i "0x1">NUL
if errorlevel 1 (
for /f "tokens=2,*" %%b in ('reg query "%%a" ^| find /i " displayname"') do echo %%c>>"%ServerLoc%\%dirdate %\%Compute rName%_%da te%.txt"
)
)
)
sort "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.t xt">"%Serv erLoc%\%di rdate%\%Co mputerName %_%date%.s rt"
SET LastLine=
IF EXIST "%ServerLoc%\%dirdate%\%Co mputerName %_%DIRdate %.one" DEL /Q "%ServerLoc%\%dirdate%\%Co mputerName %_%DIRdate %.one"
FOR /F "tokens=*" %%a IN (%ServerLoc%\%dirdate%\%Co mputerName %_%DIRdate %.srt) DO (
ECHO LineRead: "%%a"
IF NOT "%%a"=="!LastLine!" (
ECHO %%a>>"%ServerLoc%\%dirdate %\%Compute rName%_%DI Rdate%.one "
SET LastLine=%%a
)
)
move /y "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.o ne" "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.t xt"
if exist "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.s rt" del "%ServerLoc%\%dirdate%\%Co mputerName %_%date%.s rt"
Software inventory
I dont know why the code snippet is not attaching
Pasting the code below
@echo off
:: Start getting the date and time and then into single variable - Don't Modify
for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set MM=%%j
set DD=%%k
set YYYY=%%l
set date=%%k-%%j-%%l
set dirdate=%%k-%%j-%%l
)
for /f "Tokens=1-2 delims=/ " %%i in ('time /t') do (
set tm=%%i
set ampm=%%j
)
:: End getting the date and time and then into single variable - Don't Modify
set ServerLoc=\\insm\Logs\Soft
::It's check for current date folder, if not available, it will create one
if not exist "%ServerLoc%\%dirdate%\" mkdir "%ServerLoc%\%dirdate%\"
if exist "%ServerLoc%\%dirdate%\%Co
for /f "tokens=*" %%a in ('reg query "hklm\software\microsoft\w
reg query "%%a" | find /i "parentkeyname">NUL
if errorlevel 1 (
reg query "%%a" | find /i "systemcomponent" | find /i "0x1">NUL
if errorlevel 1 (
for /f "tokens=2,*" %%b in ('reg query "%%a" ^| find /i " displayname"') do echo %%c>>"%ServerLoc%\%dirdate
)
)
)
sort "%ServerLoc%\%dirdate%\%Co
SET LastLine=
IF EXIST "%ServerLoc%\%dirdate%\%Co
FOR /F "tokens=*" %%a IN (%ServerLoc%\%dirdate%\%Co
ECHO LineRead: "%%a"
IF NOT "%%a"=="!LastLine!" (
ECHO %%a>>"%ServerLoc%\%dirdate
SET LastLine=%%a
)
)
move /y "%ServerLoc%\%dirdate%\%Co
if exist "%ServerLoc%\%dirdate%\%Co
Sharath, try using this VBS to run the above Batch file.
Regards,
Rob.
Regards,
Rob.
strAdmin = "domain\administrator"
strComputers = "Computers.txt"
strLogFile = "\\server\share\GetInstalledProgramsLog.txt"
strPSExec = "\\server\share\psexec.exe"
strBatchFile = "\\server\share\GetInstalledPrograms.bat"
strPassword = InputBox("Please enter the password for " & strAdmin & ":", "Password")
If strPassword = "" Then
MsgBox "Password cannot be blank"
WScript.Quit
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
strPSExec = objFSO.GetFile(strPSExec).ShortPath
Set objComputers = objFSO.OpenTextFile(strComputers, intForReading, False)
Set objLog = objFSO.CreateTextFile(strLogFile, True)
While Not objComputers.AtEndOfStream
strComputer = objComputers.ReadLine
If Ping(strComputer) = True Then
strCommand = "cmd /c " & strPSExec & " -accepteula -e -u " & strAdmin & " -p " & strPassword & " \\" & strComputer & " cmd /c """ & strBatchFile & """"
intReturn = objShell.Run(strCommand, 0, True)
If intReturn = 0 Then
objLog.WriteLine strComputer & ": SUCCESS"
Else
objLog.WriteLine strComputer & ": ERROR " & intReturn
End If
Else
objLog.WriteLine strComputer & ": OFFLINE"
End If
Wend
objComputers.Close
objLog.Close
MsgBox "Finished"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER
Thanks Rob works perfect
Can we run multiple computers at the same time...
I have 1000's of computers to query
Can we run on 50 each time?
Can we run multiple computers at the same time...
I have 1000's of computers to query
Can we run on 50 each time?
ASKER
Hi Rob any views on this Q and the below
https://www.experts-exchange.com/questions/26280035/Excellent-uninstall-script-from-Zoofan-Need-a-way-to-speed-it-up-or-run-multiple-machines-at-the-same-time.html
https://www.experts-exchange.com/questions/26280035/Excellent-uninstall-script-from-Zoofan-Need-a-way-to-speed-it-up-or-run-multiple-machines-at-the-same-time.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Rob
I am using this vbs for run a lot of batch files..
Can you help adding some code that when run asks for the computers.txt file name and then splits it into 20 of each file and then runs it seperately...
Some time back you gave me a code to split. Can this be added into the initial code
I am using this vbs for run a lot of batch files..
Can you help adding some code that when run asks for the computers.txt file name and then splits it into 20 of each file and then runs it seperately...
Some time back you gave me a code to split. Can this be added into the initial code
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intPerFile = 3
strFile = "computers.txt"
intLines = 0
intStart = 1
strCommands = ""
If objFSO.FileExists(strFile) Then
Set objFile = objFSO.OpenTextFile(strFile, intForReading, False)
While Not objFile.AtEndOfStream
strText = objFile.ReadLine
If Trim(strText) <> "" Then
If strContents = "" Then
strContents = strText
Else
strContents = strContents & VbCrLf & strText
End If
intLines = intLines + 1
If intLines = intPerFile Then
strNewName = CStr(intStart) & "to" & CStr(intStart + intPerFile - 1) & ".txt"
Set objOutput = objFSO.CreateTextFile(strNewName, True)
objOutput.Write strContents
objOutput.Close
Set objOutput = Nothing
intLines = 0
intStart = intStart + intPerFile
strContents = ""
If strCommands = "" Then
strCommands = "Start wscript.exe inventory.vbs " & strNewName & " inactive_" & strNewName & " Results" & Left(strNewName, Len(strNewName) - 3) & "xls"
Else
strCommands = strCommands & VbCrLf & "wscript.exe inventory.vbs " & strNewName & " inactive_" & strNewName & " Results" & Left(strNewName, Len(strNewName) - 3) & "xls"
End If
End If
End If
Wend
objFile.Close
If strContents <> "" Then
intTotal = UBound(Split(strContents, VbCrLf))
strNewName = CStr(intStart) & "to" & CStr(intStart + intTotal) & ".txt"
Set objOutput = objFSO.CreateTextFile(strNewName, True)
objOutput.Write strContents
objOutput.Close
Set objOutput = Nothing
If strCommands = "" Then
strCommands = "wscript.exe inventory.vbs " & strNewName & " inactive_" & strNewName & " Results" & Left(strNewName, Len(strNewName) - 3) & "xls"
Else
strCommands = strCommands & VbCrLf & "wscript.exe inventory.vbs " & strNewName & " inactive_" & strNewName & " Results" & Left(strNewName, Len(strNewName) - 3) & "xls"
End If
End If
Set objCmdFile = objFSO.CreateTextFile("InventoryBatch.bat", True)
objCmdFile.Write strCommands
objCmdFile.Close
Set objCmdFile = Nothing
MsgBox "Done"
Else
WScript.Echo "Could not find " & strFile
End If
I can't really make a generic one to create a batch file for every script, because the parameters will be different. You can use this version to create a batch for this particular script though.
Regards,
Rob.
Regards,
Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intPerFile = 3
strFile = "computers.txt"
strVBSToRun = "C:\Temp\Temp\Test Script\Test2.vbs"
intLines = 0
intStart = 1
strCommands = ""
If objFSO.FileExists(strFile) Then
Set objFile = objFSO.OpenTextFile(strFile, intForReading, False)
While Not objFile.AtEndOfStream
strText = objFile.ReadLine
If Trim(strText) <> "" Then
If strContents = "" Then
strContents = strText
Else
strContents = strContents & VbCrLf & strText
End If
intLines = intLines + 1
If intLines = intPerFile Then
strNewName = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & CStr(intStart) & "_to_" & CStr(intStart + intPerFile - 1) & ".txt"
Set objOutput = objFSO.CreateTextFile(strNewName, True)
objOutput.Write strContents
objOutput.Close
Set objOutput = Nothing
intLines = 0
intStart = intStart + intPerFile
strContents = ""
If strCommands = "" Then
strCommands = "wscript.exe " & objFSO.GetFile(strVBSToRun).ShortPath & " /i:""" & objFSO.GetFile(strNewName).ShortPath & """"
Else
strCommands = strCommands & VbCrLf & "wscript.exe " & objFSO.GetFile(strVBSToRun).ShortPath & " /i:""" & objFSO.GetFile(strNewName).ShortPath & """"
End If
End If
End If
Wend
objFile.Close
If strContents <> "" Then
intTotal = UBound(Split(strContents, VbCrLf))
strNewName = CStr(intStart) & "_to_" & CStr(intStart + intTotal) & ".txt"
Set objOutput = objFSO.CreateTextFile(strNewName, True)
objOutput.Write strContents
objOutput.Close
Set objOutput = Nothing
If strCommands = "" Then
strCommands = "wscript.exe " & objFSO.GetFile(strVBSToRun).ShortPath & " /i:""" & objFSO.GetFile(strNewName).ShortPath & """"
Else
strCommands = strCommands & VbCrLf & "wscript.exe " & objFSO.GetFile(strVBSToRun).ShortPath & " /i:""" & objFSO.GetFile(strNewName).ShortPath & """"
End If
End If
Set objCmdFile = objFSO.CreateTextFile("GetInstalledAppsBatch.bat", True)
objCmdFile.Write strCommands
objCmdFile.Close
Set objCmdFile = Nothing
MsgBox "Done"
Else
WScript.Echo "Could not find " & strFile
End If
ASKER
Thanks Rob i can use the same for the uninstall code also right?
Not quite. The parameters aren't the same....I'll post another version there. Not much to change...
Rob.
Rob.
ASKER
Thank you Rob all fine now.. :-)