File VB脚本:如果文件存在,则运行,如果不存在,则结束
我想用一个脚本来禁用Windows7机器上的一个文件(REAgentc.exe),如果它不存在(即XP机器上),那么就结束。下面是我到目前为止所得到的,但有谁能帮助我实现我所追求的其他目标吗?我的VB脚本知识是承认不是很大,但任何帮助,可以提供向前将不胜感激,谢谢File VB脚本:如果文件存在,则运行,如果不存在,则结束,file,vbscript,operating-system,File,Vbscript,Operating System,我想用一个脚本来禁用Windows7机器上的一个文件(REAgentc.exe),如果它不存在(即XP机器上),那么就结束。下面是我到目前为止所得到的,但有谁能帮助我实现我所追求的其他目标吗?我的VB脚本知识是承认不是很大,但任何帮助,可以提供向前将不胜感激,谢谢 'Declare Variables Dim strApp Dim arrPath Dim strPath Dim strAppPath ' main if statement to run the script and call
'Declare Variables
Dim strApp
Dim arrPath
Dim strPath
Dim strAppPath
' main if statement to run the script and call functions and sub's
If (CheckRegistryForValue)= True Then
'msgbox( strPath & " I am here")
WScript.Quit (0)
Else
RunCommand
WriteRegkey
WScript.Quit (0)
End If
'Sub to run the REAgent disable command
Sub RunCommand
Set objShell = CreateObject("Wscript.Shell")
strApp = "C:\Windows\System32\REAgentc.exe /disable"
arrPath = Split(strApp, "\")
For i = 0 To Ubound(arrPath) - 1
strAppPath = strAppPath & arrPath(i) & "\"
Next
objShell.CurrentDirectory = strAppPath
objShell.Run(strApp)
End Sub
'Function to check registry for value, Return check registry for value
Function CheckRegistryForValue
Set WshShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
dong = wshShell.RegRead ("HKLM\SOFTWARE\REAgent\")
If (Err.Number <> 0) Then
CheckRegistryForValue = False
Else
CheckRegistryForValue = True
End If
End Function
' sub to write registery key to flag computers that the script has run On
Sub WriteRegkey
HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set ObjRegistry = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strPath = "SOFTWARE\REAgent\Script Complete"
Return = objRegistry.CreateKey(HKEY_LOCAL_MACHINE, strPath)
End Sub
“声明变量
暗带
暗波道
暗通道
暗道
'main if语句运行脚本并调用函数和子函数'
如果(CheckRegistryForValue)=True,则
'msgbox(strPath&“我在这里”)
WScript.Quit(0)
其他的
运行命令
WriteRegkey
WScript.Quit(0)
如果结束
'Sub以运行试剂禁用命令
子运行命令
设置objShell=CreateObject(“Wscript.Shell”)
STRAP=“C:\Windows\System32\REAgentc.exe/disable”
arrPath=Split(带“\”)
对于i=0到Ubound(arrPath)-1
STRAPPATH=STRAPPATH和arrPath(i)和“\”
下一个
objShell.CurrentDirectory=路径
objShell.Run(带)
端接头
'函数检查注册表的值,返回检查注册表的值
函数CheckRegistryForValue
设置WshShell=WScript.CreateObject(“WScript.Shell”)
出错时继续下一步
dong=wshShell.regrad(“HKLM\SOFTWARE\Regent\”)
如果(错误编号0),则
CheckRegistryForValue=False
其他的
CheckRegistryForValue=True
如果结束
端函数
'sub以写入注册表项以标记已在其上运行脚本的计算机
分写器
HKEY_本地_机器=&H8000002
strComputer=“”
Set ObjRegistry=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\”&strComputer&“\root\default:StdRegProv”)
strPath=“软件\试剂\脚本完成”
Return=objRegistry.CreateKey(HKEY\u LOCAL\u MACHINE,strPath)
端接头
您可以修改RunCommand
以检测并运行
dim FSO, objShell, strApp
set FSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Wscript.Shell")
'//get system path
strApp = FSO.GetSpecialFolder(1) & "\REAgentc.exe"
if FSO.FileExists(strApp) then
'//no need to change directory as you have the full path
objShell.Run(strApp & " /disable")
else
'//does not exist
end if
您可以修改
RunCommand
以检测并运行
dim FSO, objShell, strApp
set FSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Wscript.Shell")
'//get system path
strApp = FSO.GetSpecialFolder(1) & "\REAgentc.exe"
if FSO.FileExists(strApp) then
'//no need to change directory as you have the full path
objShell.Run(strApp & " /disable")
else
'//does not exist
end if
它有什么问题/失败/不起作用吗?您好,上面的摘录实际上很好。我只是不确定如何实现一个函数来查找文件是否存在/机器是7还是xp。这个脚本已经完成了您正在尝试的操作。我不明白你还想要什么。它有什么问题/失败了/不行吗?你好,上面的摘录实际上很好。我只是不确定如何实现一个函数来查找文件是否存在/机器是7还是xp。这个脚本已经完成了您正在尝试的操作。我不明白你还想要什么。好的,谢谢,你是怎么做到的?一位同事实际上在最初构建了脚本,我只是用我所掌握的知识稍微调整了一下。再次感谢。好的,谢谢,我们怎么做呢?一位同事实际上在最初构建了脚本,我只是用我所掌握的知识稍微调整了一下。再次感谢。