Статус: Эксперт
Группы: Участники
Зарегистрирован: 05.03.2015(UTC) Сообщений: 1,602  Откуда: Иркутская область Сказал(а) «Спасибо»: 110 раз Поблагодарили: 396 раз в 366 постах
|
Вроде бы уже поднимался вопрос, в общих чертах: 1) для каждого ПК слепить в SuperOrca минипатч с одним только регистрационным номером - сохранить как %CompName%.msp. Как вариант файл реестра %CompName%.reg 2) удалять 4.0 в принципе не обязательно, так как 5.0 заменит 4.0, но если вдруг: запустить удаление через msiexec по гуид или имени продукта (разные версии 4.0 имеют разные гуиды, но по имени и 5.0 снесет). Как вариант набросал скрипт автоопределения;
Прототип, находит версии КриптоПро отличные от 5.0 в экспорте из реестра, записывает во второй командный файл. Сам скрипт второй командный файл на исполнение не вызывает, чтобы антивирусы не среагировали, поэтому и экспорт реестра и вызов скрипта и вызов второго командного файла идет из первого командного файла. Надо еще команду удаления поправить, паузы убрать, хотел еще сбор на веб-сервер дописать, но основа есть, выложу пока так. start1.cmd Код:md %TEMP%\reg
REG EXPORT HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall %TEMP%\reg\uninstall32.reg /y /reg:32
REG EXPORT HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall %TEMP%\reg\uninstall.reg /y /reg:64
REG EXPORT HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products %TEMP%\reg\product32.reg /y /reg:32
REG EXPORT HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products %TEMP%\reg\product.reg /y /reg:64
REG EXPORT HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName %TEMP%\reg\compname.reg /y
cscript.exe appdetect.vbs %TEMP%\reg
call %TEMP%\reg\start2.cmd
pause
AppDetect.vbs Код:Option Explicit
Dim ReportUrl, ReportData, RemoveCmd
Dim AppName, AppNeedVer
AppName="КриптоПро CSP"
AppNeedVer="5.0"
RemoveCmd="rem msiexec.exe /uninstall %GUID%"
'ReportUrl="http://localhost/appscan.php"
ReportData="comp=%COMP%&ver=%VER%&guid=%GUID%&dt=%DT%&code=%CODE%&product=%PROD%"
' ==============
Dim FSO, CDir, CmdFile, CompName
Sub ReportWWW(Product,Ver,Guid,Dt,Code)
Dim S, S2
If ReportUrl<>"" Then
S=ReportUrl
S2=ReportData
S=Replace(S,"%GUID%",Guid)
S=Replace(S,"%COMP%",Compname)
S=Replace(S,"%VER%",Ver)
S=Replace(S,"%DT%",Dt)
S=Replace(S,"%CODE%",Code)
S=Replace(S,"%PROD%",Product)
'
S2=Replace(S2,"%GUID%",Guid)
S2=Replace(S2,"%COMP%",Compname)
S2=Replace(S2,"%VER%",Ver)
S2=Replace(S2,"%DT%",Dt)
S2=Replace(S2,"%CODE%",Code)
S2=Replace(S2,"%PROD%",Product)
'
WScript.Echo S2
End If
End Sub
Sub ReportApp(Product,Ver,Guid,Dt,Code)
Dim S
If Instr(1,Product,AppName)>0 Then
WScript.Echo Product+" "+Ver+chr(13)+chr(10)+Guid+chr(13)+chr(10)+Compname+" "+Dt+chr(13)+chr(10)+Code
If RemoveCmd<>"" Then
S=RemoveCmd
S=Replace(S,"%GUID%",Guid)
S=Replace(S,"%COMP%",Compname)
S=Replace(S,"%VER%",Ver)
S=Replace(S,"%DT%",Dt)
S=Replace(S,"%CODE%",Code)
S=Replace(S,"%PROD%",Product)
If Instr(1,Ver,AppNeedVer)=0 And Code="" Then
CmdFile.WriteLine S
End If
End If
ReportWWW Product, Ver, Guid, Dt, Code
End If ' Detected Appname
End Sub
Sub DetectInFile(Fname)
Dim F, F2, S, Sect, Ver, k, ParName, ParValue, Product,Dt,Code
If Not FSO.FileExists(CDir+"\"+Fname) Then Exit Sub
Set F=FSO.OpenTextFile(CDir+"\"+Fname,1,,-1)
Sect=""
Do While Not F.AtEndOfStream
S=F.ReadLine()
If S<>"" Then
If Left(S,1)="[" Then
ReportApp Product, Ver, Sect, Dt, Code
S=Trim(Mid(S,2,Len(S)-2))
Sect=Replace(S,"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\","",vbTextCompare)
Sect=Replace(Sect,"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","",vbTextCompare)
Product=""
Ver=""
Dt=""
Code=""
ElseIf Sect<>"" Then
k=Instr(1,S,"=")
If k>0 Then
ParName=Replace(Left(S,k-1),"""","")
ParValue=Mid(S,k+1)
Do While Right(ParValue,1)="\"
S=Trim(F.ReadLine())
ParValue=Left(ParValue,Len(ParValue)-1)+S
Loop
ParValue=Replace(ParValue,"""","")
If ParName="DisplayName" Then
Product=ParValue
End If
If ParName="DisplayVersion" Then
Ver=ParValue
End If
If ParName="InstallDate" Then
Dt=ParValue
End If
'"UninstallString"=hex(2):
'"VersionMajor"=dword:00000004
'"VersionMinor"=dword:00000000
End If ' Equal sign presents
End If ' Sect not empty
End If ' S not empty
Loop
ReportApp Product, Ver, Sect, Dt, ""
F.Close
End Sub
Sub DetectProducts(Fname)
Dim F, F2, S, Sect, Ver, k, ParName, ParValue, Product,Dt,Code
If Not FSO.FileExists(CDir+"\"+Fname) Then Exit Sub
Set F=FSO.OpenTextFile(CDir+"\"+Fname,1,,-1)
Sect=""
Do While Not F.AtEndOfStream
S=F.ReadLine()
If S<>"" Then
If Left(S,1)="[" Then
ReportApp Product, Ver, Sect, Dt, Code
S=Trim(Mid(S,2,Len(S)-2))
Sect=Replace(S,"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\","",vbTextCompare)
Sect=Replace(Sect,"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products","",vbTextCompare)
Product=""
Ver=""
Dt=""
Code=""
ElseIf Instr(1,Sect,"InstallProperties",vbTextCompare)>0 Then
k=Instr(1,S,"=")
If k>0 Then
ParName=Replace(Left(S,k-1),"""","")
ParValue=Mid(S,k+1)
Do While Right(ParValue,1)="\"
S=Trim(F.ReadLine())
ParValue=Left(ParValue,Len(ParValue)-1)+S
Loop
ParValue=Replace(ParValue,"""","")
If ParName="DisplayName" Then
Product=ParValue
End If
If ParName="DisplayVersion" Then
Ver=ParValue
End If
If ParName="InstallDate" Then
Dt=ParValue
End If
If ParName="ProductID" Then
Code=ParValue
End If
'"UninstallString"=hex(2):
'"VersionMajor"=dword:00000004
'"VersionMinor"=dword:00000000
End If ' Equal sign presents
End If ' Sect not empty
End If ' S not empty
Loop
ReportApp Product, Ver+"/"+AppNeedVer, "", Dt, Code
F.Close
End Sub
Sub DetectComp(Fname)
Dim F, F2, S, Sect, k, ParName, ParValue
Set F=FSO.OpenTextFile(CDir+"\"+Fname,1,,-1)
Sect=""
Do While Not F.AtEndOfStream
S=F.ReadLine()
If S<>"" Then
If Left(S,1)="[" Then
S=Trim(Mid(S,2,Len(S)-2))
Sect=Replace(S,"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName","A",vbTextCompare)
ElseIf Sect<>"" Then
k=Instr(1,S,"=")
If k>0 Then
ParName=Replace(Left(S,k-1),"""","")
ParValue=Mid(S,k+1)
Do While Right(ParValue,1)="\"
S=Trim(F.ReadLine())
ParValue=Left(ParValue,Len(ParValue)-1)+S
Loop
ParValue=Replace(ParValue,"""","")
If ParName="ComputerName" Then
CompName=ParValue
End If
End If ' Equal sign presents
End If ' Sect not empty
End If ' S not empty
Loop
F.Close
End Sub
Set FSO=CreateObject("Scripting.FileSystemObject")
CDir=WScript.Arguments(0)
If CDir="" Then CDir=FSO.GetFolder(".")
WScript.Echo CDir
Set CmdFile=FSO.CreateTextFile(CDir+"\start2.cmd",True)
CmdFile.WriteLine "chcp 1251"
DetectComp "compname.reg"
WScript.Echo ">>SCAN: "+CompName+" "+AppName+" "+AppNeedVer
DetectInFile "uninstall32.reg"
DetectInFile "uninstall.reg"
DetectProducts "product32.reg"
DetectProducts "product.reg"
CmdFile.WriteLine ""
'CmdFile.WriteLine "pause"
CmdFile.Close
3) запустить стандартную установку - есть в виде msi; 4) запустить патчик %CompName%.msp или внедрение %CompName%.reg Повторить на все компы можно групповой политикой либо другими средствами автоматизации. Если при создании групповой политики будет ругаться что нет такого файла %CompName%.msp - временно создать копию патча с таким именем, потом сразу удалить. Отредактировано пользователем 15 октября 2020 г. 8:14:19(UTC)
| Причина: скрипт теперь пишет в TEMP и находит лицензию в реестре
|