域控电脑判断有没有安装某个软件

Dim Process '进程名
Dim path    '安装包位置 
Dim pakgeName '安装包名
Dim temp '临时存放路径
Dim oShell 
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell= CreateObject("WScript.Shell")
Process = "firefox.exe"
path = "\\172.16.17.10\常用软件\浏览器\"'这里要\
pakgeName = "Firefox Setup 65.0.2.exe"
temp = "c:\networkAccess"'这里不要\

Set oExec = oShell.Exec("%COMSPEC% /C ""tasklist|find /i """ &Process&"""""")'Chr(34)表示双引号
if Not oExec.StdOut.AtEndOfStream then
    strText = oExec.StdOut.Readline()
    s = split(strText," ")
    strText = s(0)
    if  strcomp(Process,strText)<>0 then
        msgbox "没有chrome.exe" '\\172.16.17.10\常用软件\浏览器\Firefox Setup 65.0.2.exe
        if not fso.folderExists(temp) then
            set fld = fso.createfolder(temp)
        end if
        if not IsExitAFile(temp&"\"&pakgeName) then
            fso.CopyFile path&pakgeName,temp&"\"&pakgeName,False
        end if
        runProgamo(temp&"\"&pakgeName)

    else
        msgbox "有chrome.exe"
          
        if IsExitAFile(temp&"\"&pakgeName) then
            DeleteAFile(temp&"\"&pakgeName)
        end if
        if IsExitAFile(temp) then
            DeleteAFolder(temp)
        end if
    end if 
else
    msgbox "什么都没有找到"
    if not fso.folderExists(temp) then
            set fld = fso.createfolder(temp)
    end if  
   if not  IsExitAFile(temp&"\"&pakgeName) then
            msgbox "this 不存在"
            fso.CopyFile path&pakgeName,temp&"\"&pakgeName,False
    end if
    msgbox temp&"\"&pakgeName
    runProgamo(temp&"\"&pakgeName)
end if 


msgbox "end"

Function IsExitAFile(filespec)
        Dim fso
        Set fso=CreateObject("Scripting.FileSystemObject")        
        If fso.fileExists(filespec) Then         
        IsExitAFile=True        
        Else IsExitAFile=False        
        End If
End Function 



Sub CreateAFile(filespec)
        Dim fso
        Set fso=CreateObject("Scripting.FileSystemObject")
        fso.CreateTextFile(filespec)
End Sub


Sub DeleteAFile(filespec)
        Dim fso
        Set fso= CreateObject("Scripting.FileSystemObject")
        fso.DeleteFile(filespec)
End Sub


Function IsExitAFolder(filespec)
        Dim fso
        Set fso=CreateObject("Scripting.FileSystemObject")        
        If fso.folderExists(filespec) Then         
        IsExitAFolder=True        
        Else IsExitAFolder=False        
        End If
End Function 

Sub DeleteAFolder(filespec)
        Dim fso
        Set fso= CreateObject("Scripting.FileSystemObject")
        fso.Deletefolder(filespec)
End Sub

sub runProgamo(filespec)
        Dim objws
        Set objws=WScript.CreateObject("wscript.shell")
        objws.Run """"&filespec&"""",True
End sub

'Set oExec = oShell.Exec("%COMSPEC% /C ""PING 127.0.0.1""")
'Do While Not (oExec.StdOut.AtEndOfStream) 
    'strText = oExec.StdOut.Readline()
    'msgbox strText
'Loop


猜你喜欢

转载自blog.csdn.net/ben9518chen/article/details/88531520
今日推荐