【发布时间】:2012-03-22 10:05:54
【问题描述】:
我正在寻找使用脚本来禁用 Windows 7 机器上的文件 (REAgentc.exe),如果它不存在(即在 XP 机器上)则结束。以下是我到目前为止所得到的,但任何人都可以帮助我实现我所追求的其余部分吗?诚然,我对 VB 脚本的了解并不多,但如果能提供任何帮助,我们将不胜感激,谢谢。
'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
【问题讨论】:
-
它有什么问题/失败/不行吗?
-
您好,上面的摘录实际上运行良好。我只是不确定如何实现一个函数来查找文件是否存在/机器是7还是XP
-
这个脚本已经做了你想做的事情。我不明白你还想要什么。
标签: file vbscript operating-system