2012-03-22 73 views
1

我正在寻找使用脚本去禁用Windows 7机器上的文件(REAgentc.exe),如果它不存在(即在XP机器上)然后结束。下面是我迄今为止所得到的,但任何人都可以帮助我实现我所追求的其余部分?我对VB脚本的认识并不是很好,但可以提供的任何帮助将不胜感激,谢谢。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 
+0

它有什么问题/失败/它不行吗? – 2012-03-22 10:11:01

+0

嗨,上面的摘录实际上工作正常。我只是不确定如何实现一个函数来查找文件是否存在/一台机器是7还是XP – user1285511 2012-03-22 10:27:43

+0

这个脚本已经做了你想做的事情。我不明白你想要什么。 – Nilpo 2012-03-24 06:30:44

回答

1

您可以修改您的RunCommand来检测& run;

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 
+0

好的,谢谢,人们如何去做这件事?一个同事最初实际构建了这个脚本,我只是用我拥有的知识稍微修改了一下。再次感谢。 – user1285511 2012-03-22 10:54:23

相关问题