vbscript - 对象必需的错误

时间:2016-08-30 13:38:17

标签: vbscript

出于某种原因,当我运行我的vbscript时,我在InstallLog的第4行Char 1中获得了一个对象。知道为什么会这样吗?

m2=0
m1=0
x1+y2-n >= 0
2x1 - y1 >= 0

2 个答案:

答案 0 :(得分:1)

您肯定需要使用这行代码PRECEDES那些使用FSO对象或调用FSO.OpenTextFile

之类的函数的代码
Set FSO = CreateObject("Scripting.FileSystemObject")

答案 1 :(得分:1)

下面。这应该让你去。 icacls命令现在正在回显到日志中,因此您可以确认正确传递了语法。编辑 - 某些命令行程序未正确传递参数,而不使用" cmd.exe / C"。我添加了这个以及icacls.exe的完整路径,以防您从不在系统路径中的位置运行。

Option Explicit
Dim wshShell, objFSO, strDexcomFolder, strDexcom, SysRoot, intRunError, strGroup, strDomain, InstallLog, strWinDir

Set wshShell = CreateObject("WScript.Shell")
SysRoot = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
strWinDir = WshShell.ExpandEnvironmentStrings("%windir%")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading =   1
Const ForWriting =   2
Const ForAppending = 8
Const ReadOnly =     1

strDexcomFolder = "c:\Program Files (x86)\Bioex"
strDomain = "xxxxxxxx"
strGroup = "domain users"

Set InstallLog = objFSO.CreateTextFile("Install_Log.txt", True)

MsgBox strDexcomFolder
If objFSO.FolderExists(strDexcomFolder) Then
  MsgBox "Start"
  InstallLog.WriteLine("Running Command - " & strWinDir & "\System32\cmd.exe /C " & strWinDir & "\System32\icacls.exe " & Chr(34) & strDexcomFolder & Chr(34) & " /grant " & Chr(34) & strDomain & "\" & strGroup & chr(34) & ":(OI)(CI)(M)")
  intRunError = WshShell.Run(strWinDir & "\System32\cmd.exe /C " & strWinDir & "\System32\icacls.exe " & Chr(34) & strDexcomFolder & Chr(34) & " /grant " & Chr(34) & strDomain & "\" & strGroup & chr(34) & ":(OI)(CI)(M)", 2, True)
  MsgBox intRunError
    If intRunError <> 0 Then
      InstallLog.WriteLine("")
      InstallLog.WriteLine("Error Assigning Permissions!")
      InstallLog.WriteLine("Error #: " & Err.Number & ", " & Err.Description) 
      InstallLog.WriteLine("")
      MsgBox "Error assigning permissions!"
    End If
Else
  InstallLog.WriteLine("Error: folder " & strDexcomFolder & " does not exist")
  WScript.Echo "Error: folder " & strDexcomFolder & " does not exist"
End If
InstallLog.close
WScript.Quit